/* ── Animación de fondo: canvas z-stacking ─────────────────────────────── */
#bg-canvas          { z-index: 0; }
body.app-shell aside { position: fixed; z-index: 10; }
body.app-shell main.app-main {
    position: relative;
    z-index: 1;
    background: transparent;   /* deja que el canvas se vea entre los paneles */
}

/* Custom Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInFromBottom {
    from { opacity: 0; transform: translateY(0.5rem); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation-duration: 300ms;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    animation-fill-mode: both;
}

.fade-in {
    animation-name: fadeIn;
}

.slide-in-from-bottom-2 {
    animation-name: slideInFromBottom;
}

/* Base Selectors for pseudo loaders */
.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .5; }
}

.animate-bounce {
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(-25%);
        animation-timing-function: cubic-bezier(0.8,0,1,1);
    }
    50% {
        transform: none;
        animation-timing-function: cubic-bezier(0,0,0.2,1);
    }
}

/* Print Styles */
@media print {
    body * { visibility: hidden; }
    .printable-area, .printable-area * { visibility: visible; }
    .printable-area { 
        position: absolute; 
        left: 0; 
        top: 0; 
        width: 100%; 
        border: none !important; 
        box-shadow: none !important; 
    }
    aside { display: none !important; }
    main { margin-left: 0 !important; padding: 0 !important; }
}

/* EXECUTIVE DARK THEME OVERRIDES */
body {
    background-color: #0B1120 !important;
    color: #F3F4F6 !important;
    font-family: 'DM Sans', sans-serif !important;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Syne', sans-serif !important;
    color: #F8FAFC !important;
    letter-spacing: -0.02em !important;
}

.bg-white, .bg-gray-50, .bg-amber-50, .bg-indigo-50 {
    background-color: #111827 !important;
    border: 1px solid #1E3A8A !important;
}

.text-gray-800, .text-gray-900, .text-amber-900, .text-indigo-900 {
    color: #F8FAFC !important;
}

.text-gray-700, .text-gray-600, .text-amber-700, .text-indigo-800 {
    color: #D1D5DB !important;
}

.text-gray-500, .text-slate-500 {
    color: #9CA3AF !important;
}

.border-gray-100, .border-gray-200, .border-amber-100, .border-amber-200, .border-indigo-100, .border-indigo-200 {
    border-color: #1E3A8A !important;
}

