/* =========================================
   1. VARIABLES Y TEMAS (EL CEREBRO DEL DISEÑO)
   ========================================= */
:root {
    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --bg-header: #ffffff;
    --bg-hover: #e4e6eb;
    --text-main: #1c1e21;
    --text-muted: #65676b;
    --text-inverse: #ffffff;
    --accent: #0d6efd;
    --accent-hover: #0a58ca;
    --accent-glow: rgba(13, 110, 253, 0.25);
    --border-color: #ced0d4;
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.1);
    --danger: #dc3545;
    --danger-hover: #bb2d3b;
    --success: #198754;
    --scroll-track: #f0f2f5;
    --scroll-thumb: #bcc0c4;
    --logo-filter: none;
    --calendar-bg: #ffffff;
    --calendar-text: #1c1e21;
    --header-height: 70px;
    --radius: 8px;
}

body.dark-mode {
    --bg-body: #050505;
    --bg-card: #1a1a1a;
    --bg-input: #000000;
    --bg-header: #1a1a1a;
    --bg-hover: #2a2a2a;
    --text-main: #e0e0e0;
    --text-muted: #b0b0b0;
    --text-inverse: #000000;
    --accent: #ff6600;
    --accent-hover: #e65c00;
    --accent-glow: rgba(255, 102, 0, 0.3);
    --border-color: #333333;
    --shadow-card: 0 4px 15px rgba(255, 165, 0, 0.1);
    --danger: #ff4d4d;
    --danger-hover: #cc0000;
    --success: #28a745;
    --scroll-track: #0f0f0f;
    --scroll-thumb: #333;
    --logo-filter: invert(1) brightness(100);
    --calendar-bg: #1a1a1a;
    --calendar-text: #e0e0e0;
}

/* =========================================
   2. RESET Y ESTRUCTURA (AJUSTE DE ALTURAS)
   ========================================= */
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    padding-top: 90px;
    margin: 0; padding: 0;
    min-height: 100vh;
    display: flex; flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* =========================================
   3. HEADER — DOS FILAS (Top Bar + Nav Bar)
   ========================================= */
.header-bar {
    background-color: var(--bg-header);
    position: fixed; top: 0; left: 0; width: 100%;
    z-index: 2000;
    box-shadow: var(--shadow-card);
    transition: background-color 0.3s ease;
    display: flex;
    flex-direction: column;
}

/* ---- FILA 1: TOP BAR ---- */
.header-top {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 56px;
    padding: 0 24px;
    border-bottom: 1px solid rgba(128,128,128,0.15);
}
.header-left  { display: flex; align-items: center; }
.header-right { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }

/* ---- FILA 2: NAV BAR ---- */
.header-nav-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    border-bottom: 2px solid var(--accent);
    padding: 0 20px;
    overflow: visible;
}

/* Logo */
.logo-container {
    display: flex; align-items: center; justify-content: center;
    height: 46px;
    position: static; transform: none;
}
.logo-img {
    height: 100%; width: auto; object-fit: contain;
    filter: var(--logo-filter);
    transition: filter 0.3s ease;
}

