/* --- Variables y Configuración Global --- */
:root {
    --primary: #2a5298;
    --primary-dark: #1e3c72;
    --secondary: #2c3e50;
    --success: #27ae60;
    --info: #2980b9;
    --warning: #f39c12;
    --danger: #e74c3c;
    --text-main: #2d3436;
    --text-muted: #636e72;
    --bg-light: #f4f7f6;
    --sidebar-width: 260px;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* --- Reset Crítico --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    position: relative;
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* --- Layout Principal --- */
.dashboard-layout { display: flex; width: 100%; }

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--secondary);
    color: white;
    height: 100vh;
    position: fixed;
    transition: 0.3s;
    z-index: 2000;
    overflow-y: auto;
}

.sidebar-header { padding: 30px 20px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-header h2 { font-size: 20px; font-weight: 800; }

.sidebar-menu { padding: 20px 0; list-style: none; }
.sidebar-menu li { padding: 5px 20px; }
.sidebar-menu a {
    color: #dfe6e9; text-decoration: none; display: flex; align-items: center; gap: 15px;
    padding: 12px 15px; border-radius: 12px; transition: 0.3s; font-size: 15px;
}
.sidebar-menu a:hover, .sidebar-menu a.active { background-color: #2a5298 !important; color: white; }

.main-area {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

/* Estado colapsado (escondido) de la sidebar en Desktop */
.sidebar-is-collapsed .sidebar {
    transform: translateX(-100%);
}

.sidebar-is-collapsed .main-area {
    margin-left: 0;
}

/* Evitar parpadeo inicial pero permitir animación después */
.no-transition .sidebar,
.no-transition .main-area {
    transition: none !important;
}

.topbar {
    height: 70px; background: white; display: flex; align-items: center;
    justify-content: space-between; padding: 0 30px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.dashboard-content { padding: 30px; width: 100%; }

.stats-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 25px;
    margin-bottom: 40px;
}

.stat-card {
    background: white;
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 25px;
    text-decoration: none !important;
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1 1 240px;
    max-width: 350px;
    margin-bottom: 0; /* Managed by gap in flex container */
}

.table-responsive { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: auto; }
th, td { padding: 15px; text-align: left; border-bottom: 1px solid #eee; }

/* ============================================================
   RESPONSIVIDAD: OPTIMIZACIÓN VERTICAL (SIN MOVIMIENTO LATERAL)
   ============================================================ */
@media (max-width: 768px) {
    /* 1. Forzar que todo sea una sola columna y quepa al 100% */
    .dashboard-layout { flex-direction: column; }
    
    .main-area { 
        margin-left: 0 !important; 
        width: 100% !important;
        overflow-x: hidden;
    }

    .sidebar { transform: translateX(-100%); width: 280px; }
    .sidebar.mobile-open { transform: translateX(0); }

    .topbar { padding: 0 15px; position: sticky; top: 0; z-index: 1500; }
    .topbar-user .user-info { display: none; }

    .dashboard-content { padding: 12px !important; }

    /* 2. Grids a una sola columna vertical */
    [style*="display: grid"], 
    [style*="display:grid"] {
        grid-template-columns: 1fr !important;
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    .stats-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
        width: 100% !important;
    }

    .stat-card {
        padding: 15px !important;
        gap: 10px !important;
        margin-bottom: 15px !important;
    }

    /* 3. Tablas Verticales: Prohibir scroll horizontal y ajustar al ancho */
    .table-responsive {
        overflow-x: hidden !important; /* Prohibido mover a los lados */
        width: 100% !important;
        padding: 0;
        margin: 0;
    }

    table {
        min-width: 100% !important;
        max-width: 100% !important;
        table-layout: fixed; /* Fuerza a las celdas a no empujar el ancho */
    }

    /* Ocultar celdas secundarias de forma muy agresiva */
    .hide-mobile, th:nth-child(3):not(.table-stack-mobile th), td:nth-child(3):not(.table-stack-mobile td), th:nth-child(4):not(.table-stack-mobile th), td:nth-child(4):not(.table-stack-mobile td), th:nth-child(5):not(.table-stack-mobile th), td:nth-child(5):not(.table-stack-mobile td), th:nth-child(6):not(.table-stack-mobile th), td:nth-child(6):not(.table-stack-mobile td), th:nth-child(7):not(.table-stack-mobile th), td:nth-child(7):not(.table-stack-mobile td) {
        display: none !important;
    }

    /* Permitir ver la columna de Acciones en el modal de series del Almacén */
    #modal-material-series th, 
    #modal-material-series td {
        display: table-cell !important;
    }

    /* Estilo de Tarjetas para Tablas Apiladas (.table-stack-mobile) en móviles */
    .table-stack-mobile, 
    .table-stack-mobile thead, 
    .table-stack-mobile tbody, 
    .table-stack-mobile tr, 
    .table-stack-mobile th, 
    .table-stack-mobile td {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box;
    }
    .table-stack-mobile thead {
        display: none !important;
    }
    .table-stack-mobile tr {
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 20px !important;
        padding: 18px !important;
        margin-bottom: 20px !important;
        box-shadow: 0 4px 15px rgba(0,0,0,0.015) !important;
        display: block !important;
    }
    .table-stack-mobile td {
        border: none !important;
        border-bottom: 1px dashed #f1f5f9 !important;
        padding: 12px 0 !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        text-align: right !important;
        font-size: 13px !important;
        min-height: 44px !important;
    }
    .table-stack-mobile td:last-child {
        border-bottom: none !important;
        margin-bottom: 0 !important;
    }
    .table-stack-mobile td::before {
        content: attr(data-label);
        font-weight: 800;
        color: #64748b;
        font-size: 10px;
        text-transform: uppercase;
        float: left;
        margin-right: 15px;
        text-align: left;
        letter-spacing: 0.5px;
    }

    /* Optimización de Fila de Acciones en Tarjetas de Tabla */
    .table-stack-mobile td[data-label="Acciones"] {
        justify-content: center !important;
        padding: 15px 0 5px 0 !important;
        border-bottom: none !important;
        min-height: 54px !important;
    }
    .table-stack-mobile td[data-label="Acciones"]::before {
        display: none !important;
    }
    .table-stack-mobile td[data-label="Acciones"] > div {
        justify-content: center !important;
        width: 100% !important;
        gap: 12px !important;
    }
    .table-stack-mobile td[data-label="Acciones"] button,
    .table-stack-mobile td[data-label="Acciones"] a {
        width: 44px !important;
        height: 44px !important;
        font-size: 16px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 12px !important;
        flex-shrink: 0 !important;
        margin: 0 !important;
    }

    /* Mobile Bottom Sheets para Modales */
    #modal-material-add > div, 
    #modal-material-edit > div, 
    #modal-material-ajustar > div, 
    #modal-material-series > div,
    #scanner-lote-modal > div,
    #scanner-modal > div,
    #modal-gasto > div {
        position: absolute !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 28px 28px 0 0 !important;
        padding: 30px 20px calc(20px + env(safe-area-inset-bottom, 15px)) 20px !important;
        animation: bottomSheetSlideUp 0.3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both !important;
        box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.15) !important;
        margin: 0 !important;
    }

    /* Safe Area insets para elementos estructurales */
    .sidebar {
        padding-top: calc(20px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    }
    .topbar {
        padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
        height: calc(70px + env(safe-area-inset-top, 0px)) !important;
    }

    /* Botones y targets táctiles ampliados para dedos */
    button, .btn-primary, .btn-login, a.btn-primary, .btn-primary a {
        min-height: 44px;
        touch-action: manipulation;
    }

    @keyframes bottomSheetSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
}

/* --- Real-Time Chat System (WhatsApp Web Clone Theme) --- */
:root {
    --wa-green: #008069;
    --wa-green-dark: #005e4c;
    --wa-bg: #efeae2;
    --wa-bubble-me: #d9fdd3;
    --wa-bubble-them: #ffffff;
    --wa-text: #111b21;
    --wa-text-muted: #667781;
    --wa-gray-light: #f0f2f5;
    --wa-gray-hover: #f5f6f6;
    --wa-border: #e9edef;
    --wa-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.chat-widget-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 15px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.chat-trigger-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--wa-green);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 128, 105, 0.3);
    font-size: 26px;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.15);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.chat-trigger-btn:hover {
    transform: scale(1.06) translateY(-2px);
    background: var(--wa-green-dark);
    box-shadow: 0 10px 28px rgba(0, 128, 105, 0.4);
}