.bg-amber-100 { background-color: rgba(212,175,55,0.1) !important; color: #D4AF37 !important; border: 1px solid rgba(212,175,55,0.2) !important; }
.bg-emerald-100 { background-color: rgba(16,185,129,0.1) !important; color: #10B981 !important; border: 1px solid rgba(16,185,129,0.2) !important; }
.bg-red-100 { background-color: rgba(239,68,68,0.1) !important; color: #EF4444 !important; border: 1px solid rgba(239,68,68,0.2) !important; }
.bg-blue-100 { background-color: rgba(59,130,246,0.1) !important; color: #3B82F6 !important; border: 1px solid rgba(59,130,246,0.2) !important; }
.bg-orange-50 { background-color: rgba(245,158,11,0.06) !important; border: 1px solid rgba(245,158,11,0.14) !important; }
.bg-purple-50 { background-color: rgba(139,92,246,0.06) !important; border: 1px solid rgba(139,92,246,0.14) !important; }
.bg-indigo-100 { background-color: rgba(99,102,241,0.1) !important; color: #818CF8 !important; border: 1px solid rgba(99,102,241,0.2) !important; }

.text-amber-600, .text-amber-700 { color: #D4AF37 !important; }
.text-emerald-600 { color: #10B981 !important; }
.text-red-500, .text-red-600 { color: #EF4444 !important; }
.text-blue-500, .text-blue-600 { color: #3B82F6 !important; }
.text-indigo-600, .text-indigo-900 { color: #818CF8 !important; }
.text-orange-700 { color: #F59E0B !important; }
.text-purple-700 { color: #A78BFA !important; }

.bg-amber-600, .bg-indigo-600, .bg-gray-800 {
    background-color: #D4AF37 !important;
    color: #111827 !important;
    border: none !important;
    box-shadow: 0 4px 14px rgba(212, 175, 55, 0.25) !important;
    font-weight: 600 !important;
}

.bg-amber-600:hover, .bg-indigo-700:hover, .bg-gray-900:hover {
    background-color: #F59E0B !important;
}

thead.bg-gray-50 {
    background-color: #0F172A !important;
    color: #9CA3AF !important;
    border-bottom: 1px solid #1E3A8A !important;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.divide-y > * + * {
    border-color: #1E3A8A !important;
}

.bg-gray-100 {
    background-color: #1E293B !important;
}

input, select {
    background-color: #0F172A !important;
    color: #F3F4F6 !important;
    border: 1px solid #1E3A8A !important;
    border-radius: 6px !important;
}
input:focus, select:focus {
    border-color: #D4AF37 !important;
    outline: none !important;
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2) !important;
}

.shadow-lg, .shadow-sm {
    box-shadow: 0 4px 6px -1px #00000050, 0 2px 4px -1px #00000020 !important;
}

.hover\:bg-gray-50:hover {
    background-color: rgba(255,255,255,0.02) !important;
}

.dashboard-chart {
    width: 100%;
    height: 320px;
    min-width: 0;
}

.dashboard-chart-lg {
    width: 100%;
    height: 360px;
    min-width: 0;
}

.dashboard-chart-xl {
    width: 100%;
    height: 430px;
    min-width: 0;
}

.dashboard-chart-sm {
    width: 100%;
    height: 260px;
    min-width: 0;
}

.dashboard-panel {
    background:
        radial-gradient(circle at top left, rgba(245, 158, 11, 0.08), transparent 42%),
        linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.88));
    min-width: 0;
    overflow: hidden;
}

.dashboard-kpi {
    background:
        linear-gradient(180deg, rgba(15, 23, 42, 0.95), rgba(17, 24, 39, 0.92));
    border: 1px solid rgba(59, 130, 246, 0.18);
    min-height: 176px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
}

.dashboard-kpi:hover {
    transform: scale(1.02);
    box-shadow: 0 12px 24px rgba(59, 130, 246, 0.25), 0 8px 16px rgba(0, 0, 0, 0.3);
    border-color: rgba(59, 130, 246, 0.35);
}

.kpi-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    z-index: 10;
}

.kpi-sparkline {
    width: 100%;
    height: 40px;
    margin-top: 8px;
    opacity: 0;
    animation: slideInUpKPI 0.4s ease-out 0.2s forwards;
}

@keyframes slideInUpKPI {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dashboard-filter {
    min-width: 160px;
}

.dashboard-period-chip {
    border: 1px solid rgba(51, 65, 85, 0.95);
    background: rgba(15, 23, 42, 0.7);
    color: #94a3b8;
    border-radius: 9999px;
    padding: 0.45rem 0.8rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    transition: all 0.2s ease;
}

.dashboard-period-chip:hover {
    color: #f8fafc;
    border-color: rgba(245, 158, 11, 0.24);
}

.dashboard-period-chip.is-active {
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.28);
    color: #fbbf24;
}

.dashboard-period-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 0.95rem;
    border: 1px solid rgba(51, 65, 85, 0.95);
    background: rgba(15, 23, 42, 0.85);
    color: #cbd5e1;
    transition: all 0.2s ease;
}

.dashboard-period-arrow:hover {
    border-color: rgba(245, 158, 11, 0.24);
    color: #f8fafc;
    background: rgba(30, 41, 59, 0.92);
}

.dashboard-empty {
    min-height: 320px;
}

#inventoryCartList {
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.5) rgba(15, 23, 42, 0.85);
}

#inventoryCartList::-webkit-scrollbar {
    width: 10px;
}

#inventoryCartList::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.92);
    border-radius: 999px;
    border: 1px solid rgba(30, 41, 59, 0.95);
}

#inventoryCartList::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(148, 163, 184, 0.7), rgba(100, 116, 139, 0.9));
    border-radius: 999px;
    border: 2px solid rgba(15, 23, 42, 0.92);
}

#inventoryCartList::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(148, 163, 184, 0.92), rgba(100, 116, 139, 1));
}

.executive-brief-view {
    --executive-surface: rgba(15, 23, 42, 0.88);
    --executive-line: rgba(59, 130, 246, 0.14);
}

.executive-hero {
    background:
        radial-gradient(circle at top right, rgba(14, 165, 233, 0.14), transparent 28%),
        radial-gradient(circle at top left, rgba(245, 158, 11, 0.1), transparent 30%),
        linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.9));
}