.user-info { font-size: 0.9rem; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.user-info strong { color: var(--accent); }

.header-tools { display: flex; gap: 8px; align-items: center; position: relative; justify-content: flex-end; }

/* ---- NAV LINKS: estilo flat — SOLO DESKTOP ---- */
@media (min-width: 993px) {
    .header-nav-bar .nav-links {
        display: flex !important;
        flex-direction: row !important;
        position: static !important;
        transform: none !important;
        background: transparent !important;
        width: auto !important; height: auto !important;
        padding: 0 !important;
        gap: 2px !important;
        align-items: center !important;
        pointer-events: all !important;
        box-shadow: none !important;
        overflow: visible !important;
        border: none !important;
    }
    .header-nav-bar .nav-links a,
    .header-nav-bar .nav-links button {
        background: none !important;
        border: none !important;
        color: var(--text-main) !important;
        font-size: 0.74rem !important;
        font-weight: 700 !important;
        letter-spacing: 0.07em !important;
        text-transform: uppercase !important;
        padding: 4px 10px !important;
        height: 30px !important;
        border-radius: 6px !important;
        box-shadow: none !important;
        display: inline-flex !important;
        align-items: center !important;
        gap: 4px !important;
        transition: color 0.18s, background 0.18s !important;
        white-space: nowrap !important;
        width: auto !important;
    }
    .header-nav-bar .nav-links a:hover,
    .header-nav-bar .nav-links button:hover {
        color: var(--accent) !important;
        background: rgba(0,86,179,0.09) !important;
    }
    .header-nav-bar .nav-links .btn-orange { color: #e67e22 !important; }
    .header-nav-bar .nav-links .btn-orange:hover { color: #d35400 !important; background: rgba(230,126,34,0.1) !important; }
    .header-nav-bar .nav-links .btn-red    { color: #dc3545 !important; }
    .header-nav-bar .nav-links .btn-red:hover    { color: #a71d2a !important; background: rgba(220,53,69,0.1) !important; }
    .header-nav-bar .nav-links .btn-navy   { color: var(--accent) !important; }
    .nav-mobile-extras { display: none !important; }
    .nav-separator { display: inline-block !important; }
    .hdr-salir-desktop { display: inline-flex !important; }
}

/* Separador visual entre grupos de nav items */
.nav-separator { width: 1px; height: 18px; background: var(--border-color); margin: 0 4px; opacity: 0.6; display: none; }

/* Extras que solo aparecen en el drawer mobile */
.nav-mobile-extras { display: none; }

.role-tag { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; margin-left: 8px; font-weight: bold; border: 1px solid currentColor; text-transform: uppercase; }
.tag-god { color: #d63384; border-color: #d63384; }
.tag-admin { color: var(--accent); border-color: var(--accent); }

body.dark-mode .tag-god { text-shadow: 0 0 5px #d63384; }
body.dark-mode .tag-admin { text-shadow: 0 0 5px var(--accent); }

.badge-bell {
    position: absolute; top: -5px; right: -5px;
    background-color: var(--danger); color: white;
    border-radius: 50%; padding: 2px 5px; font-size: 0.65rem; font-weight: bold;
    border: 1px solid var(--bg-card); min-width: 14px; text-align: center;
    display: none; z-index: 10;
}

/* =========================================
   4. BOTONES
   ========================================= */
.btn {
    text-decoration: none; padding: 0 20px; height: 38px; border-radius: 50px;
    font-size: 0.85rem; font-weight: 700; border: none; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.2s ease; text-transform: uppercase; letter-spacing: 0.5px;
}

.btn-navy, .btn-orange, .btn-save { background-color: var(--accent); color: var(--text-inverse) !important; }
.btn-navy:hover, .btn-orange:hover, .btn-save:hover { background-color: var(--accent-hover); transform: translateY(-2px); box-shadow: 0 0 10px var(--accent-glow); }

.btn-red { background-color: var(--danger); color: white !important; }
.btn-red:hover { background-color: var(--danger-hover); box-shadow: 0 0 10px var(--danger); }

.btn-gray, .btn-edit { background-color: var(--bg-hover); color: var(--text-main) !important; border: 1px solid var(--border-color); }
.btn-gray:hover, .btn-edit:hover { background-color: var(--border-color); color: var(--text-main); }

.btn-green { background-color: var(--success); color: white !important; }

.counter-badge { background: var(--bg-body); color: var(--text-main); padding: 1px 6px; border-radius: 10px; margin-left: 6px; font-size: 0.7rem; font-weight: bold; border: 1px solid var(--border-color); }
.has-pending { background: var(--danger) !important; color: white !important; border: none; }

.btn-big-save {
    display: block; width: 60%; margin: 30px auto 0 auto;
    padding: 18px; font-size: 1.1rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: 1px;
    border-radius: 50px; background: var(--accent);
    color: var(--text-inverse) !important; border: none;
    cursor: pointer; transition: 0.3s;
}
.btn-big-save:hover { transform: scale(1.02); background: var(--accent-hover); box-shadow: 0 5px 15px var(--accent-glow); }

/* =========================================
   5. TARJETAS Y CUADRÍCULA DE GESTIÓN
   ========================================= */
.main-container { flex: 1; padding: 40px 20px; display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 1600px; margin: 0 auto; }

.dashboard-grid { display: grid; grid-template-columns: 1fr 450px; gap: 25px; padding: 25px; max-width: 1700px; margin: 0 auto; align-items: stretch; }

.panel-card { background-color: var(--bg-card); padding: 25px; border-radius: var(--radius); border: 1px solid var(--border-color); box-shadow: var(--shadow-card); display: flex; flex-direction: column; transition: all 0.3s ease; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; }

.card-form, .card, .card-edit { background-color: var(--bg-card); width: 100%; max-width: 1100px; padding: 30px; border-radius: var(--radius); border: 1px solid var(--border-color); box-shadow: var(--shadow-card); }
body.dark-mode .card-form, body.dark-mode .panel-card { border-color: var(--accent); }

h1, h2, h3, .form-title, .page-title, .card-title, .panel-title { color: var(--accent); text-align: center; margin-top: 0; margin-bottom: 25px; text-transform: uppercase; letter-spacing: 1px; }

/* =========================================
   6. INPUTS Y FILAS DE USUARIO
   ========================================= */
.user-row { background-color: var(--bg-body); border: 1px solid var(--border-color); padding: 20px; margin-bottom: 20px; border-radius: 8px; }
.user-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 15px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; }
.user-meta { display: flex; flex-direction: column; gap: 7px; }
.user-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; padding-top: 2px; }
.user-name { font-size: 1rem; font-weight: 700; color: var(--text-main); }
.user-rol-select { width: 180px !important; max-width: 180px !important; height: 32px !important; font-size: 0.82rem !important; padding: 0 8px !important; }
.config-grid { display: grid; grid-template-columns: 200px 1fr; gap: 20px; margin-top: 15px; align-items: end; }

.brand-checks { display: flex; flex-wrap: wrap; gap: 15px; padding: 10px; background: rgba(0,0,0,0.03); border: 1px solid var(--border-color); border-radius: 4px; }
.brand-label { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; cursor: pointer; white-space: nowrap; width: auto !important; }
input[type="checkbox"] { width: 18px !important; height: 18px !important; margin: 0; cursor: pointer; }

.row { display: flex; gap: 20px; margin-bottom: 15px; }
.col { flex: 1; }
@media (max-width: 900px) { .dashboard-grid, .config-grid { grid-template-columns: 1fr; } .row { flex-direction: column; } }

label { display: block; margin-bottom: 5px; color: var(--text-muted); font-size: 0.85rem; }
input, select, textarea, .form-input, .cyber-input, .swal2-input { width: 100%; padding: 10px; background-color: var(--bg-input) !important; border: 1px solid var(--border-color) !important; color: var(--text-main) !important; border-radius: 4px; box-sizing: border-box; font-size: 0.95rem; transition: border-color 0.3s, box-shadow 0.3s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent) !important; box-shadow: 0 0 5px var(--accent-glow); }

.row-highlight { background: var(--bg-hover); padding: 20px; border-radius: 10px; border: 1px dashed var(--border-color); }
.fiscal-block { border-color: var(--accent); background-color: var(--accent-light); }
.input-total { font-weight: 800; font-size: 1.1rem; color: var(--success) !important; border: 2px solid var(--success) !important; }

/* =========================================
   7. TABLAS E HISTORIAL (MODO COMPACTO / REPORTE)
   ========================================= */
.table-responsive { 
    overflow-x: auto; 
    border-radius: var(--radius); 
    border: 1px solid var(--border-color); 
    width: 100%; 
    max-width: 1600px;
    box-shadow: var(--shadow-card);
    max-height: 70vh; 
    position: relative;
}

.styled-table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0;
    font-size: 0.85rem; 
    background: var(--bg-card);
    table-layout: auto; 
    min-width: 1900px;
}

.styled-table th { 
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #002147; 
    color: white; 
    padding: 14px 10px; 
    text-align: left; 
    font-weight: 800; 
    text-transform: uppercase;
    font-size: 0.75rem;
    white-space: nowrap;
    border-right: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 2px 2px rgba(0,0,0,0.1);
}

.styled-table td { 
    padding: 12px 10px; 
    border-bottom: 1px solid var(--border-color); 
    color: var(--text-main); 
    vertical-align: middle;
    line-height: 1.2;
    max-width: 250px; 
    overflow: hidden;
    text-overflow: ellipsis;
    background: transparent !important; 
}

.styled-table tbody tr:nth-child(even) { background-color: rgba(0,0,0,0.01); }
.styled-table tr:hover { background-color: var(--bg-hover); }

.alert-row { border-left: 6px solid var(--danger) !important; background-color: rgba(220, 53, 69, 0.03) !important; }
.pending-load-row { border-left: 6px solid var(--success) !important; background-color: rgba(25, 135, 84, 0.03) !important; }

.price-col { font-family: 'Courier New', Courier, monospace; font-weight: bold; text-align: right !important; padding-right: 15px !important; white-space: nowrap; }
.main-monto { color: var(--success); font-size: 0.95rem; }

.badge-marca { background: var(--bg-hover); padding: 2px 6px; border-radius: 4px; font-weight: bold; border: 1px solid var(--border-color); font-size: 0.65rem; display: inline-block; }
.alert-note { display: block; font-size: 0.7rem; background: var(--danger); color: white; padding: 4px 8px; border-radius: 4px; margin-top: 5px; font-weight: bold; width: fit-content; }

/* =========================================
   8. EXTRAS (Scrollbar, Loader, Notis)
   ========================================= */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--scroll-track); }
::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border-radius: 5px; border: 2px solid var(--scroll-track); }

