/* Los estilos base ahora los proporciona crm-common.css */
/* Reutilizamos las variables del tema común */



#sidebar {
    width: 320px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: background 0.3s;
}

.sidebar-header {
    padding: 10px 16px;
    background: var(--bg-sidebar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
}

.sidebar-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

.sidebar-header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon-wa {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-wa:hover {
    background: rgba(0,0,0,0.05);
}

[data-theme="dark"] .btn-icon-wa:hover {
    background: rgba(255,255,255,0.1);
}
.search-container {
    padding: 8px 16px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
}

.search-wrapper {
    position: relative;
    background: var(--bg-search);
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border: none;
}

.search-icon {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-right: 15px;
}
.search-input {
    background: transparent;
    border: none;
    padding: 10px;
    color: var(--text-main);
    font-size: 0.9rem;
    width: 100%;
    outline: none;
}
.search-input::placeholder { color: var(--text-muted); }

#chat-list {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-sidebar);
}

.chat-filters {
    display: flex;
    gap: 8px;
    padding: 8px 16px 12px 16px;
    background: var(--bg-sidebar);
    overflow-x: auto;
}

.chat-filters::-webkit-scrollbar { display: none; }

.filter-pill {
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--bg-search);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.filter-pill.active {
    background: #d9fdd3;
    color: #008069;
}

[data-theme="dark"] .filter-pill.active {
    background: #005c4b;
    color: #e9edef;
}

.chat-item {
    display: flex;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--border);
    position: relative;
    align-items: center;
}

.chat-item:hover { background: var(--bg-header); }
.chat-item.active { background: var(--bg-search); }

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin-right: 15px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    background: #ddd;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-info-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.chat-info-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.unread-badge {
    background: #25d366;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.chat-item {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border); /* Better themed divider */
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 15px; /* WA typical spacing */
    background: var(--bg-card, #ffffff);
}
.chat-item:hover { background: var(--bg-hover, #f0f2f5); }
.chat-item.active { 
    background: var(--bg-active, #ebebeb) !important; 
    border-left: 4px solid #25d366;
}

.chat-avatar { 
    width: 40px; 
    height: 40px; 
    border-radius: 50%; /* Circle avatars for WA native look */
    background: var(--accent); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: 600; 
    font-size: 1rem; 
    flex-shrink: 0; 
    overflow: hidden;
    position: relative; 
    color: white;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-info { flex: 1; overflow: hidden; display: flex; flex-direction: column; gap: 4px; }
.chat-phone { font-weight: 600; font-size: 0.95rem; color: var(--text-main); }
.chat-name-small { 
    font-size: 0.85rem; 
    color: var(--text-muted); 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}

.tag-pill {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.65rem;
    margin-right: 4px;
    margin-top: 2px;
    color: white;
    font-weight: 500;
    text-transform: uppercase;
}

/* Main Chat Area */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-chat);
    position: relative;
    box-shadow: inset 0 2px 4px 0 rgba(0,0,0,0.06);
}

#chat-header {
    padding: 10px 16px;
    background: #f0f2f5 !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
    z-index: 5;
    border-bottom: 1px solid rgba(0,0,0,0.08);
}
.header-user { display: flex; align-items: center; gap: 12px; }

/* Intervention Switch */
.switch-container { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--text-muted); }
.switch { position: relative; display: inline-block; width: 40px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--bg-search); transition: .3s; border-radius: 20px; border: 1px solid var(--border); }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 2px; bottom: 2px; background-color: var(--text-muted); transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent); border-color: var(--accent); }
input:checked + .slider:before { transform: translateX(20px); background-color: white; }

#messages {
    flex: 1;
    padding: 24px 7%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px; /* WhatsApp use smaller gaps between bubbles from same sender */
    background-color: #efeae2;
    background-image: url('/assets/wa-bg-light.jpg');
    background-repeat: no-repeat !important;
    background-size: cover !important;
    background-position: center !important;
    background-attachment: scroll !important;
}

[data-theme="dark"] #messages {
    background-image: url('/assets/wa-bg-dark.jpg') !important;
    background-color: #0b141a !important;
    background-repeat: no-repeat !important;
    background-size: cover !important;
    background-position: center !important;
    background-attachment: scroll !important;
}

.welcome-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 40px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.85); /* Mayor opacidad para lectura clara */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    max-width: 500px;
    margin: auto;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 10px 40px 0 rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .welcome-container {
    background: rgba(32, 44, 51, 0.9); /* Más oscuro y sólido en dark mode */
    border-color: rgba(255, 255, 255, 0.1);
    color: #e9edef;
}