.executive-kpi-shell {
    position: relative;
    overflow: hidden;
}

.executive-kpi-shell::after {
    content: '';
    position: absolute;
    inset: auto -40px -50px auto;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.08), transparent 70%);
    pointer-events: none;
}

.executive-filter-field {
    display: grid;
    gap: 0.45rem;
}

.executive-filter-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.24em;
    color: #94a3b8;
    font-weight: 700;
}

.executive-filter-select {
    width: 100%;
    border: 0;
    background: transparent !important;
    color: #f8fafc !important;
    padding: 0;
    font-weight: 600;
    box-shadow: none !important;
}

.executive-filter-select:focus {
    outline: none !important;
    box-shadow: none !important;
}

.executive-tab {
    border: 1px solid rgba(51, 65, 85, 0.95);
    background: rgba(15, 23, 42, 0.7);
    color: #cbd5e1;
    border-radius: 999px;
    padding: 0.78rem 1rem;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    transition: all 180ms ease;
}

.executive-tab:hover {
    border-color: rgba(96, 165, 250, 0.3);
    color: #f8fafc;
    background: rgba(15, 23, 42, 0.95);
}

.executive-tab-active {
    border-color: rgba(6, 182, 212, 0.34);
    background: linear-gradient(180deg, rgba(8, 47, 73, 0.95), rgba(17, 24, 39, 0.92));
    color: #cffafe;
    box-shadow: 0 8px 30px rgba(8, 47, 73, 0.28);
}

@media (max-width: 1024px) {
    body.app-shell {
        display: block !important;
    }

    /* Solo la barra lateral principal de navegacion debe volverse sticky en
       pantallas angostas. El selector anterior ("body.app-shell aside") era
       un selector de descendiente y afectaba TODOS los <aside> de la app,
       incluido el <aside> anidado del Informe Ejecutivo (tarjetas Semaforos /
       Ritmo del periodo), que quedaba fijado con position:sticky y se
       solapaba sobre las pestanas y el contenido al hacer scroll. Lo
       limitamos al sidebar principal por su id. */
    body.app-shell > #main-sidebar {
        position: sticky !important;
        top: 0 !important;
        width: 100% !important;
        height: auto !important;
        border-right: none !important;
        border-bottom: 1px solid #1f2937 !important;
    }

    body.app-shell #sidebar-nav {
        display: flex;
        gap: 0.75rem;
        overflow-x: auto;
        padding-bottom: 0.25rem;
    }

    body.app-shell #sidebar-nav button {
        width: auto !important;
        flex: 0 0 auto;
    }

    body.app-shell main.app-main {
        margin-left: 0 !important;
        padding: 1.25rem !important;
    }
}

@media (max-width: 640px) {
    .dashboard-kpi {
        min-height: 188px;
    }

    .dashboard-chart,
    .dashboard-chart-lg,
    .dashboard-chart-sm {
        height: 280px;
    }
}

/* ── NUMERIC KEYPAD ────────────────────────────────────────────────────────── */
.numeric-key {
    padding: 16px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.1s ease;
    background: white;
    color: #1f2937;
}

.numeric-key:hover {
    background: #f3f4f6;
    border-color: #3b82f6;
}

.numeric-key:active {
    transform: scale(0.95);
    background: #dbeafe;
}

.numeric-key-action {
    background: #f59e0b;
    color: white;
    border-color: #f59e0b;
}

.numeric-key-action:hover {
    background: #d97706;
    border-color: #d97706;
}

.numeric-key-ok {
    background: #10b981;
    border-color: #10b981;
}

.numeric-key-ok:hover {
    background: #059669;
    border-color: #059669;
}

#numericDisplay {
    font-size: 32px;
    font-weight: bold;
    text-align: right;
    padding: 16px;
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 16px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    word-break: break-all;
    color: #1f2937;
}

/* ─────────────────────────────────────────────────────────────────────────────
   SIDEBAR RESPONSIVE — MÓVIL (≤ 768px)
   ───────────────────────────────────────────────────────────────────────────── */