.loader-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); display: none; justify-content: center; align-items: center; flex-direction: column; z-index: 9999; }
.spinner { border: 5px solid #333; border-top: 5px solid var(--accent); border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.loader-text { color: var(--accent); margin-top: 15px; font-weight: bold; }

.dropdown-content { display: none; position: absolute; right: 0; top: 45px; background: var(--bg-card); min-width: 280px; border: 1px solid var(--border-color); border-radius: 6px; z-index: 2000; box-shadow: var(--shadow-card); }
.dropdown-content.show { display: block; }
.noti-item { display: block; padding: 12px; border-bottom: 1px solid var(--border-color); color: var(--text-main); text-decoration: none; font-size: 0.85rem; }
.noti-item:hover { background-color: var(--bg-hover); }

/* =========================================
   9. CALENDARIO FLATPICKR Y ÁREAS
   ========================================= */
.flatpickr-calendar { background: var(--bg-card) !important; border: 1px solid var(--accent) !important; color: var(--text-main) !important; }
.flatpickr-day { color: var(--text-main) !important; }
.flatpickr-day.selected { background: var(--accent) !important; border-color: var(--accent) !important; color: var(--text-inverse) !important; }

.grouping-grid { display: grid; grid-template-columns: 1fr; gap: 6px; flex-grow: 1; max-height: 450px; overflow-y: auto; padding: 12px; border: 1px solid var(--border-color); background: var(--bg-input); border-radius: 6px; margin: 12px 0; }
.area-item { padding: 12px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }

/* =========================================
   10. EDICIÓN EN RENGLÓN (PROTEGIDO)
   ========================================= */
.edit-form-row { display: none; }
.edit-form-row td { padding: 0 !important; background-color: var(--bg-hover) !important; }
.edit-form-compact { display: flex; gap: 10px; padding: 10px 15px; align-items: flex-end; border-bottom: 2px solid var(--accent); width: 100%; box-sizing: border-box; }
.edit-input-group { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.edit-input-group label { font-size: 0.65rem; font-weight: 800; color: var(--accent); text-transform: uppercase; }
.edit-input-group input, .edit-input-group select { height: 32px !important; padding: 4px 8px !important; font-size: 0.8rem !important; border: 1px solid var(--border-color) !important; border-radius: 4px !important; }
.readonly-notes { font-size: 0.8rem; color: var(--text-muted); font-style: italic; background: transparent !important; border: none !important; pointer-events: none; user-select: none; }
.btn-save-inline { height: 32px; padding: 0 15px; background: var(--accent); color: white; border: none; border-radius: 4px; font-weight: bold; cursor: pointer; text-transform: uppercase; font-size: 0.7rem; }

/* =========================================
   11. AJUSTES ESPECÍFICOS PARA LOGIN
   ========================================= */
body.body-centered { display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; padding: 20px; box-sizing: border-box; }
.login-container { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; max-width: 400px; }
.login-container .card-form { width: 100%; padding: 40px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); }
.login-container p { text-align: center; width: 100%; }
@media (max-height: 500px) { body.body-centered { align-items: flex-start; } }

/* =========================================
   12. ANIMACIÓN COMETA Y HEADER TOOLS
   ========================================= */
.header-tools { position: relative; display: flex; gap: 10px; align-items: center; }
#notiDropdown.dropdown-content { display: none; position: absolute; top: 55px; right: 320px; width: 320px; background: var(--bg-card); border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 9999; }
#notiDropdown.dropdown-content::before { content: ""; position: absolute; top: -10px; right: 15px; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 10px solid var(--accent); }
.noti-item { display: flex; flex-direction: column; padding: 12px 15px; border-bottom: 1px solid var(--border-color); text-decoration: none; transition: background 0.2s; }
.noti-item:hover { background-color: var(--bg-hover); }

.header-loader { display: none; position: absolute; bottom: 0; left: 0; width: 100%; height: 5px; background: rgba(0, 0, 0, 0.1); z-index: 9999; overflow: visible; }
.header-loader.active { display: block; }
.meteor-bar { position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: linear-gradient(90deg, transparent 0%, #ff6600 40%, #ffcc00 80%, #ffffff 100%); box-shadow: 0 0 20px 5px rgba(255, 102, 0, 0.5); animation: meteor-pass 1s infinite linear; }
.meteor-bar::after { content: ''; position: absolute; top: -25px; right: -10px; width: 35px; height: 35px; background-image: url('/static/logo.png'); background-size: contain; background-repeat: no-repeat; filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.8)); transform: rotate(10deg); }
@keyframes meteor-pass { 0% { left: -100%; } 100% { left: 100%; } }

/* =========================================
   13. MENÚ — DESKTOP (nav inline)
   ========================================= */
/* Texto que solo se muestra en mobile (dentro del drawer) */
.nav-text-mobile { display: none; }

.burger-btn { display: none; font-size: 1.5rem; background: none; border: none; color: var(--text-main); cursor: pointer; padding: 0 10px; line-height: 1; }
.nav-links { display: flex; gap: 10px; align-items: center; }

/* Overlay del drawer — SIN blur */
.nav-drawer-overlay {
    display: none;
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.45);
    z-index: 10000;
}
.nav-drawer-overlay.active { display: block; }

