/* ==========================
   VARIABLES CSS
========================== */
:root {
    /* Colores principales */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #06b6d4;
    --accent: #f43f5e;

    /* Colores de fondo */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-header: #1e293b;

    /* Colores de texto */
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-light: #cbd5e1;

    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Bordes */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    /* Espaciado */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Transiciones */
    --transition-fast: 150ms ease-in-out;
    --transition-base: 250ms ease-in-out;
    --transition-slow: 350ms ease-in-out;
}

/* ==========================
   RESET BÁSICO
========================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ==========================
   BODY Y HTML
========================== */
html {
    scroll-behavior: smooth;
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
    pointer-events: none;
    z-index: -1;
}

/* ==========================
   HEADER / NAVBAR
========================== */
header {
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(10px);
    padding: 0 24px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
    animation: slideDown 0.4s ease-out;
    /* altura fija para alinear verticalmente todo */
    height: 64px;
    display: flex;
    align-items: center;
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

/* ==========================
   HEADER IZQUIERDA — info de usuario
========================== */
.nav-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Avatar con inicial del usuario */
.nav-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
    letter-spacing: 0;
}

.nav-user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1;
}

.nav-user-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
}

.nav-user-meta {
    font-size: 0.72rem;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Badges de rol */
.nav-role-badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1px 6px;
    border-radius: 4px;
}

.nav-role-admin {
    background: rgba(99, 102, 241, 0.3);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.4);
}

.nav-role-user {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Brand cuando no está autenticado */
.nav-brand {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}

/* ==========================
   HEADER DERECHA — links de nav
========================== */
.header-right {
    position: relative;
    display: flex;
    align-items: center;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 2px;
    align-items: center;
    margin: 0;
    padding: 0;
}

.nav-links li {
    display: flex;
    align-items: center;
}

/* Separador vertical entre links y "Salir" */
.nav-separator {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 6px;
    flex-shrink: 0;
}

/* ==========================
   NAV LINKS — estado base, hover, active
========================== */
.nav-link {
    color: var(--text-light);
    text-decoration: none;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background var(--transition-fast),
                color var(--transition-fast),
                transform var(--transition-fast);
    position: relative;
    white-space: nowrap;
    /* subrayado animado */
    border-bottom: 2px solid transparent;
}

.nav-link:hover {
    background: rgba(99, 102, 241, 0.15);
    color: #fff;
    transform: translateY(-1px);
}

.nav-link:active {
    transform: translateY(0);
}

/* Estado activo — link de la página actual */
.nav-link--active {
    background: rgba(99, 102, 241, 0.2);
    color: #fff;
    border-bottom-color: var(--primary-light);
}

.nav-link--active .menu-icon {
    filter: drop-shadow(0 0 4px rgba(129, 140, 248, 0.6));
}

/* Salir — mantiene su color rojo */
.nav-logout {
    color: #fca5a5 !important;
}

.nav-logout:hover {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #fecaca !important;
}

.menu-icon {
    font-size: 1rem;
    line-height: 1;
    flex-shrink: 0;
}

/* ==========================
   HAMBURGUESA (móvil)
========================== */
.hamburger {
    display: none;
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.3);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-base);
    margin-right: 8px;
}

.hamburger:hover {
    background: rgba(99, 102, 241, 0.3);
    transform: scale(1.05);
}

.hamburger:active {
    transform: scale(0.95);
}

/* ==========================
   CONTENEDOR PRINCIPAL
========================== */
.container {
    max-width: 1200px;
    margin: 32px auto;
    background: var(--bg-card);
    padding: 32px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    animation: fadeInUp 0.5s ease-out;
    position: relative;
    flex: 1;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0);    }
}

.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--secondary), var(--accent));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* ==========================
   FLASH MESSAGES
========================== */
.flash-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    max-width: 400px;
    width: 100%;
}

.flash {
    padding: 16px 20px;
    margin-bottom: 12px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideInRight 0.4s ease-out;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.flash-content { flex: 1; }

.flash-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flash-close:hover { opacity: 1; }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: translateX(0);    }
}

.flash::before { font-size: 1.5rem; flex-shrink: 0; }

.flash-success {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    border-left: 4px solid #10b981;
    color: #065f46;
}
.flash-success::before { content: '✓'; }

.flash-danger {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-left: 4px solid #ef4444;
    color: #991b1b;
}
.flash-danger::before { content: '✕'; }

.flash-warning {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-left: 4px solid #f59e0b;
    color: #92400e;
}
.flash-warning::before { content: '⚠'; }

.flash-info {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    border-left: 4px solid #3b82f6;
    color: #1e40af;
}
.flash-info::before { content: 'ℹ'; }

/* ==========================
   TIPOGRAFÍA
========================== */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 16px;
}

h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }

a {
    color: var(--primary);
    transition: color var(--transition-fast);
}

a:hover { color: var(--primary-dark); }

/* ==========================
   SCROLLBAR
========================== */
::-webkit-scrollbar       { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--primary-light); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ==========================
   FOOTER — minimalista
========================== */
.footer {
    margin-top: auto;
    padding: 12px 24px;
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
}

.footer-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(203, 213, 225, 0.45);
    font-size: 0.78rem;
}

.footer-sep     { opacity: 0.4; }
.footer-version { opacity: 0.35; font-size: 0.72rem; }

/* ==========================
   OFFLINE BANNER
========================== */
.offline-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9998;
    background: #92400e;
    color: #fef3c7;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-top: 1px solid #b45309;
    animation: slideUpBanner 0.3s ease-out;
}

@keyframes slideUpBanner {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* ==========================
   LOADING OVERLAY
========================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    color: white;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spinner 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spinner { to { transform: rotate(360deg); } }

.loading-overlay p { font-size: 1.1rem; font-weight: 600; }

/* ==========================
   RESPONSIVE
========================== */
@media screen and (max-width: 768px) {
    header {
        height: auto;
        padding: 12px 16px;
    }

    /* En móvil ocultamos la info de sucursal para ahorrar espacio */
    .nav-user-meta { display: none; }

    .nav-links {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 52px;
        right: 0;
        background: rgba(30, 41, 59, 0.98);
        backdrop-filter: blur(20px);
        width: 240px;
        padding: 12px;
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-xl);
        border: 1px solid rgba(255, 255, 255, 0.1);
        animation: slideIn 0.25s ease-out;
        gap: 4px;
    }

    @keyframes slideIn {
        from { opacity: 0; transform: translateY(-8px) scale(0.97); }
        to   { opacity: 1; transform: translateY(0)    scale(1);    }
    }

    .nav-links.show { display: flex; }

    .nav-links li  { width: 100%; }
    .nav-separator { width: 100%; height: 1px; margin: 4px 0; }

    .nav-link {
        width: 100%;
        padding: 11px 14px;
        border-bottom: none;
        border-left: 2px solid transparent;
    }

    .nav-link--active {
        border-bottom-color: transparent;
        border-left-color: var(--primary-light);
    }

    .hamburger { display: block; }

    .container {
        margin: 16px;
        padding: 20px;
    }

    .flash-container {
        top: 70px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

    .flash { padding: 12px 16px; font-size: 0.85rem; }

    .footer { padding: 10px 16px; }
}