.chat-unread-total-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #25d366;
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}

.chat-window {
    width: 420px;
    height: 580px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: var(--wa-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--wa-border);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(25px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-header {
    background: var(--wa-green);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-back-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-back-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.chat-header-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-header-info {
    display: flex;
    flex-direction: column;
}

.chat-header h3 {
    font-size: 14.5px;
    font-weight: 600;
    margin: 0;
    color: white;
}

.chat-header-status {
    font-size: 11px;
    opacity: 0.85;
    margin-top: 1px;
}

.chat-close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 24px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    line-height: 1;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.chat-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: #ffffff;
}

/* WhatsApp Mobile-Style Navigation: 100% width sliding columns */
.chat-sidebar-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: white;
    flex-shrink: 0;
}

.chat-messages-area {
    width: 100%;
    height: 100%;
    display: none; /* Oculto inicialmente para el staff hasta que abre un chat */
    flex-direction: column;
    background-color: var(--wa-bg);
    background-image: radial-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px);
    background-size: 18px 18px;
    flex-shrink: 0;
}

/* Active chat views (for Staff sliding navigation) */
.chat-window.chat-view-active .chat-sidebar-container {
    display: none;
}

.chat-window.chat-view-active .chat-messages-area {
    display: flex;
}

/* Client Support layout: always direct to messages, hide sidebar completely */
.chat-body.client-chat .chat-sidebar-container {
    display: none;
}