@media (max-width: 992px) {
    .burger-btn { display: block; }
    /* SIDE DRAWER desde la derecha */
    .nav-links {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        top: 0; right: 0;
        height: 100vh;
        width: 75vw;
        max-width: 280px;
        background-color: var(--bg-card);
        border-left: 3px solid var(--accent);
        box-shadow: -6px 0 30px rgba(0,0,0,0.35);
        transform: translateX(110%);
        transition: transform 0.3s ease;
        z-index: 10002;
        padding: 80px 12px 25px 12px;
        gap: 6px;
        overflow-y: auto;
        align-items: stretch;
        pointer-events: none;
    }
    .nav-links.active {
        transform: translateX(0);
        pointer-events: all;
    }
    .nav-links a, .nav-links button {
        width: 100%;
        justify-content: flex-start;
        padding-left: 16px;
        height: 48px;
        font-size: 0.9rem;
        border-radius: 10px;
        margin: 0;
        box-sizing: border-box;
        touch-action: manipulation;
    }
}

/* =========================================
   14. FIX FINAL (NUCLEAR)
   ========================================= */
html, body { margin: 0 !important; padding: 0 !important; width: 100% !important; max-width: 100% !important; overflow-x: hidden !important; }
html { scrollbar-gutter: stable; }
.header-bar { position: fixed !important; top: 0 !important; left: 0 !important; width: 100% !important; height: auto !important; z-index: 10003 !important; margin: 0 !important; box-sizing: border-box !important; display: flex !important; flex-direction: column !important; }
.header-top { height: 56px !important; padding: 0 24px !important; }
.header-nav-bar { height: 42px !important; overflow: visible !important; }
body { padding-top: 100px !important; }
/* Salir desktop visible por defecto — el media query lo oculta en mobile */
.hdr-salir-desktop { display: inline-flex; }
.main-container h2, .page-title { margin-top: 0 !important; padding-top: 20px !important; }

