:root { 
    --bg-dark: #0b141a; --sidebar-bg: #111b21; --accent: #faf757; 
    --msg-in: #202c33; --msg-out: #005c4b; --text-main: #e9edef; --text-dim: #8696a0; 
    --ai-box: #1a2228; --wa-green: #25D366; --ai-blue: #34b7f1;
}

html, body { min-height: 100%; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: var(--bg-dark); color: var(--text-main); display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; }
/* Reset global para que el padding no afecte el ancho calculado */
* {
    box-sizing: border-box;
}

html, body { height: 100%; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: var(--bg-dark); color: var(--text-main); display: flex; flex-direction: column; min-height: 100vh; overflow-y: auto; overflow-x: hidden; }

/* Bloqueo de scroll solo para el Dashboard en Desktop (mantiene el diseño tipo App) */
@media (min-width: 769px) {
    body:has(.crm-container) { height: 100vh; overflow: hidden; }

    /* Distribución proporcional del header para centrar y expandir stats */
    .header-logo-link { flex: 1; }
    .header-actions-group { flex: 1; justify-content: flex-end; }

    /* El contenedor de stats toma el espacio central */
    .dashboard-stats {
        flex: 3;
        margin: 0 15px;
        flex-wrap: nowrap; /* Evita que bajen a otra fila en desktop */
    }

    /* Forzar ancho igual para todas las tarjetas */
    .stat-card {
        flex: 1;
        min-width: 90px;
        max-width: 200px; /* Limite para que no se estiren demasiado */
    }
}