.chat-body.client-chat .chat-messages-area {
    display: flex;
}

/* Sidebar Search Section */
.chat-sidebar-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--wa-border);
    background: white;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-new-chat {
    width: 100%;
    padding: 8px 12px;
    background: var(--wa-green);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    font-size: 12px;
    transition: background 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.btn-new-chat:hover {
    background: var(--wa-green-dark);
}

.chat-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.chat-search-icon {
    position: absolute;
    left: 10px;
    color: var(--wa-text-muted);
    font-size: 12px;
}

.chat-search-wrapper input {
    width: 100%;
    padding: 7px 10px 7px 32px;
    border: none;
    border-radius: 8px;
    background: var(--wa-gray-light);
    outline: none;
    font-size: 12.5px;
    color: var(--wa-text);
    transition: 0.2s;
}

.chat-search-wrapper input:focus {
    background: #ffffff;
    box-shadow: 0 0 0 1.5px rgba(0, 128, 105, 0.25);
}

.chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
}

/* Customized Scrollbars for WhatsApp Style */
.chat-sidebar-list::-webkit-scrollbar,
.chat-messages-list::-webkit-scrollbar,
.chat-modal-results::-webkit-scrollbar {
    width: 6px;
}
.chat-sidebar-list::-webkit-scrollbar-track,
.chat-messages-list::-webkit-scrollbar-track,
.chat-modal-results::-webkit-scrollbar-track {
    background: transparent;
}
.chat-sidebar-list::-webkit-scrollbar-thumb,
.chat-messages-list::-webkit-scrollbar-thumb,
.chat-modal-results::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Conversation List Items */
.chat-conversation-item {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--wa-border);
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-conversation-item:hover {
    background: var(--wa-gray-hover);
}

.chat-conversation-item.active {
    background: var(--wa-gray-light);
}

.chat-conv-avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}

.chat-conv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: #54656f;
    background: #e9edef;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-conv-status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid white;
    background: #cbd5e1;
}

.chat-conv-status-dot.online {
    background: #25d366;
}

.chat-conv-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-conv-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.chat-conv-name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--wa-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-time {
    font-size: 10.5px;
    color: var(--wa-text-muted);
    flex-shrink: 0;
}

.chat-conv-preview {
    font-size: 12px;
    color: var(--wa-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 3px;
    line-height: 1.2;
}

.chat-unread-badge {
    background: #25d366;
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    margin-left: auto;
    margin-top: 3px;
    box-shadow: 0 1px 3px rgba(37, 211, 102, 0.2);
}

/* Chat Messages Panel */
.chat-messages-list {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-messages-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--wa-text-muted);
    text-align: center;
    padding: 20px;
}

.chat-messages-placeholder i {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.35;
}