.msg { 
    max-width: 65%; 
    padding: 8px 12px 8px 12px; 
    border-radius: 8px; 
    line-height: 1.4; 
    font-size: 0.92rem; 
    position: relative;
    margin-bottom: 2px;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
    word-wrap: break-word;
}

/* User (Incoming) - Native WA Style */
.msg.user { 
    align-self: flex-start; 
    background: #ffffff; 
    color: #111b21; 
    border-top-left-radius: 0;
    margin-left: 10px;
}

.msg.user::before {
    content: "";
    position: absolute;
    top: 0;
    left: -10px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 10px 10px 0;
    border-color: transparent #ffffff transparent transparent;
}

/* Assistant (Outgoing) - Native WA Style */
.msg.assistant { 
    align-self: flex-end; 
    background: #dcf8c6; 
    color: #111b21; 
    border-top-right-radius: 0;
    margin-right: 10px;
}

.msg.assistant::before {
    content: "";
    position: absolute;
    top: 0;
    right: -10px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 10px 10px 0 0;
    border-color: #dcf8c6 transparent transparent transparent;
}

.msg-time {
    font-size: 0.65rem;
    color: #667781;
    margin-left: 8px;
    float: right;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 3px;
}

.msg-time i {
    display: none !important; /* Remove WhatsApp status icons as requested */
}



.chat-item:active {
    transform: scale(0.98);
}

/* Nav item styles removed to avoid conflict with crm-common.css expansion logic */

.msg {
    animation: msgIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes msgIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.msg-media img, .msg-media video {
    max-width: 100%;
    border-radius: 6px;
    display: block;
    margin-top: 2px;
}
.msg-file {
    background: rgba(0,0,0,0.05);
    padding: 12px;
    border-radius: 8px;
    margin-top: 8px;
    font-size: 0.85rem;
    border: 1px solid rgba(0,0,0,0.05);
}
.msg.assistant .msg-file {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.1);
}
.msg-file a {
    color: var(--accent);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
.msg.assistant .msg-file a {
    color: white;
}

.msg-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 8px;
    float: right;
    margin-top: 4px;
    opacity: 0.8;
}
.msg.assistant .msg-time {
    color: #667781; /* Darker color for light green bubble */
}

/* WhatsApp Style Input Area */
#input-area {
    padding: 12px 16px;
    background: #f0f2f5;
    display: flex;
    gap: 12px;
    align-items: center;
    min-height: 62px;
    border-top: 1px solid rgba(0,0,0,0.08);
}
.input-wrapper {
    flex: 1;
    background: #ffffff;
    border-radius: 24px; /* More rounded */
    display: flex;
    align-items: center;
    padding: 0 16px;
    border: none;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05); /* Subtle shadow like WA */
}
#message-input {
    width: 100%;
    background: transparent;
    border: none;
    padding: 12px 0;
    color: var(--text-main);
    outline: none;
    font-size: 0.95rem;
}
#message-input:disabled { color: var(--text-muted); }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.btn-icon:hover { 
    background: rgba(148, 163, 184, 0.1);
    color: var(--accent); 
}
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }

/* CRM Panel & Micro-animations */
#crm-panel {
    position: fixed;
    right: -420px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: var(--bg-main);
    box-shadow: -10px 0 30px rgba(0,0,0,0.15);
    z-index: 1100;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    visibility: hidden;
    opacity: 0;
}

#crm-panel.active {
    right: 0;
    visibility: visible;
    opacity: 1;
}

.crm-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
}

.crm-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.crm-section {
    margin-bottom: 30px;
}

.crm-divider {
    height: 1px;
    background: var(--border);
    margin: 25px 0;
    opacity: 0.5;
}

.crm-input {
    width: 100%;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 18px;
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.crm-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    background: var(--bg-main);
}

.crm-section label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.tag-item-edit {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 12px;
    background: var(--bg-sidebar);
    border-radius: 12px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.tag-item-edit:hover {
    border-color: var(--accent);
    transform: translateX(4px);
}

/* Status colors */
.status-bot { color: #818cf8; font-weight: 600; }
.status-human { color: #f87171; font-weight: 600; }

/* Scrollbars customization */
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: var(--scrollbar-track); }
*::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 10px; }
*::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* --- TICKETS STYLES --- */
.badge-container {
    position: relative;
    cursor: pointer;
}

.badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #f87171;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 20px;
    min-width: 18px;
    text-align: center;
    border: 2px solid var(--bg-header);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-main);
    width: 100%;
    max-width: 500px;
    border-radius: 20px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.modal-header {
    padding: 20px 24px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 24px;
}