.crm-header { flex-shrink: 0; background: var(--sidebar-bg); padding: 15px 20px; border-bottom: 1px solid #313d45; z-index: 1000; display: flex; flex-direction: column; gap: 15px; }
.header-top { display: flex; align-items: center; justify-content: space-between; width: 100%; flex-wrap: wrap; gap: 10px; }

/* Estilos base (Móvil primero o neutral) */
.header-logo-link { text-decoration: none; display: flex; align-items: center; }
.header-actions-group { display: flex; gap: 8px; align-items: center; }

.dashboard-stats { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.stat-card { background: #2a3942; padding: 8px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; transition: 0.3s; text-align: center; min-width: 60px; position: relative; overflow: hidden; }
.stat-card:hover { border-color: var(--accent); background: #3b4a54; }
.stat-card .num { display: block; font-size: 16px; font-weight: bold; color: var(--accent); }
.stat-card .lab { display: block; font-size: 9px; color: var(--text-dim); text-transform: uppercase; font-weight: bold; }

/* Por defecto (escritorio): Mostrar nombre completo, ocultar abreviado */
.stat-card .lab-full { display: inline; }
.stat-card .lab-short { display: none; }

/* Barras de color en tarjetas de estado */
.stat-card::after { content: ''; position: absolute; bottom: 0; left: 0; width: 100%; height: 4px; }

.total-card::after { 
    background: linear-gradient(to right, 
        #d63384 20%, 
        var(--ai-blue) 20%, var(--ai-blue) 40%, 
        #ea4335 40%, #ea4335 60%, 
        var(--accent) 60%, var(--accent) 80%, 
        #fd7e14 80%
    ); 
}
.total-card .num { color: #fff; }

.status-card-1::after { background: #d63384; }
.status-card-1 .num { color: #d63384; }

.status-card-2::after { background: var(--ai-blue); }
.status-card-2 .num { color: var(--ai-blue); }

.status-card-3::after { background: #ea4335; }
.status-card-3 .num { color: #ea4335; }

.status-card-4::after { background: var(--accent); }
.status-card-4 .num { color: var(--accent); }

.status-card-5::after { background: #fd7e14; } /* Naranja para PRUEBA */
.status-card-5 .num { color: #fd7e14; }

/* Menú de Usuario y Dropdown */
.user-menu-section { display: flex; align-items: center; gap: 20px; margin-left: auto; }

.dropdown { position: relative; display: flex; }
.dropdown-trigger { background: #2a3942; color: #fff; border: 1px solid #313d45; padding: 0 18px; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: bold; text-transform: uppercase; transition: 0.3s; display: flex; align-items: center; }
.dropdown-trigger:hover { border-color: var(--accent); background: #3b4a54; }

.dropdown-header {
    padding: 12px 16px;
    font-size: 12px;
    border-bottom: 1px solid #313d45;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.dropdown-header strong {
    color: var(--accent);
    font-weight: 800;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #233138;
    min-width: 250px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.5);
    z-index: 1001;
    border-radius: 8px;
    border: 1px solid #313d45;
    overflow: hidden;
    top: 100%;
    margin-top: 5px;
}

/* Puente de seguridad (invisible) para evitar que el menú se cierre al mover el mouse */
.dropdown-content::before {
    content: "";
    position: absolute;
    top: -15px; /* Cubre el espacio sobre el menú */
    left: 0;
    right: 0;
    height: 15px;
    background: transparent;
}

.dropdown-content a {
    color: #e9edef;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 13px;
    transition: background 0.2s, color 0.2s;
}

.dropdown-content a:hover { background-color: #2a3942; color: var(--accent); }

/* Iconos en gris para Perfil y Usuarios */
.icon-gray {
    filter: contrast(0.1);
    opacity: 0.7;
    display: inline-block;
    transition: filter 0.2s, opacity 0.2s;
}
.dropdown-content a:hover .icon-gray {
    filter: contrast(0.1);
    opacity: 1;
}

.dropdown-divider { border: 0; border-top: 1px solid #313d45; margin: 0; }
.logout-link { color: #ea4335 !important; }
.logout-link:hover { background-color: rgba(234, 67, 53, 0.1) !important; }

.dropdown-content.show { display: block; }

.search-container { width: 100%; display: grid; grid-template-columns: 1fr 1fr 1fr 1fr auto; gap: 12px; align-items: end; padding: 15px; border-radius: 8px; box-sizing: border-box; }
.search-box { display: flex; flex-direction: column; gap: 5px; }
.search-box label { font-size: 10px; color: var(--accent); font-weight: bold; text-transform: uppercase; }
input, select { background: #2a3942; border: 1px solid #3b4a54; padding: 8px 10px; border-radius: 6px; color: white; outline: none; font-size: 13px; margin-top: 5px;}

.main-content { flex-grow: 1; overflow-y: auto; padding: 10px; }
.chat-wrapper { max-width: 1400px; margin: 0 auto; height: auto; }

.client-thread { background: var(--sidebar-bg); overflow: hidden; display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 450px; }

.status-1 { border-left-color: #d63384; } .status-2 { border-left-color: var(--ai-blue); } .status-3 { border-left-color: #ea4335; } .status-4 { border-left-color: var(--accent); } .status-5 { border-left-color: #fd7e14; }

.client-header { flex-shrink: 0; background: #202c33; padding: 12px 20px; border-bottom: 1px solid #333; display: flex; justify-content: space-between; align-items: center; }
.client-header h3 { margin: 0; color: var(--accent); font-size: 16px; display: flex; align-items: center; gap: 10px; }

.btn-ui { border: none; padding: 8px 15px; border-radius: 5px; font-size: 11px; font-weight: bold; cursor: pointer; text-transform: uppercase; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; transition: opacity 0.2s, background 0.2s; color: #000; }
.btn-ui:hover { opacity: 0.9; }
.btn-whatsapp { background: var(--wa-green); color: white; font-size: 10px; padding: 4px 10px; }
.btn-save { background: var(--accent); color: #0b141a; width: 100%; }
.btn-ai { background: var(--ai-blue); color: #fff; width: 100%; }

.client-body { display: flex; flex-grow: 1; overflow: hidden; border-top: 1px solid #222; }
.chat-column { flex: 1.4; display: flex; flex-direction: column; border-right: 1px solid #313d45; overflow: hidden; }
.message-area { flex-grow: 1; padding: 0 20px 20px; display: flex; flex-direction: column; background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png'); background-blend-mode: overlay; overflow-y: auto; scroll-behavior: smooth; }

.day-group {
    display: flex;
    flex-direction: column;
    padding-bottom: 10px;
}

.human-reply-area { padding: 10px 15px; background: #202c33; display: none; align-items: flex-end; gap: 10px; border-top: 1px solid #313d45; position: relative; }
.reply-input { flex-grow: 1; background: #2a3942; border: none; border-radius: 8px; color: white; padding: 10px 15px; min-height: 20px; max-height: 120px; overflow-y: auto; outline: none; font-size: 14px; line-height: 1.4; }
.reply-input[contenteditable]:empty:before { content: 'Escribe un mensaje...'; color: var(--text-dim); }
.btn-send-wa { background: var(--wa-green); color: white; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; cursor: pointer; }
.emoji-trigger { cursor: pointer; padding-bottom: 10px; user-select: none; color: var(--text-dim); transition: color 0.2s; }
.emoji-trigger:hover { color: var(--text-main); }

.emoji-picker { position: absolute; bottom: 65px; left: 15px; background: #233138; border: 1px solid #3b4a54; border-radius: 8px; padding: 8px; display: none; grid-template-columns: repeat(6, 1fr); gap: 5px; z-index: 100; box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
.emoji-item { cursor: pointer; font-size: 18px; text-align: center; }

.management-area { flex: 1; background: var(--ai-box); padding: 20px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; }
.input-group { display: flex; flex-direction: column; gap: 8px; flex-grow: 1; }
.group-title { font-size: 10px; color: var(--accent); font-weight: bold; text-transform: uppercase; letter-spacing: 1px; }

.bubble { padding: 8px 14px; border-radius: 8px; font-size: 14px; max-width: 85%; position: relative; display: flex; flex-direction: column; overflow-wrap: break-word; }
.bubble:not(:last-child) { margin-bottom: 12px; } /* Separación entre burbujas */
.bubble:last-child { margin-bottom: 0; } /* Elimina el margen de la última burbuja en un grupo */
.cliente { align-self: flex-start; background: var(--msg-in); }
.bot { align-self: flex-end; background: var(--msg-out); }
.msg-time { font-size: 10px; color: var(--text-dim); align-self: flex-end; margin-top: 4px; line-height: 1; }

/* Separador de fecha estilo WhatsApp (Sticky) */
.chat-date-separator {
    display: flex;
    justify-content: center;
    padding: 15px 0;
    position: sticky;
    top: 0;
    z-index: 10;
}
.chat-date-separator span {
    background: #121b22; /* Fondo oscuro para mayor contraste */
    color: #8696a0;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.chat-image {
    max-width: 100px;
    max-height: 100px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

/* Etiqueta para identificar al remitente humano en el chat */
.msg-sender-label {
    font-size: 11px;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 4px;
}

textarea { width: 100%; background: #0b141a; border: 1px solid #3b4a54; color: var(--text-main); padding: 12px; border-radius: 8px; outline: none; resize: none; box-sizing: border-box; font-size: 13px; line-height: 1.5; flex-grow: 1; }
.ai-textarea { color: var(--ai-blue); border-color: #34b7f133; min-height: 180px; }
.note-textarea { color: #a5d6a7; min-height: 120px; }

.status-management { display: flex; gap: 20px; align-items: center; }
.status-edit-box { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.status-label-title { font-size: 10px; color: var(--accent); font-weight: bold; text-transform: uppercase; }
.last-update { font-size: 10px; color: var(--text-dim); margin-top: 2px; }
/* --- ADICIONAL PANTALLA CONFIGURACIÓN (ABM) --- */

/* Estilos Login */
.login-html, .login-html body { height: auto !important; overflow: auto !important; }
.login-body { display: flex; align-items: center; min-height: 100vh; background: var(--bg-dark); padding: 20px; box-sizing: border-box; }
.login-container { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; animation: fadeIn 0.6s ease-out; }
.login-logo-section { margin-bottom: 30px; text-align: center; }
.login-logo-section img { max-width: 100%; object-fit: contain; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4)); }
.login-logo-section h1 { color: var(--accent); margin: 0; font-size: 42px; letter-spacing: 2px; text-shadow: 0 4px 10px rgba(0,0,0,0.5); }

.login-card { 
    background: var(--sidebar-bg); 
    padding: 40px; 
    border-radius: 20px; 
    border: 1px solid #313d45; 
    width: 100%; 
    text-align: center; 
    box-shadow: 0 20px 50px rgba(0,0,0,0.6); 
    box-sizing: border-box; 
}
.login-card h2 { color: #81e7f2; margin-bottom: 30px; text-transform: uppercase; letter-spacing: 2px; margin-top: 0; font-size: 18px; opacity: 0.8; }
.login-card input { width: 100%; margin-bottom: 20px; box-sizing: border-box; padding: 12px; background: #2a3942; border: 1px solid #3b4a54; color: #81e7f2; border-radius: 6px; outline: none; font-size: 14px; }
.login-card input:focus { border-color: #81e7f2; }
.remember-container { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; color: var(--text-dim); font-size: 13px; cursor: pointer; justify-content: flex-start; }
.remember-container input[type="checkbox"] { width: auto !important; margin-bottom: 0 !important; cursor: pointer; }
.remember-container label { cursor: pointer; user-select: none; }
.btn-login { width: 100%; background: #81e7f2; color: #0b141a; padding: 12px; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; text-transform: uppercase; transition: 0.3s; font-size: 14px; }
.btn-login:hover { opacity: 0.9; transform: scale(1.02); }
.error-msg { color: #ea4335; font-size: 13px; margin-bottom: 20px; display: block; background: rgba(234, 67, 53, 0.1); padding: 10px; border-radius: 4px; border: 1px solid rgba(234, 67, 53, 0.3); }

/* Contenedor centralizado para que no ocupe todo el ancho */
.abm-container { 
    background: var(--sidebar-bg); 
    padding: 40px; 
    border-radius: 16px; 
    border: 1px solid #313d45; 
    width: 90%;
    max-width: 1000px; 
    margin: 50px auto; /* Centrado horizontal automático */
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.abm-container h2 { 
    color: var(--accent); 
    font-size: 20px;
    margin: 0;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid #313d45;
    padding-bottom: 15px;
    grid-column: 1 / -1;
}

/* Estilo para los grupos de inputs */
.abm-container .form-group { 
    margin-bottom: 0; 
}

/* Asegura que los contenedores de tablas ocupen todo el ancho del grid */
.abm-container > div {
    grid-column: 1 / -1;
}

.abm-container .btn-save {
    grid-column: 1 / -1;
}

/* Forzamos que los inputs del ABM se vean como los del buscador */
.abm-container input {
    width: 100%;
    box-sizing: border-box; /* Evita que el padding ensanche el input fuera del contenedor */
    display: block;
}

/* El link de volver */
.btn-back { 
    display: block; 
    text-align: center; 
    color: var(--text-dim); 
    text-decoration: none; 
    font-size: 13px; 
    margin-top: 25px; 
}

.btn-back:hover {
    color: var(--ai-blue);
}

/* Layout Principal tipo WhatsApp Web */
.crm-container {
    display: flex; /* Default: row layout */
    flex: 1;
    height: auto;
    overflow: hidden;
    background: var(--bg-dark);
}

/* Columna Izquierda: Lista de Chats */
.chats-sidebar {
    flex-basis: 350px; /* Use flex-basis instead of fixed width */
    background: var(--sidebar-bg);
    border-right: 1px solid #313d45;
    overflow-y: auto;
    flex-shrink: 0;
}

/* Estilos personalizados para todas las barras de scroll del sistema */
::-webkit-scrollbar {
    width: 6px;
    height: 6px; /* Para scroll horizontal */
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #313d45;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Compatibilidad global con Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #313d45 transparent;
}

.sidebar-title {
    padding: 15px;
    font-size: 14px;
    font-weight: bold;
    color: var(--accent);
    text-transform: uppercase;
    background: var(--sidebar-bg);
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: 1px solid #313d45;
}

.chat-item {
    padding: 15px;
    border-bottom: 1px solid #222;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-left: 4px solid transparent;
    padding-left: 11px; /* 15px - 4px de borde */
}

.chat-item:hover { background: #2a3942; }
.chat-item.active { background: #2a3942; }

/* Estilo para chats no leídos que no están activos */
.chat-item.unread {
    background: var(--ai-blue);
}
.chat-item.unread .name {
    font-weight: bold;
}
.chat-item.unread .last-msg {
    color: var(--text-main);
}

/* Colores de estado en la lista de chats */
.chat-item[data-status="1"] { border-left-color: #d63384; }      /* Atendido por Bot */
.chat-item[data-status="2"] { border-left-color: var(--ai-blue); } /* Interviene Humano */
.chat-item[data-status="3"] { border-left-color: #ea4335; }     /* Caído */
.chat-item[data-status="4"] { border-left-color: var(--accent); }  /* Cliente */
.chat-item[data-status="5"] { border-left-color: #fd7e14; opacity: 0.3;}  /* Prueba */

.chat-item .name { font-weight: bold; color: var(--accent); font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.chat-item .last-msg { font-size: 12px; color: var(--text-dim); white-space: normal; overflow-wrap: break-word; }

/* Columna Derecha: Visor de Chat */
.chat-viewer {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    position: relative;
}

.chat-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
    text-align: center;
    padding-top: 10px;
}

/* Ocultar todos los hilos por defecto */
.client-thread { display: none; height: 100%; flex-direction: column; }
.client-thread.active { display: flex; }

/* Footer */
.crm-footer {
    flex-shrink: 0;
    text-align: center;
    padding: 10px;
    font-size: 11px;
    color: var(--text-dim);
    background: var(--sidebar-bg);
    border-top: 1px solid #313d45;
    margin-top: auto;
}
.crm-footer a { color: var(--text-dim); text-decoration: none; font-weight: bold; }
.crm-footer a:hover { color: var(--accent); }

/* Documentación / Instrucciones */
.docs-container { padding: 40px 20px; overflow-y: auto; flex: 1; }
.docs-container h1 { color: var(--accent); text-align: center; margin-bottom: 40px; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #313d45; padding-bottom: 20px; margin-top: 0; }
.docs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.docs-card { background: var(--sidebar-bg); padding: 25px; border-radius: 12px; border: 1px solid #313d45; transition: 0.3s; }
.docs-card:hover { border-color: var(--accent); transform: translateY(-5px); box-shadow: 0 5px 15px rgba(0,0,0,0.3); }
.docs-card h3 { color: var(--ai-blue); margin-top: 0; display: flex; align-items: center; gap: 10px; font-size: 18px; margin-bottom: 15px; }
.docs-card p, .docs-card li { font-size: 14px; line-height: 1.6; color: var(--text-dim); }
.docs-card strong { color: var(--text-main); }
.docs-card ul { padding-left: 20px; margin-bottom: 0; }

/* --- Auditoria Page --- */
.audit-container {
    max-width: 1000px;
    margin: 30px auto;
    background: var(--sidebar-bg);
    border: 1px solid #313d45;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.audit-chat-area {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-blend-mode: overlay;
    background-color: #0b141a;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.audit-input-area {
    padding: 15px;
    background: #202c33;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid #313d45;
}

/* Modal de Zoom de Imagen */
.image-modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.9); align-items: center; justify-content: center; }
.image-modal-content { 
    margin: auto; 
    display: block; 
    max-width: 90%; 
    max-height: 90%; 
    object-fit: contain; 
    animation: zoom 0.3s; 
    border: 3px solid #6b6969;
    border-radius: 4px;
}
.image-modal-close { 
    position: absolute; 
    top: 20px; 
    right: 20px; 
    color: #111; 
    background: rgba(255,255,255,0.9);
    width: 45px; height: 45px; 
    border-radius: 50%; 
    font-size: 30px; 
    font-weight: normal; 
    transition: 0.3s; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center;
}
.image-modal-close:hover, .image-modal-close:focus { background: var(--accent); color: #0b141a; text-decoration: none; transform: scale(1.1); }
@keyframes zoom { from {transform:scale(0)} to {transform:scale(1)} }

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

/* --- Media Queries for Responsiveness --- */
@media (max-width: 768px) {
    /* En móvil, el logo no debe crecer para que los botones de la derecha queden cerca */
    .header-logo-link { flex: 0 0 auto; }

    html, body {
        height: auto;
        overflow-y: auto;
    }

    .crm-header {
        padding: 10px 15px; /* Adjust padding */
        gap: 10px;
    }
    .header-top {
        flex-direction: row; /* Mantiene logo y cuenta en la misma línea */
        align-items: center;
        gap: 10px;
    }
    .dashboard-stats {
        order: 3;
        width: 100%;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px; /* Espacio mínimo entre tarjetas */
    }
    .stat-card {
        padding: 6px 2px;
        flex: 1;
        min-width: 0; /* Permite que la tarjeta se encoja por debajo de su contenido si es necesario */
    }
    .stat-card .num {
        font-size: 14px;
    }
    .stat-card .lab {
        font-size: 8px;
    }
    /* En móvil (hasta 768px): Ocultar nombre completo, mostrar abreviado */
    .stat-card .lab-full { display: none; }
    .stat-card .lab-short { display: inline; }

    .search-container {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 0 0px 10px; /* Add padding to match header */
    }
    .search-box label {
        font-size: 9px;
    }
    input, select {
        padding: 6px 8px;
        font-size: 12px;
    }
    .btn-ui {
        padding: 6px 12px;
        font-size: 10px;
    }

    .crm-container {
        flex-direction: column; /* Stack sidebar and chat viewer */
        overflow-y: auto; /* Allow scrolling for the whole container */
    }

    .chats-sidebar {
        width: 100%; /* Full width */
        flex-basis: auto;
        border-right: none;
        border-bottom: 1px solid #313d45; /* Add a bottom border */
        max-height: 32vh; /* Limit height to prevent it from taking too much space */
    }

    .chat-viewer {
        width: 100%; /* Full width */
        flex-grow: 1;
    }

    .client-thread {
        height: auto; /* Allow content to define height */
        min-height: auto;
        margin-bottom: 10px; /* Reduce margin */
    }

    .client-header {
        align-items: flex-start;
        gap: 10px;
        padding: 10px 15px;
    }
    .client-header h3 {
        font-size: 15px;
    }
    .status-management {
        justify-content: space-between; /* Distribute status elements */
    }

    .client-body {
        flex-direction: column; /* Stack chat column and management area */
        overflow-y: auto; /* Allow scrolling for client body */
    }
    .chat-column {
        flex: none; /* Remove flex sizing */
        width: 100%; /* Full width */
        border-right: none;
        border-bottom: 1px solid #313d45; /* Add a bottom border */
    }
    .message-area {
        padding: 15px; /* Adjust padding */
        min-height: 300px; /* Ensure some minimum height */
    }
    .human-reply-area {
        padding: 8px 10px;
    }
    .reply-input {
        padding: 8px 12px;
        font-size: 13px;
    }
    .btn-send-wa {
        width: 35px;
        height: 35px;
        font-size: 16px;
    }
    .emoji-picker {
        bottom: 55px; /* Adjust position */
        left: 10px;
        grid-template-columns: repeat(5, 1fr); /* Fewer columns for emojis */
    }

    .management-area {
        flex: none; /* Remove flex sizing */
        padding: 15px; /* Adjust padding */
    }
    .input-group {
        gap: 6px;
    }
    .group-title {
        font-size: 9px;
    }
    textarea {
        padding: 10px;
        font-size: 12px;
    }
    .ai-textarea, .note-textarea {
        min-height: 100px; /* Adjust min-heights */
    }

    .bubble {
        max-width: 90%; /* Allow bubbles to take more width */
        padding: 7px 12px;
        font-size: 13px;
    }
    .msg-time {
        font-size: 9px;
    }

    .login-card, .abm-container {
        padding: 20px 15px;
        margin: 20px auto; /* Adjust margin */
        grid-template-columns: 1fr;
        width: 85%;
    }
    .login-card h2, .abm-container h2 {
        font-size: 18px;
    }
    .login-card input, .abm-container input {
        padding: 10px;
        font-size: 13px;
    }
    .btn-login {
        padding: 10px;
        font-size: 13px;
    }

    .docs-container {
        padding: 20px 10px;
        height: auto; /* Allow content to define height */
    }
    .docs-container h1 {
        font-size: 24px;
        margin-bottom: 20px;
        padding-bottom: 15px;
    }
    .docs-grid {
        grid-template-columns: 1fr; /* Single column on mobile */
        gap: 15px;
    }
    .docs-card {
        padding: 20px;
    }
    .docs-card h3 {
        font-size: 16px;
    }
    .docs-card p, .docs-card li {
        font-size: 13px;
    }

    .audit-container {
        margin: 10px;
    }
    .audit-chat-area {
        padding: 15px;
    }
    .audit-input-area {
        padding: 8px 10px;
    }

    .image-modal-close {
        top: 10px;
        right: 10px;
        width: 35px;
        height: 35px;
        font-size: 24px;
    }
}

@media (max-width: 480px) {
    .search-container {
        grid-template-columns: 1fr 1fr; /* Two columns on mobile */
        padding: 10px;
    }
    .dashboard-stats {
        gap: 5px;
        flex-wrap: nowrap; /* Fuerza a que todo quede en una fila */
        overflow-x: auto; /* Permite scroll horizontal si no caben */
        justify-content: center;
    }
    .dashboard-stats::-webkit-scrollbar { display: none; } /* Oculta la barra de scroll */
    .stat-card {
    }
    /* En móvil muy pequeño (hasta 480px): Asegurar que se muestre el abreviado */
    .stat-card .lab-full { display: none; }
    .stat-card .lab-short { display: inline; }

    .crm-header {
        padding: 10px;
    }
    .config-link {
        height: 35px;
        padding: 8px 4px;
    }
    .config-icon {
        font-size: 18px;
    }
    .btn-whatsapp {
        font-size: 9px;
        padding: 3px 8px;
    }
    .sidebar-title {
        padding: 10px;
        font-size: 13px;
    }
    .chat-item {
        padding: 10px;
        padding-left: 6px; /* Adjust for 4px border */
    }
    .chat-item .name {
        font-size: 13px;
    }
    .chat-item .last-msg {
        font-size: 11px;
    }
    .emoji-picker {
        grid-template-columns: repeat(4, 1fr); /* Even fewer columns for emojis */
    }
}
.image-modal-close { 
    position: absolute; 
    top: 20px; 
    right: 20px; 
    color: #111; 
    background: rgba(255,255,255,0.9);
    width: 45px; height: 45px; 
    border-radius: 50%; 
    font-size: 30px; 
    font-weight: normal; 
    transition: 0.3s; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center;
}

/* Estilos para Tablas ABM */
.user-table { width: 100%; border-collapse: collapse; color: var(--text-main); font-size: 14px; grid-column: 1 / -1; }
.user-table th { text-align: left; padding: 12px; border-bottom: 2px solid #313d45; color: var(--accent); text-transform: uppercase; font-size: 11px; }
.user-table td { padding: 12px; border-bottom: 1px solid #222; }
.user-table tr:hover { background: rgba(255,255,255,0.05); }
.role-badge { padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: bold; text-transform: uppercase; }
.role-admin { background: var(--ai-blue); color: #fff; }
.role-editor { background: var(--wa-green); color: #fff; }
.role-lector { background: #3b4a54; color: var(--text-dim); }
.btn-delete { color: #ea4335; cursor: pointer; border: none; background: none; font-size: 12px; font-weight: bold; }
.btn-delete:hover { text-decoration: underline; }
.image-modal-close:hover, .image-modal-close:focus { background: var(--accent); color: #0b141a; text-decoration: none; transform: scale(1.1); }
@keyframes zoom { from {transform:scale(0)} to {transform:scale(1)} }

/* --- LOADING OVERLAY --- */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 9999;
    color: var(--accent);
    font-weight: bold;
    gap: 15px;
}
.loader-spinner {
    border: 4px solid #2a3942;
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin-loader 1s linear infinite;
}
@keyframes spin-loader { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.introjs-tooltiptext{
    color: var(--accent);
}
.introjs-tooltip-title{
    color: var(--accent);
}