.chat-messages-placeholder p {
    font-size: 13.5px;
    margin: 0;
    max-width: 240px;
    line-height: 1.4;
}

/* WhatsApp Message Bubbles with Tail design */
.chat-msg-wrapper {
    display: flex;
    flex-direction: column;
    margin-bottom: 6px;
    position: relative;
    width: 100%;
}

.chat-msg-wrapper.me {
    align-items: flex-end;
}

.chat-msg-wrapper.them {
    align-items: flex-start;
}

.chat-msg-author {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--wa-text-muted);
    margin-bottom: 2px;
    padding: 0 6px;
}

.chat-msg {
    padding: 8px 12px;
    font-size: 13.5px;
    line-height: 1.4;
    border-radius: 8px;
    position: relative;
    max-width: 82%;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    word-break: break-word;
}

.chat-msg.me {
    background: var(--wa-bubble-me);
    color: var(--wa-text);
    border-top-right-radius: 0px;
}

.chat-msg.me::after {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-left-color: var(--wa-bubble-me);
    border-top-color: var(--wa-bubble-me);
}

.chat-msg.them {
    background: var(--wa-bubble-them);
    color: var(--wa-text);
    border-top-left-radius: 0px;
}

.chat-msg.them::after {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: var(--wa-bubble-them);
    border-top-color: var(--wa-bubble-them);
}

/* Timestamp and Checkmarks inside bubble */
.chat-msg-meta {
    font-size: 9.5px;
    color: var(--wa-text-muted);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: 4px;
    gap: 3px;
    text-align: right;
    line-height: 1;
}

.chat-typing-indicator {
    font-size: 11.5px;
    color: var(--wa-text-muted);
    font-style: italic;
    padding: 4px 16px;
    height: 20px;
    font-weight: 500;
}

/* WhatsApp Composer / Input Footer */
.chat-footer {
    padding: 8px 10px;
    background: var(--wa-gray-light);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chat-footer-action-btn {
    background: none;
    border: none;
    color: #54656f;
    cursor: pointer;
    font-size: 18px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.chat-footer-action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.chat-input {
    flex: 1;
    border: none;
    padding: 9px 15px;
    border-radius: 20px;
    outline: none;
    font-size: 13.5px;
    color: var(--wa-text);
    background: white;
}

.chat-send-btn {
    background: var(--wa-green);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.chat-send-btn:hover {
    background: var(--wa-green-dark);
}

.chat-send-btn:disabled {
    background: #cbd5e1;
    color: white;
    cursor: not-allowed;
}

/* Search Contacts Modal (WhatsApp style) */
.chat-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(11, 20, 26, 0.7);
    z-index: 10001;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.chat-modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 16px 36px rgba(0,0,0,0.15);
    overflow: hidden;
    animation: scaleUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes scaleUp {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.chat-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--wa-green);
    color: white;
}

.chat-modal-header h3 {
    margin: 0;
    font-size: 15px;
    color: white;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-modal-header button {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.8);
    transition: color 0.2s;
    line-height: 1;
}

.chat-modal-header button:hover {
    color: white;
}

.chat-modal-body {
    padding: 16px;
}

.chat-modal-search-group {
    margin-bottom: 16px;
}

.chat-modal-search-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--wa-text-muted);
    margin-bottom: 6px;
}

.chat-modal-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.chat-modal-search-input-wrapper i {
    position: absolute;
    left: 12px;
    color: var(--wa-text-muted);
}

.chat-modal-search-input-wrapper input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border: 1px solid var(--wa-border);
    background: var(--wa-gray-light);
    border-radius: 8px;
    outline: none;
    font-size: 13px;
    color: var(--wa-text);
    transition: 0.2s;
}

.chat-modal-search-input-wrapper input:focus {
    background: white;
    border-color: var(--wa-green);
    box-shadow: 0 0 0 2px rgba(0, 128, 105, 0.15);
}

.chat-modal-results {
    max-height: 260px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid var(--wa-border);
}

.chat-modal-placeholder {
    padding: 24px;
    text-align: center;
    color: var(--wa-text-muted);
    font-size: 13px;
}

/* Contact cards inside searches */
.chat-modal-contact-card {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--wa-border);
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-modal-contact-card:hover {
    background: var(--wa-gray-hover);
}