.animate-pop {
    animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* Panel Lateral Universal (Tickets / Meta / Leads) */
.tickets-panel {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    width: 450px !important;
    min-width: 450px !important;
    height: 100vh !important;
    background: var(--bg-card, #ffffff);
    color: var(--text-main);
    border-left: 1px solid var(--border);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    box-shadow: -10px 0 30px rgba(0,0,0,0.3);
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
    opacity: 0;
    transform: translateX(100%); /* Escondido a la derecha */
    pointer-events: none;
}

.tickets-panel.active, 
#meta-panel.active,
#leads-panel.active,
#crm-panel.active {
    visibility: visible !important;
    opacity: 1 !important;
    transform: translateX(0) !important;
    display: flex !important;
    z-index: 999999 !important;
    pointer-events: all !important;
    border-left: 3px solid #0668E1 !important;
    box-shadow: -20px 0 50px rgba(0,0,0,0.5) !important;
}

/* Modo oscuro específico para paneles laterales */
[data-theme="dark"] .tickets-panel {
    background: #1e293b !important;
    border-left: 1px solid rgba(255,255,255,0.1) !important;
}

[data-theme="dark"] .tickets-panel .panel-header {
    background: #0f172a !important;
    border-bottom: 1px solid rgba(255,255,255,0.1) !important;
}

.panel-header {
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
}

.tickets-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ticket-item {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.ticket-item:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.ticket-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.ticket-title {
    font-weight: 700;
    font-size: 0.95rem;
}

.ticket-badge {
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 700;
}

.priority-Alta { background: #fee2e2; color: #ef4444; }
.priority-Media { background: #fef3c7; color: #d97706; }
.priority-Baja { background: #dcfce7; color: #10b981; }

.ticket-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.panel-tabs {
    display: flex;
    padding: 10px 20px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.ticket-status-row {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-select {
    padding: 4px 8px;
    font-size: 0.8rem;
    background: var(--bg-main);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
}

.status-select:focus {
    border-color: var(--accent);
}

/* ========================================================
   RESPONSIVO / MOBILE BACKOFFICE
   ======================================================== */
@media (max-width: 768px) {
    .crm-main-container {
        flex-direction: column;
        padding-bottom: 80px; /* Space for fixed bottom navbar */
    }
    
    #sidebar {
        width: 100%;
        height: 35vh; /* La lista de chats toma la parte superior */
        border-right: none;
        border-bottom: 2px solid var(--border);
        flex-shrink: 0;
    }

    #main-content {
        width: 100%;
        flex: 1; /* Coge el resto del espacio disponible */
        min-height: 40vh; 
    }

    .sidebar-header {
        min-height: 60px;
        padding: 10px 15px;
    }

    #chat-header {
        padding: 10px 15px;
        min-height: 60px;
    }

    .header-user {
        gap: 8px;
    }

    #input-area {
        padding: 10px;
        min-height: 60px;
        gap: 8px;
    }

    #messages {
        padding: 15px 10px;
    }

    .msg {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    /* Paneles laterales en móvil abrazan toda la vista interactiva */
    #crm-panel, .tickets-panel {
        width: 100% !important;
        right: 0 !important;
        transform: translateX(100%);
        height: calc(100vh - 65px) !important;
        top: auto !important;
        bottom: 65px !important;
        visibility: hidden;
        opacity: 0;
    }

    #crm-panel.active, .tickets-panel.active {
        transform: translateX(0) !important;
        visibility: visible !important;
        opacity: 1 !important;
        display: flex !important;
        z-index: 999999 !important;
    }

    #crm-jump-container {
        padding: 4px 8px;
    }
    
    #crm-lead-jump {
        width: 120px !important;
    }
}

/* --- META DESIGN SYSTEM (SDK-LIKE) --- */
.meta-modal-content {
    max-width: 1000px !important;
    height: 90vh;
    display: flex;
    flex-direction: column;
}

