:root { 
            --primary: #0f172a; 
            --secondary: #1e293b; 
            --bg: #f4f7f6; 
            --surface: #ffffff;
            --text: #19191a; 
            --text-muted: #404d60;
            --border: #e2e8f0; 
            
            --content-surface: #ffffff;
            --content-bg: #f8fafc;
            --content-border: #cbd5e1;

            --emitidos: #10b981; 
            --recibidos: #f59e0b; 
            --info: #0ea5e9; 
            --danger: #ef4444;
            --pdf: #8b5cf6;

            --e-light: #ffebee; --e-dark: #ffcdd2; --e-text: #c0392b;
            --p-light: #e3f2fd; --p-dark: #bbdefb; --p-text: #2980b9;
            --n-light: #f5eef8; --n-dark: #d7bde2; --n-text: #8e44ad;
        }

        html.dark-mode {
            --primary: #f8fafc; --secondary: #cbd5e1; --bg: #0f172a; 
            --surface: #1e293b; --text: #edf0f3; --text-muted: #94a3b8; --border: #334155;
        }

        .mosaic-card { color: #1e293b !important; }
        .m-provider { color: #0f172a !important; }
        .m-folio { color: #2c3e50 !important; }
        .m-footer-mosaic .m-uuid { color: #64748b !important; }
        table.excel-table td { color: #2c3e50 !important; }

        body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 0; overflow: hidden; transition: 0.3s; }
        
        .app-layout { display: flex; height: 100vh; overflow: hidden; }
        
        .sidebar-explorer { width: 300px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; padding: 20px 15px; box-shadow: 2px 0 15px rgba(0,0,0,0.03); flex-shrink: 0; z-index: 50; transition: margin-left 0.3s ease; margin-left: 0; }
        .sidebar-explorer.hidden { margin-left: -320px; }
        .sidebar-title { font-size: 13px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; border-bottom: 2px solid var(--user-accent); padding-bottom: 8px; margin-bottom: 15px; }
        
        .tree-type { font-size: 12px; font-weight: 900; margin: 15px 0 5px 0; padding: 8px 12px; border-radius: 8px; color: white; display: flex; align-items: center; gap: 8px; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
        .tree-type.emitidos { background: var(--emitidos); } .tree-type.recibidos { background: var(--recibidos); } .tree-type.otros { background: var(--text-muted); }
        
        .rfc-container { margin-left: 10px; border-left: 2px solid var(--border); padding-left: 10px; }
        .tree-rfc { font-size: 11px; font-weight: bold; color: var(--primary); margin: 8px 0; cursor: pointer; padding: 6px 10px; border-radius: 8px; display: flex; align-items: center; justify-content: space-between; transition: 0.2s; border: 1px solid transparent; background: var(--bg); }
        .tree-rfc:hover { border-color: var(--user-accent); box-shadow: 0 2px 5px var(--user-accent-glow); }
        .tree-rfc.active { background: var(--user-accent-glow); color: var(--user-accent); border-color: var(--user-accent); }
        .tree-rfc-left { display: flex; align-items: center; gap: 6px; }
        .tree-rfc-icon { font-size: 14px; background: var(--surface); border-radius: 6px; padding: 3px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
        
        .month-container { margin-left: 12px; border-left: 1px dashed var(--border); padding-left: 10px; display: none; }
        .tree-month { font-size: 11px; margin: 4px 0; padding: 6px 10px; color: var(--text-muted); cursor: pointer; display: flex; justify-content: space-between; align-items: center; border-radius: 6px; transition: 0.2s; }
        .tree-month:hover { background: var(--user-accent-glow); color: var(--user-accent); font-weight: bold; }
        .tree-month.active { background: var(--user-accent); color: white; font-weight: bold; box-shadow: 0 4px 10px var(--user-accent-glow); }
        
        .provider-list-container { margin-left: 12px; padding-left: 8px; border-left: 1px dotted var(--border); display: none; }
        .tree-provider { font-size: 10px; margin: 4px 0; padding: 6px 8px; color: var(--text-muted); cursor: pointer; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; transition: 0.2s; }
        .tree-provider:hover { background: var(--bg); color: var(--user-accent); }
        .tree-provider.active { background: var(--user-accent-glow); color: var(--user-accent); font-weight: bold; border-left: 3px solid var(--user-accent); }
        
        .tree-count { background: var(--border); padding: 2px 8px; border-radius: 12px; font-size: 9px; color: var(--text-muted); font-weight:bold; }
        .main-content { flex-grow: 1; padding: 15px 25px; overflow-y: auto; position: relative; background: var(--bg); padding-bottom: 20px; }

        /* HEADER PREMIUM */
        .dashboard-header { 
            background: var(--user-accent-glass); 
            backdrop-filter: blur(16px) saturate(180%);
            -webkit-backdrop-filter: blur(16px) saturate(180%); 
            border: 1px solid rgba(255, 255, 255, 0.3); 
            border-bottom: 1px solid var(--user-accent-glow);
            padding: 12px 20px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); 
            display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: nowrap; position: sticky; top: -15px; z-index: 100; 
        }
        
        /* 1. Los botones son Intocables (No se aplastan, solo se ocultan con el @media) */
        .header-group-left { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
        .header-group-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
        
        /* 2. El Buscador es elástico (Absorbe y cede espacio) */
        .search-group { 
            flex-grow: 1; 
            flex-shrink: 1; /* AHORA SÍ PUEDE ENCOGERSE */
            display: flex; 
            justify-content: center; 
            gap: 10px; 
            min-width: 40px; /* Límite mínimo para que no desaparezca */
            overflow: hidden; 
        }
        
        /* 3. La caja de texto cede su tamaño */
        .search-box { 
            padding: 0 15px; height: 36px; border: 2px solid var(--border); border-radius: 8px; 
            outline: none; font-size: 12px; font-family: inherit;
            flex-grow: 1; 
            flex-shrink: 1; /* Se encoge junto con su grupo */
            width: 100%;
            min-width: 60px !important; /* ELIMINAMOS EL 150px ESTRICTO QUE ROMPÍA TODO */
            max-width: 350px; 
            transition: 0.3s; 
            background: var(--bg); color: var(--text-muted); 
        }
        .search-box:focus { border-color: var(--user-accent); box-shadow: 0 0 0 4px var(--user-accent-glow); }

        /* Ajuste para que el selector ceda un poco */
        #sortSelect { flex-shrink: 1; min-width: 120px !important; }

        /* --- BOTONES PREMIUM: EFECTO CRISTAL --- */
        .btn-apple {
            height: 32px; padding: 0 12px;
            background: var(--user-accent-glass); 
            backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 6px;
            color: var(--text); font-weight: 600; font-size: 12px;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            display: flex; align-items: center; justify-content: center; gap: 0;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            cursor: pointer; white-space: nowrap; flex-shrink: 0; user-select: none; box-shadow: 0 4px 6px rgba(0,0,0,0.05);
        }
        
        .btn-apple:hover {
            background: rgba(255, 255, 255, 0.4); border-color: rgba(255, 255, 255, 0.4); box-shadow: 0 6px 12px rgba(0,0,0,0.1); gap: 8px;
        }
        .btn-apple:active { transform: scale(0.96); }

        .btn-text {
            display: inline-block; max-width: 0; opacity: 0; transform: translateX(-10px);
            transition: max-width 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease-out, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
            white-space: nowrap;
        }
        .btn-apple:hover .btn-text { max-width: 150px; opacity: 1; transform: translateX(0); }

        .btn-apple.primary { background: var(--user-accent); color: white; border: none; }
        .btn-apple.primary:hover { filter: brightness(1.1); box-shadow: 0 4px 8px var(--user-accent-glow); }
        .btn-apple.danger { color: var(--danger); }
        .btn-apple.excel { color: var(--emitidos); }
        .btn-apple.info { color: var(--info); }

        /* --- LÓGICA DE EXPANSIÓN CUANDO EL SIDEBAR SE ESCONDE --- */
        body.sidebar-collapsed .btn-apple .btn-text {
            max-width: 150px !important; /* Forzamos el ancho del texto */
            opacity: 1 !important;       /* Forzamos visibilidad */
            transform: translateX(0) !important; /* Eliminamos el desplazamiento */
        }

        /* Opcional: Ajuste de padding cuando están todos expandidos */
        body.sidebar-collapsed .btn-apple {
            padding: 0 15px !important;
            gap: 8px !important;
        }
        
        /* OCULTAMIENTO PROGRESIVO RESPONSIVE */
        /* =======================================================
           COLAPSO INTELIGENTE DE PANTALLA (RESPONSIVE)
           ======================================================= */
        
        /* 1. Sacrificar textos de botones de la derecha */
        @media (max-width: 1300px) {
            .prio-6 .btn-text, .prio-7 .btn-text, .prio-8 .btn-text { display: none !important; }
            .prio-6, .prio-7, .prio-8 { padding: 0 10px !important; gap: 0 !important; }
        }
        
        /* 2. Sacrificar textos centrales */
        @media (max-width: 1100px) {
            .prio-4 .btn-text, .prio-5 .btn-text { display: none !important; }
            .prio-4, .prio-5 { padding: 0 10px !important; gap: 0 !important; }
        }
        
        /* 3. Sacrificar los últimos textos (Todos son íconos ahora) */
        @media (max-width: 950px) {
            .prio-1 .btn-text, .prio-2 .btn-text, .prio-3 .btn-text { display: none !important; }
            .prio-1, .prio-2, .prio-3 { padding: 0 10px !important; gap: 0 !important; }
            .header-group-right .btn-text { display: none !important; }
            .header-group-right .btn-apple { padding: 0 10px !important; gap: 0 !important; }
        }
        
        /* 4. MODO EMERGENCIA: Sacrificar el Filtro de Fechas para salvar el buscador */
        @media (max-width: 700px) {
            #sortSelect { display: none !important; }
            .search-group { gap: 0; }
        }
        
        /* 5. MODO MÓVIL: El buscador se hace minúsculo */
        @media (max-width: 500px) {
            .search-box { padding: 0 8px; font-size: 10px; }
            .search-box::placeholder { color: transparent; } /* Ocultar el texto de ayuda para que quepa */
        }
        
        .btn-mini-rastreo { background: var(--user-accent-glow); color: var(--user-accent); border: 1px solid var(--user-accent); padding: 4px 8px; border-radius: 6px; font-size: 9.5px; font-weight: bold; cursor: pointer; font-family: monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; transition: 0.2s;}
        .btn-mini-rastreo:hover { background: var(--user-accent); color: white; }

        .status-container { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
        .status-badge { display: inline-block; padding: 6px 12px; border-radius: 8px; font-size: 11px; font-weight: bold; background: var(--surface); color: var(--primary); border: 1px solid var(--border); box-shadow: 0 2px 5px rgba(0,0,0,0.02);}

        .gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 15px; padding-bottom: 40px; }
        .mosaic-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 15px; cursor: pointer; transition: 0.3s; border-left: 5px solid var(--user-accent); display: flex; flex-direction: column; gap: 6px; box-shadow: 0 4px 6px rgba(0,0,0,0.02); overflow: hidden; position: relative;}
        .mosaic-card:hover { transform: translateY(-5px); border-color: var(--user-accent); box-shadow: 0 10px 20px var(--user-accent-glow); }
        .mosaic-card.type-E { border-left-color: var(--danger); } .mosaic-card.type-P { border-left-color: var(--info); }
        .m-top { display: flex; justify-content: space-between; align-items: center; }
        .m-date { font-size: 10px; color: var(--text-muted); font-weight: bold; }
        .m-type { font-size: 9px; padding: 3px 6px; border-radius: 4px; background: var(--bg); font-weight: 800; color: var(--text); border: 1px solid var(--border);}
        .m-provider { font-size: 12px; font-weight: 800; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }
        .m-mid { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 4px; border-top: 1px dashed var(--border); padding-top: 8px; }
        .m-folio { font-size: 13px; font-weight: 900; color: #334155 }
        .m-total { font-size: 14px; font-weight: 900; color: var(--user-accent); }
        
        .m-footer-mosaic { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px; gap: 5px; }
        .m-footer-mosaic .m-uuid { font-size: 9.5px; color: var(--text-muted); font-family: monospace; word-break: break-all; line-height: 1.2; flex-grow: 1; }
        .btn-sat-mosaic { background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); border-radius: 12px; padding: 4px 10px; font-size: 9px; font-weight: 700; cursor: pointer; transition: all 0.2s ease; display: inline-flex; align-items: center; gap: 4px; text-transform: uppercase; white-space: nowrap; }
        .btn-sat-mosaic:hover { background: var(--border); transform: scale(1.05); }

        .table-container { background: var(--surface); border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.03); overflow: auto; height: calc(100vh - 160px); border: 1px solid var(--border); display: none; }
        table.excel-table { border-collapse: collapse; font-size: 11px; table-layout: fixed; width: 100%; }
        table.excel-table th { background: #1f4e78 !important; color: white !important; padding: 8px 10px; position: sticky; top: 0; z-index: 10; border: 1px solid #34495e; font-weight: bold; text-align: center; white-space: nowrap; }
        table.excel-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .text-center { text-align: center; } .text-right { text-align: right; } .text-left { text-align: left; }
        .currency { font-family: 'Courier New', Courier, monospace; font-weight: bold; }
        .resizer { position: absolute; top: 0; right: 0; width: 6px; cursor: col-resize; user-select: none; height: 100%; z-index: 20; background: transparent; }
        .resizer:hover, .resizing { background-color: rgba(255, 255, 255, 0.3); }

        .visor-nativo-container { display: none; width: 100%; height: calc(100vh - 160px); background: #525659; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.05); border: 1px solid var(--border);}
        .visor-nativo-container iframe { width: 100%; height: 100%; border: none; }

        /* --- MODALES --- */
        .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.7); display: none; justify-content: center; align-items: center; z-index: 10000; backdrop-filter: blur(5px); }
        .modal-card { background: var(--surface); padding: 40px; border-radius: 20px; width: 90%; max-width: 480px; text-align: center; box-shadow: 0 25px 50px rgba(0,0,0,0.25); border-top: 6px solid var(--user-accent); }
        .upload-area { border: 2px dashed var(--border); padding: 30px 20px; border-radius: 12px; cursor: pointer; transition: 0.3s; background: var(--bg); margin: 20px 0; }
        .upload-area:hover { border-color: var(--user-accent); background: var(--user-accent-glow); }
        .progress-container { width: 100%; background-color: var(--border); border-radius: 8px; overflow: hidden; display: none; margin: 15px 0; height: 8px; }
        .progress-bar { height: 100%; width: 0%; background-color: var(--user-accent); transition: width 0.2s ease; }

        .pdf-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 9999; display: none; justify-content: center; align-items: center; backdrop-filter: blur(4px); }
        .pdf-modal-content { background: #525659; width: 95%; max-width: 1100px; height: 90vh; border-radius: 12px; position: relative; padding: 0; box-shadow: 0 20px 50px rgba(0,0,0,0.5); border: 1px solid #333;}
        .pdf-close { position: absolute; top: -15px; right: -15px; background: var(--danger); color: white; border: none; width: 35px; height: 35px; border-radius: 50%; font-weight: bold; cursor: pointer; font-size: 16px; box-shadow: 0 4px 10px rgba(0,0,0,0.3); transition: 0.2s; z-index: 100; }
        .pdf-close:hover { filter: brightness(1.1); transform: scale(1.1); }
        .pdf-modal-content iframe { width: 100%; height: 100%; border: none; border-radius: 12px; }

        /* LOADER RASTREO */
        .search-loader-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.85); z-index: 10001; display: none; flex-direction: column; align-items: center; justify-content: center; color: white; backdrop-filter: blur(5px); }
        .search-spinner { width: 60px; height: 60px; border: 6px solid rgba(255,255,255,0.1); border-top: 6px solid var(--user-accent); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 20px; }
        @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

        .mosaic-card.is-canceled::after { content: "CANCELADO"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-45deg); font-size: 22px; color: rgba(239, 68, 68, 0.15); font-weight: 900; border: 3px solid rgba(239, 68, 68, 0.15); padding: 4px 8px; z-index: 100; pointer-events: none; white-space: nowrap; border-radius: 6px;}
        .toast-banner { position: fixed; top: 20px; right: 20px; background: var(--emitidos); color: white; padding: 12px 20px; border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); display: none; align-items: center; gap: 10px; z-index: 10002; animation: slideIn 0.3s ease; font-size: 13px; font-weight: bold; }
        @keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

        @media print { .app-layout, .dashboard-header, .sidebar-explorer { display: none !important; } body { background: white; overflow: auto; } }

        .status-badge.status-emitido { background: #e8f5e9 !important; color: #27ae60 !important; border: 1px solid #27ae60 !important; }
        .status-badge.status-recibido { background: #fbeee6 !important; color: #e67e22 !important; border: 1px solid #e67e22 !important; }
        .status-badge.status-otros { background: var(--bg) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }

        .btn-sat-circular {
            background: var(--user-accent-glow) !important; border: 1px solid var(--user-accent) !important;
            backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
            box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.25), 0 4px 10px rgba(0, 0, 0, 0.08);
            padding: 0; width: 28px; height: 28px; border-radius: 50%; font-size: 11px;
            display: flex; align-items: center; justify-content: center; margin: 0 auto;
            cursor: pointer; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); user-select: none;
        }
        .btn-sat-circular:hover { transform: scale(1.15) translateY(-1px); box-shadow: 0 6px 15px var(--user-accent-glow); filter: brightness(1.1); }

        .reload-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.4); z-index: 10005; display: none; justify-content: center; align-items: center; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); opacity: 0; transition: opacity 0.3s ease; }
        .reload-card { background: var(--surface); padding: 30px 40px; border-radius: 20px; text-align: center; box-shadow: 0 25px 50px rgba(0,0,0,0.2); border: 1px solid var(--border); border-top: 5px solid var(--user-accent); transform: scale(0.9); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); display: flex; flex-direction: column; align-items: center; gap: 15px; }
        .reload-overlay.active { opacity: 1; } .reload-overlay.active .reload-card { transform: scale(1); }
        .reload-spinner { width: 40px; height: 40px; border: 4px solid var(--border); border-top: 4px solid var(--user-accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
        .reload-text { font-weight: 900; color: var(--primary); font-size: 14px; text-transform: uppercase; letter-spacing: 1px;}
        .reload-sub { font-size: 11px; color: var(--text-muted); font-weight: bold;}

        /* --- EFECTOS DRAG & DROP PARA EL EXPLORADOR --- */
        .draggable-tree-item { transition: transform 0.2s ease, background-color 0.2s ease; }
        .draggable-tree-item.dragging { opacity: 0.4; background: var(--user-accent-glow); border: 1px dashed var(--user-accent); border-radius: 8px; }
        .draggable-tree-item.drag-over { border-top: 2px solid var(--user-accent); }

        /* =======================================================
           MODO ÍCONOS FORZADO (FIJADO POR EL USUARIO)
           ======================================================= */
        body.force-icons-mode .btn-apple .btn-text,
        body.force-icons-mode.sidebar-collapsed .btn-apple .btn-text {
            display: none !important;
            max-width: 0 !important;
            opacity: 0 !important;
        }

        body.force-icons-mode .btn-apple,
        body.force-icons-mode.sidebar-collapsed .btn-apple {
            padding: 0 10px !important;
            gap: 0 !important;
            justify-content: center !important;
        }