.chat-modal-contact-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: #54656f;
    background: #e9edef;
}

.chat-modal-contact-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-modal-contact-name-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-modal-contact-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--wa-text);
}

.chat-modal-contact-role-tag {
    font-size: 8px;
    font-weight: 700;
    padding: 1.5px 5px;
    border-radius: 4px;
}

.chat-modal-contact-role-tag.client {
    background: #dcfce7;
    color: #166534;
}

.chat-modal-contact-role-tag.admin {
    background: #f3e8ff;
    color: #6b21a8;
}

.chat-modal-contact-role-tag.staff {
    background: #e0f2fe;
    color: #075985;
}

.chat-modal-contact-email {
    font-size: 11px;
    color: var(--wa-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

@media (max-width: 768px) {
    .chat-window {
        width: calc(100% - 40px);
        height: calc(100% - 100px);
        bottom: 20px;
        right: 20px;
        border-radius: 12px;
    }
}

.chat-file-link {
    color: var(--wa-green-dark);
    font-weight: 600;
    text-decoration: underline;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.chat-file-link:hover {
    color: #111b21;
}
.chat-image-preview img {
    max-width: 100%;
    max-height: 180px;
    border-radius: 8px;
    border: 1px solid #dcdcdc;
    margin-top: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: transform 0.2s;
}
.chat-image-preview img:hover {
    transform: scale(1.02);
}


.ticket-form-pro {
    background: white;
    border-radius: 24px;
    padding: 30px;
    border: 1px solid var(--ticket-border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 2.5rem;
}

.ticket-table-pro {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
}

.ticket-row-pro {
    background: white;
    transition: all 0.2s ease;
    cursor: pointer;
}

.ticket-row-pro td {
    padding: 16px;
    border-top: 1px solid var(--ticket-border);
    border-bottom: 1px solid var(--ticket-border);
    vertical-align: middle;
}

.ticket-row-pro td:first-child { border-left: 1px solid var(--ticket-border); border-radius: 12px 0 0 12px; }
.ticket-row-pro td:last-child { border-right: 1px solid var(--ticket-border); border-radius: 0 12px 12px 0; }

.ticket-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.ticket-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.2s;
    font-size: 12px;
}

.ticket-action-btn:hover {
    transform: scale(1.1);
    filter: brightness(0.9);
}

/* --- Responsividad: Card Layout para Móvil --- */
@media (max-width: 768px) {
    .ticket-table-pro, .ticket-table-pro tbody, .ticket-table-pro thead, .ticket-table-pro tr {
        display: block !important;
    }
    
    .ticket-table-pro thead { display: none !important; }
    
    .ticket-row-pro {
        display: flex !important;
        flex-direction: column !important;
        background: white !important;
        border: 1px solid var(--ticket-border) !important;
        border-radius: 16px !important;
        margin-bottom: 1.5rem !important;
        padding: 15px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
    }
    
    .ticket-row-pro td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 8px 0 !important;
        border: none !important;
        width: 100% !important;
    }
    
    .ticket-row-pro td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 11px;
        color: var(--ticket-text-muted);
        text-transform: uppercase;
    }
    
    .ticket-row-pro td:first-child { border: none !important; border-radius: 0 !important; }
    .ticket-row-pro td:last-child { border: none !important; border-radius: 0 !important; justify-content: center !important; margin-top: 10px; border-top: 1px solid var(--ticket-border) !important; padding-top: 15px !important; }
}

    /* Ajustar celdas que quedan para que no se corten */
    td {
        word-wrap: break-word;
        white-space: normal !important;
        padding: 10px 5px !important;
        font-size: 13px !important;
    }

    /* --- Compactar Formulario de Tickets en Móvil --- */
    .ticket-form-container {
        padding: 15px !important;
        border-radius: 15px !important;
    }
    
    .ticket-form-container h3 {
        font-size: 14px !important;
        margin-bottom: 15px !important;
    }
    
    .ticket-form-container .input-group {
        margin-bottom: 12px !important;
    }
    
    .ticket-form-container input,
    .ticket-form-container select,
    .ticket-form-container textarea {
        padding: 10px !important;
        font-size: 12px !important;
        border-radius: 10px !important;
    }
    
    .ticket-form-container textarea {
        min-height: 80px !important;
    }
    
    .ticket-form-container button[type="submit"] {
        padding: 12px !important;
        font-size: 13px !important;
        border-radius: 10px !important;
    }

    /* --- Compactar el Menú Lateral (Sidebar) para que quepa todo --- */
    .sidebar-menu li {
        padding: 2px 15px !important;
    }
    .sidebar-menu a {
        padding: 10px 12px !important;
        font-size: 13px !important;
        gap: 10px !important;
    }
    .sidebar-header {
        padding: 20px 15px !important;
    }
    .sidebar-header h2 {
        font-size: 16px !important;
    }
    /* Asegurar que se pueda hacer scroll hasta el final y se vea Cerrar Sesión */
    .sidebar {
        padding-bottom: 120px !important; 
        height: 100% !important; /* Mejor que 100vh en móviles para evitar recortes de la barra de navegación */
        -webkit-overflow-scrolling: touch !important; /* Scroll suave en iOS */
    }

    /* Proporciones para móvil */
    .slider-container, .banner-carousel-container, .banner-slide {
        height: auto !important;
        aspect-ratio: 6 / 4; /* Todo en 6x4 */
    }
}

    /* --- Fix para Iconos --- */
    /* Asegurar que todos los iconos en botones/links esten centrados y se vean bien en movil */
    button, a {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
    }
    
    /* Si el icono es el unico elemento o debe estar centrado */
    button i, a i {
        margin: 0 !important;
        text-align: center !important;
    }
}