.meta-tabs {
    background: var(--bg-header);
    padding: 10px 24px;
    display: flex;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.meta-tab {
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.meta-tab:hover {
    background: rgba(0,0,0,0.05);
}

.meta-tab.active {
    background: #0668E1;
    color: white;
}

.meta-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background: var(--bg-main);
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding: 24px;
}

.meta-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 200px;
}

.meta-card:hover {
    border-color: #0668E1;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    transform: translateY(-5px);
}

.meta-card-tag {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.meta-card-name {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
    margin-bottom: 8px;
    padding-right: 60px;
}

.meta-card-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 20px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.meta-status-approved { background: #dcfce7; color: #15803d; }
.meta-status-pending { background: #fef3c7; color: #b45309; }
.meta-status-rejected { background: #fee2e2; color: #b91c1c; }

.meta-preview-overlay {
    background: #f0f2f5;
    padding: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.wa-preview-bubble {
    background: #ffffff;
    border-radius: 0 15px 15px 15px;
    padding: 12px 15px;
    max-width: 320px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.wa-preview-bubble::before {
    content: "";
    position: absolute;
    left: -10px;
    top: 0;
    border-top: 12px solid #ffffff;
    border-left: 12px solid transparent;
}

.wa-preview-text {
    font-size: 0.95rem;
    color: #111b21;
    line-height: 1.4;
    white-space: pre-wrap;
}

.wa-preview-time {
    font-size: 0.65rem;
    color: #667781;
    float: right;
    margin-top: 4px;
    margin-left: 10px;
}

.meta-library-badge {
    background: linear-gradient(135deg, #0668E1, #00F2FE);
    color: white;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 5px;
    font-weight: 800;
}

/* --- Dark Mode Native WA Overrides --- */
[data-theme="dark"] {
    --bg-main: #0b141a;
    --bg-sidebar: #111b21;
    --bg-header: #202c33;
    --bg-search: #202c33;
    --border: #222d34;
    --text-main: #e9edef;
    --text-muted: #8696a0;
}

#navbar {
    background: var(--bg-sidebar);
    width: 64px;
}

.nav-item {
    font-size: 1.1rem;
    width: 40px;
    height: 40px;
}

[data-theme="dark"] #messages {
    background-color: #0b141a;
    background-image: url('/assets/wa-bg-dark.png'); /* User provided dark background */
    background-blend-mode: normal; /* The dark image is ready as is */
    background-size: cover; /* Dark image looks more like a fixed wallpaper */
}

[data-theme="dark"] .msg.user {
    background: #202c33;
    color: #e9edef;
}
[data-theme="dark"] .msg.user::before {
    border-color: transparent #202c33 transparent transparent;
}

[data-theme="dark"] .msg.assistant {
    background: #005c4b;
    color: #e9edef;
}
[data-theme="dark"] .msg.assistant::before {
    border-color: #005c4b transparent transparent transparent;
}

[data-theme="dark"] .msg-time {
    color: #8696a0;
}
[data-theme="dark"] .msg.assistant .msg-time {
    color: rgba(233, 237, 239, 0.6);
}

[data-theme="dark"] .crm-input,
[data-theme="dark"] .search-wrapper {
    background: #2a3942;
    border-color: #374151;
}

[data-theme="dark"] #send-btn {
    color: #00a884 !important;
}

[data-theme="dark"] #chat-header,
[data-theme="dark"] #input-area {
    background: #202c33 !important;
    border-color: rgba(255,255,255,0.1);
}

[data-theme="dark"] .input-wrapper {
    background: #2a3942;
    color: #e9edef;
}
[data-theme="dark"] #message-input {
    color: #e9edef;
}

[data-theme="dark"] .chat-item {
    background: #111b21;
}
[data-theme="dark"] .chat-item:hover {
    background: #182229 !important;
}
[data-theme="dark"] .chat-item.active {
    background: #2a3942 !important;
    border-left: 4px solid #00a884; /* WhatsApp native dark green indicator */
}

/* --- Global Sidebar/Navbar Overrides for Backoffice --- */
/* Navbar styles are now managed in crm-common.css for consistency and animations */

/* --- Chat Header Structure --- */
#chat-header {
    height: 60px;
    padding: 0 16px;
    background: var(--bg-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-left: 1px solid var(--border);
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-user .chat-avatar {
    width: 40px;
    height: 40px;
}


/* --- Responsive fixes --- */
@media (max-width: 768px) {
    #navbar {
        width: 100%;
        height: 60px;
        flex-direction: row;
        bottom: 0;
        top: auto;
    }
}