/* =========================================
   15. ESTÉTICA PARA SWEETALERT
   ========================================= */
.swal2-popup { border-radius: 12px !important; box-shadow: 0 8px 25px rgba(0,0,0,0.15) !important; font-family: inherit !important; }
.swal2-input:not([style*="display: none"]), .swal2-select:not([style*="display: none"]) { height: auto !important; padding: 12px 15px !important; font-size: 0.95rem !important; border-radius: 6px !important; border: 1px solid var(--border-color, #ccc) !important; width: 85% !important; margin: 10px auto !important; box-sizing: border-box !important; }
.swal2-html-container { overflow: hidden !important; margin-top: 15px !important; }

body.dark-mode .swal2-popup { background-color: #1a1a1a !important; color: #ffffff !important; }
body.dark-mode .swal2-title, body.dark-mode .swal2-html-container { color: #eeeeee !important; }
body.dark-mode .swal2-input:not([style*="display: none"]), body.dark-mode .swal2-select:not([style*="display: none"]) { background-color: #2a2a2a !important; color: #ffffff !important; border-color: #444 !important; }
body.dark-mode .swal2-input::placeholder { color: #888 !important; }
body.dark-mode .swal2-input:focus, body.dark-mode .swal2-select:focus { border-color: #0056b3 !important; box-shadow: 0 0 5px rgba(0, 86, 179, 0.5) !important; outline: none !important; }

/* ==========================================
   16. AJUSTES FINALES HISTORIAL (Buscador y Filtros)
   ========================================== */
.filter-bar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: flex-end !important;
    gap: 6px !important;
    padding: 10px 14px !important;
    overflow: visible !important;
    width: 100% !important;
    box-sizing: border-box !important;
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(0,86,179,0.04) 100%) !important;
    border: 1px solid var(--border-color) !important;
    border-left: 3px solid var(--accent) !important;
    border-radius: 10px !important;
    margin-bottom: 10px !important;
}
@media (min-width: 1101px) {
    .filter-bar { flex-wrap: nowrap !important; }
}

.filter-bar label {
    font-size: 0.68rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    font-weight: 700 !important;
    color: var(--text-muted) !important;
    margin-bottom: 3px !important;
}

.filter-bar .cyber-input,
.filter-bar .excel-filter button.cyber-input,
.filter-bar select.cyber-input,
.filter-bar input.cyber-input,
.filter-bar .btn {
    height: 30px !important;
    font-size: 0.76rem !important;
    padding: 0 8px !important;
    box-sizing: border-box !important;
    border-radius: 6px !important;
}

/* 1. ACHICAR EL BUSCADOR (FUERZA BRUTA) */
.filter-bar .filter-group:first-child {
    flex-grow: 0 !important;
    width: 130px !important;
    min-width: 130px !important;
    max-width: 130px !important;
}
#globalSearch { 
    width: 100% !important; 
}

/* 2. ACHICAR LAS FECHAS (Ataque directo al nombre del input) */
.filter-bar input[name="f_inicio"],
.filter-bar input[name="f_fin"],
.filter-bar input.flatpickr-input,
.filter-bar input.cyber-date {
    width: 92px !important;
    min-width: 92px !important;
    max-width: 92px !important;
    padding: 0 5px !important;
    font-size: 0.76rem !important;
}

/* 3. ACHICAR LOS DESPLEGABLES — solo en desktop */
@media (min-width: 769px) {
    select[name="aplica_a_filtro"] { width: 72px !important; min-width: 72px !important; }
    select[name="usuario_filtro"], select[name="area_filtro"] { width: 82px !important; min-width: 82px !important; }
    select[name="tipo_fecha"], .excel-filter button.cyber-input { width: 96px !important; min-width: 96px !important; }
    select[name="metodo_filtro"] { width: 108px !important; min-width: 108px !important; }
    input[name="proveedor_filtro"] { width: 120px !important; min-width: 120px !important; }
}

/* Menús flotantes */
.excel-filter { position: relative; }
.excel-filter-content { display: none; position: absolute; top: 34px; left: 0; background-color: var(--bg-card) !important; border: 1px solid var(--border-color) !important; box-shadow: 0 8px 16px rgba(0,0,0,0.2) !important; z-index: 99999 !important; min-width: 180px; max-height: 350px; overflow-y: auto; border-radius: 4px; }
.excel-filter-content.show { display: block !important; }
.excel-filter-content label { display: flex !important; align-items: center !important; gap: 8px !important; padding: 6px 10px !important; color: var(--text-main) !important; font-size: 0.85rem !important; cursor: pointer; }
.excel-filter-content label:hover { background-color: var(--bg-hover) !important; }
/* ==========================================
   17. ESTILOS PARA LAS NOTAS FLOTANTES
   ========================================== */
.nota-preview { background-color: #f1f3f5; color: #495057; padding: 5px 10px; border-radius: 6px; font-size: 0.85rem; cursor: pointer; display: inline-block; max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid #ced4da; transition: all 0.2s ease; }
.nota-flotante { display: none; position: absolute; z-index: 1000; background: var(--card-bg, #ffffff); border: 2px solid var(--navy-btn, #0056b3); border-radius: 6px; padding: 15px; width: 300px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); white-space: normal; word-wrap: break-word; color: var(--text-main, #333); font-style: normal; }
.nota-flotante.show { display: block; }
.nota-flotante-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #ddd; padding-bottom: 5px; margin-bottom: 10px; font-weight: bold; }
.btn-cerrar-nota { background: none; border: none; color: #dc3545; cursor: pointer; font-size: 1.2rem; line-height: 1; }

.dark-mode .nota-preview { background-color: #2b3035; color: #dee2e6; border-color: #495057; }
.dark-mode .nota-flotante { background: #222; border-color: #4da3ff; color: #fff; }
.dark-mode .nota-flotante-header { border-bottom-color: #444; }
.nota-preview:hover { background-color: #e2e6ea; border-color: #adb5bd; }
.dark-mode .nota-preview:hover { background-color: #343a40; }

.high-z-index-toast { z-index: 999999 !important; }

/* ==========================================
   18. MOBILE OVERRIDES (max-width: 768px)
   ========================================== */
@media (max-width: 768px) {

    /* Texto del drawer visible en mobile */
    .nav-text-mobile { display: inline !important; }

    /* ---- RESET: nada puede sobresalir del viewport ---- */
    *, *::before, *::after { box-sizing: border-box !important; }
    html { overflow-x: hidden !important; width: 100% !important; }
    body {
        overflow-x: hidden !important;
        width: 100vw !important;
        max-width: 100% !important;
        padding-top: 60px !important;
    }

    /* ---- HEADER ---- */
    body { padding-top: 60px !important; }
    .header-bar { height: auto !important; }
    .header-top {
        padding: 0 10px !important;
        height: 58px !important;
        width: 100vw !important;
        max-width: 100% !important;
    }
    /* La nav bar colapsa a 0 en mobile — el drawer es fixed y sale aparte */
    .header-nav-bar {
        height: 0 !important;
        min-height: 0 !important;
        padding: 0 !important;
        border: none !important;
        overflow: visible !important;
    }
    .logo-container { height: 38px !important; }
    .logo-img { height: 32px !important; }
    .user-info { font-size: 0.74rem !important; }
    .user-info strong {
        max-width: 80px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        display: inline-block !important;
        vertical-align: middle !important;
    }
    .user-info .role-tag { display: none !important; }
    .header-right { gap: 4px !important; }
    .burger-btn { font-size: 1.6rem !important; padding: 0 5px !important; }
    /* Salir desktop se oculta — está dentro del drawer */
    .hdr-salir-desktop { display: none !important; }
    .nav-separator { display: none !important; }
    /* Salir dentro del drawer */
    .nav-mobile-extras {
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        padding-top: 12px !important;
        border-top: 1px solid var(--border-color) !important;
        margin-top: 8px !important;
        width: 100% !important;
    }
    .nav-mobile-extras .btn-red {
        width: 100% !important;
        justify-content: flex-start !important;
        padding-left: 16px !important;
    }

    /* Notificaciones: override del inline style con position fixed */
    #notiDropdown,
    #notiDropdown.dropdown-content {
        position: fixed !important;
        top: 60px !important;
        left: 4vw !important;
        right: 4vw !important;
        width: 92vw !important;
        max-width: 92vw !important;
        min-width: 0 !important;
    }

    /* ---- MAIN CONTAINER ---- */
    .main-container {
        padding: 10px 8px 20px 8px !important;
        width: 100% !important;
        max-width: 100% !important;
        align-items: stretch !important;
    }
    .page-title { font-size: 1rem !important; padding-top: 8px !important; margin-bottom: 10px !important; }

    /* ---- CARDS / FORMS ---- */
    .card-form, .card, .card-edit, .panel-card {
        width: 100% !important;
        max-width: 100% !important;
        padding: 14px !important;
        border-radius: 8px !important;
    }
    .dashboard-grid { grid-template-columns: 1fr !important; padding: 0 !important; gap: 12px !important; }
    .row { flex-direction: column !important; gap: 10px !important; }
    .col { width: 100% !important; min-width: 0 !important; }
    .config-grid { grid-template-columns: 1fr !important; }

    /* Inputs y selects ancho completo, font-size 16px evita zoom iOS */
    input, select, textarea {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        font-size: 16px !important;
    }

    /* ---- FILTER BAR — colapsable ---- */
    .filter-bar {
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        overflow: hidden !important;
        max-height: 0 !important;
        padding: 0 8px !important;
        margin-bottom: 0 !important;
        border: none !important;
        box-shadow: none !important;
        gap: 10px !important;
        width: 100% !important;
        transition: max-height 0.35s ease, padding 0.25s ease !important;
    }
    .filter-bar.mobile-open {
        max-height: 2000px !important;
        padding: 12px 8px !important;
        border: 1px solid var(--border-color) !important;
        box-shadow: var(--shadow-card) !important;
        margin-bottom: 10px !important;
        overflow: visible !important;
    }
    .filter-bar .filter-group,
    .filter-bar .filter-group:first-child {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        flex: none !important;
    }
    #globalSearch { width: 100% !important; }

    /* Todos los controles del filtro a ancho completo */
    .filter-bar .cyber-input,
    .filter-bar select,
    .filter-bar input,
    .filter-bar button.cyber-input,
    select[name="aplica_a_filtro"],
    select[name="usuario_filtro"],
    select[name="area_filtro"],
    select[name="tipo_fecha"],
    select[name="metodo_filtro"],
    input[name="proveedor_filtro"],
    input[name="f_inicio"],
    input[name="f_fin"] {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: 44px !important;
        font-size: 16px !important;
        padding: 0 12px !important;
    }
    .excel-filter { width: 100% !important; }
    .excel-filter button { width: 100% !important; }
    .excel-filter-content { width: 100% !important; min-width: 0 !important; left: 0 !important; right: 0 !important; }
    .filter-bar .btn { width: 100% !important; height: 44px !important; margin-left: 0 !important; }

    /* ---- TABLE — scroll horizontal contenido ---- */
    .table-responsive {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        max-height: none !important;
        border-radius: 8px !important;
    }
    .styled-table {
        min-width: 780px !important;
        font-size: 0.73rem !important;
        table-layout: auto !important;
    }
    .styled-table th { padding: 9px 6px !important; font-size: 0.65rem !important; white-space: nowrap !important; }
    .styled-table td { padding: 7px 5px !important; white-space: nowrap !important; }
    .td-motivo { white-space: normal !important; min-width: 130px !important; }

    /* ID sticky para saber en qué fila estás mientras scrolleás */
    .styled-table th:first-child {
        position: sticky !important; left: 0 !important; z-index: 12 !important;
        background-color: #002147 !important;
    }
    .styled-table td:first-child {
        position: sticky !important; left: 0 !important; z-index: 5 !important;
        background: var(--bg-card) !important;
        box-shadow: 2px 0 5px rgba(0,0,0,0.15) !important;
    }
    body.dark-mode .styled-table td:first-child { background: var(--bg-card) !important; }

    /* Botones dentro de la tabla */
    .styled-table .btn { height: 32px !important; padding: 0 7px !important; font-size: 0.7rem !important; min-width: 32px !important; }

    /* ---- BOTONES GENERALES ---- */
    .btn { height: 44px !important; font-size: 0.85rem !important; }
    .btn-big-save { width: 100% !important; height: 50px !important; font-size: 1rem !important; }

    /* ---- GESTION USUARIOS ---- */
    .user-row { padding: 10px !important; }
    .user-header { flex-wrap: wrap !important; gap: 8px !important; }

    /* ---- LOGIN ---- */
    .login-container { padding: 0 !important; }
    .login-container .card-form { padding: 22px 14px !important; }

    /* ---- SWEETALERT ---- */
    .swal2-popup { width: 93vw !important; }
    .swal2-input:not([style*="display: none"]),
    .swal2-select:not([style*="display: none"]) { width: 90% !important; font-size: 16px !important; }
}

/* ---- TABLET (769px – 1100px) ---- */
@media (min-width: 769px) and (max-width: 1100px) {
    .filter-bar { flex-wrap: wrap !important; gap: 8px !important; }
    .filter-bar .filter-group { flex: 0 0 auto; min-width: 110px; }
    .filter-bar .filter-group:first-child { min-width: 140px !important; width: 140px !important; }
    .styled-table { min-width: 1300px !important; font-size: 0.8rem !important; }
    .main-container { padding: 20px 12px !important; }
}

/* Teléfonos muy chicos */
@media (max-width: 390px) {
    .user-info strong { max-width: 55px !important; }
    .header-bar { padding: 0 6px !important; }
    .styled-table { min-width: 680px !important; }
    .logo-img { height: 26px !important; }
}