/* Breakpoint para Tablets */
@media (min-width: 481px) and (max-width: 900px) {
    .slider-container, .banner-carousel-container, .banner-slide {
        height: auto !important;
        aspect-ratio: 6 / 4;
    }
}

.banner-carousel-container {
    position: relative; 
    width: 100%; 
    max-width: 600px; 
    margin: 0 auto 30px auto; 
    border-radius: 20px; 
    overflow: hidden; 
    box-shadow: 0 15px 35px rgba(0,0,0,0.1); 
    background: #0f172a; 
    animation: fadeIn 0.8s ease-out;
    aspect-ratio: 6 / 4; /* Contenedor en 6x4 */
}

.banner-slide {
    min-width: 100%; 
    position: relative; 
    height: 100%; 
    display: flex;
    align-items: center;
    justify-content: center;
}

.banner-slide img {
    width: 100%; 
    height: 100%; 
    object-fit: cover; 
    object-position: center;
    display: block;
    aspect-ratio: 6 / 4; /* Imagen en 6x4 */
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.banner-slide:hover img {
    transform: scale(1.01); /* Efecto sutil de calidez/interacción */
}

.mobile-only { display: none; }
@media (max-width: 768px) {
    .mobile-only { display: inline-block; }
}

/* --- AlineaciÃ³n estricta a la izquierda para formularios en mÃ³vil --- */
@media (max-width: 768px) {
    .controls-container, .input-group, form div {
        text-align: left !important;
        align-items: flex-start !important;
    }
    
    .controls-container label, 
    .input-group label, 
    form label {
        text-align: left !important;
        margin-left: 0 !important;
        display: block !important;
        width: 100% !important;
    }

    /* Asegurar que los select e input no tengan alineaciÃ³n interna centrada */
    select, input, textarea {
        text-align: left !important;
    }
    
    /* El contenedor de Solo Morosos */
    .checkbox-group-mobile, 
    .checkbox-group-mobile label {
        justify-content: flex-start !important;
        align-items: center !important;
        flex-direction: row !important; /* Mantener horizontal el checkbox */
    }
}

/* --- Super Fix para ocultar botones específicos en móvil --- */
@media (max-width: 768px) {
    .mobile-action-hide {
        display: none !important;
        visibility: hidden !important;
        width: 0 !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        pointer-events: none !important;
    }
}

/* --- Fix estricto para el checkbox de Solo Morosos --- */
@media (max-width: 768px) {
    .checkbox-group-mobile {
        display: flex !important;
        flex-direction: row !important; /* Forzar horizontal */
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 10px !important;
        height: auto !important;
        padding: 12px 15px !important;
    }
    
    .checkbox-group-mobile label {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        width: auto !important;
        gap: 10px !important;
        margin: 0 !important;
    }
    
    .checkbox-group-mobile input[type='checkbox'] {
        width: 20px !important;
        height: 20px !important;
        margin: 0 !important;
    }
}

/* --- Estilos del Login Moderno --- */
.login-body {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    padding: 20px;
}

.login-wrapper {
    width: 100%;
    max-width: 450px;
    animation: fadeIn 0.8s ease-out;
}

.login-card {
    background: white;
    padding: 40px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}

.login-header {
    text-align: center;
    margin-bottom: 35px;
}

.logo-container {
    width: 70px;
    height: 70px;
    background: var(--bg-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    font-size: 32px;
    margin: 0 auto 15px;
}

.login-header h1 {
    font-size: 28px;
    font-weight: 800;
    color: var(--secondary);
    margin-bottom: 5px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.login-form .input-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #475569;
    margin-bottom: 8px;
}

.input-with-icon {
    position: relative;
}

.input-with-icon input {
    width: 100%;
    padding: 14px 45px 14px 15px;
    border: 2px solid #f1f5f9;
    border-radius: 12px;
    font-size: 15px;
    transition: 0.3s;
    outline: none;
    background: #f8fafc;
}

.input-with-icon input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(42, 82, 152, 0.05);
}

.input-with-icon i {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 18px;
}

.btn-login {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: 0.3s;
    margin-top: 10px;
}

.btn-login:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(42, 82, 152, 0.2);
}