/* Overlay semitransparente detrás del sidebar cuando está abierto */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Botón FAB hamburguesa — oculto por defecto en desktop */
.sidebar-hamburger-fab {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 8;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.75rem;
    background: #1e293b;
    border: 1px solid #334155;
    color: #f8fafc;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: background 0.15s;
}
.sidebar-hamburger-fab:hover { background: #334155; }

/* Botón "X" cerrar dentro del sidebar — oculto en desktop */
.sidebar-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    border: 1px solid #334155;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 0.25rem;
    transition: background 0.15s, color 0.15s;
}
.sidebar-close-btn:hover { background: #334155; color: #f8fafc; }

@media (max-width: 768px) {
    /* Sidebar: oculto por defecto en móvil */
    body.app-shell #main-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 11;
    }

    /* Sidebar abierto: desliza hacia adentro */
    body.app-shell #main-sidebar.sidebar-open {
        transform: translateX(0);
    }

    /* Overlay visible cuando sidebar está abierto */
    body.app-shell.sidebar-nav-open .sidebar-overlay {
        display: block;
    }

    /* FAB hamburguesa visible en móvil */
    .sidebar-hamburger-fab {
        display: flex;
    }

    /* FAB oculto cuando el sidebar está abierto */
    body.app-shell.sidebar-nav-open .sidebar-hamburger-fab {
        display: none;
    }

    /* Botón X visible en móvil */
    .sidebar-close-btn {
        display: flex;
    }

    /* Contenido principal ocupa todo el ancho */
    body.app-shell main.app-main {
        margin-left: 0 !important;
        padding: 1rem !important;
        padding-top: 4rem !important; /* Espacio para el FAB */
    }

    /* Anula el comportamiento horizontal del media query 1024px en mobile puro */
    body.app-shell aside {
        position: fixed !important;
        width: 16rem !important;
        height: 100% !important;
        border-right: 1px solid #1f2937 !important;
        border-bottom: none !important;
    }

    body.app-shell #sidebar-nav {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
        overflow-x: visible !important;
        overflow-y: auto !important;
    }

    body.app-shell #sidebar-nav button {
        width: 100% !important;
        flex: none !important;
    }
}

/* ─────────────────────────────────────────────────────────────────────────────
   SIDEBAR — scroll interno para nav largo + sección usuario siempre visible
   ───────────────────────────────────────────────────────────────────────────── */

#main-sidebar {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#main-sidebar nav#sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

#main-sidebar nav#sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

#main-sidebar nav#sidebar-nav::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 2px;
}

/* Sección usuario anclada al fondo del sidebar */
#main-sidebar > div:last-child {
    flex-shrink: 0;
}

/* ─────────────────────────────────────────────────────────────────────────────
   AUTH MODAL
   ───────────────────────────────────────────────────────────────────────────── */

/* Entrada animada del panel del modal */
#auth-modal > div {
    animation: auth-slide-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes auth-slide-in {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* Inputs del formulario de auth */
.auth-input {
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.auth-input:focus {
    border-color: #f59e0b !important;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.12);
}

/* Título del modal en distintos estados */
.auth-modal-title {
    font-family: 'Syne', sans-serif;
}

/* Scroll suave dentro del modal en móvil */
#auth-modal > div {
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}
#auth-modal > div::-webkit-scrollbar {
    width: 4px;
}
#auth-modal > div::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   SIDEBAR — SECCIÓN USUARIO
   ───────────────────────────────────────────────────────────────────────────── */

#sidebar-user-section {
    transition: opacity 0.2s ease;
}

/* Icono de sync giratorio */
@keyframes spin {
    from { transform: rotate(0deg);   }
    to   { transform: rotate(360deg); }
}
.animate-spin {
    animation: spin 1s linear infinite;
}

/* ─────────────────────────────────────────────────────────────────────────────
   ROLES — botones bloqueados con efecto de lock
   ───────────────────────────────────────────────────────────────────────────── */

#sidebar-nav button.opacity-40 {
    cursor: not-allowed;
}

/* Pantalla de acceso denegado */
.access-denied-screen {
    animation: auth-slide-in 0.25s ease both;
}