.login-footer {
    margin-top: 35px;
    text-align: center;
    border-top: 1px solid #f1f5f9;
    padding-top: 25px;
    color: var(--text-muted);
    font-size: 12px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 480px) {
    .login-card { padding: 30px 20px; }
}

/* --- Remember Me Styles --- */
.remember-me-group {
    margin-bottom: 20px;
}

.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 35px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #475569;
    user-select: none;
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkbox-container:hover input ~ .checkmark {
    background-color: #e2e8f0;
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--primary);
}

.checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 22px;
    width: 22px;
    background-color: #f1f5f9;
    border-radius: 6px;
    transition: 0.3s;
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 8px;
    top: 4px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Estilos para chat de clientes (directo con soporte) */
.client-chat .chat-sidebar {
    display: none !important;
}
.client-chat .chat-messages-area {
    width: 100% !important;
}

/* ==========================================================================
   CORRECCIÓN GLOBAL DE AVATARES, ICONOS E INICIALES DESCENTRADOS/DEFORMADOS
   ========================================================================== */
.stat-icon, .user-avatar, .chat-header-avatar, .chat-modal-contact-avatar, .chat-conv-avatar,
.stat-card .stat-icon, .topbar-user .user-avatar {
    flex-shrink: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    box-sizing: border-box !important;
    line-height: normal !important;
}

.stat-icon i, .user-avatar i, .chat-header-avatar i, .chat-modal-contact-avatar i, .chat-conv-avatar i,
.stat-icon span, .user-avatar span, .chat-header-avatar span, .chat-modal-contact-avatar span, .chat-conv-avatar span {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: normal !important;
    text-align: center !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Centrado y flex-wrap de la paginación para evitar deformaciones en móviles */
.pagination-container {
    flex-wrap: wrap !important;
}
.pagination-container a {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    line-height: normal !important;
    flex-shrink: 0 !important;
}

/* Delete conversation button (Admin-only) */
.chat-conversation-item {
    position: relative !important;
}

.chat-delete-conv-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, background-color 0.2s, color 0.2s;
    z-index: 10;
    width: 28px;
    height: 28px;
}

.chat-conversation-item:hover .chat-delete-conv-btn {
    opacity: 1;
    pointer-events: auto;
}

/* Hide unread badge or timestamp slightly when delete button is hovered to prevent overlay overlap */
.chat-conversation-item:hover .chat-delete-conv-btn:hover {
    background-color: rgba(239, 68, 68, 0.15);
    color: #b91c1c;
}

.chat-conversation-item:hover .chat-unread-badge,
.chat-conversation-item:hover .chat-conv-time {
    transition: opacity 0.2s;
}

.chat-conversation-item:hover:has(.chat-delete-conv-btn:hover) .chat-unread-badge,
.chat-conversation-item:hover:has(.chat-delete-conv-btn:hover) .chat-conv-time {
    opacity: 0.1;
}

