@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

/* =============================================================================
   SISTEMA DE DISEÑO Y CONFIGURACIÓN BASE (Vanilla CSS)
   ============================================================================= */
:root {
    /* --- Colores Extraídos Básicos --- */
    --color-1: #1B6327;
    --color-2: #F47A00;
    --color-3: #E6BC9D;
    --color-4: #3B9346;
    --color-5: #2D322E;
    --color-6: #0F47A1;

    /* --- Colores Relativos / Expansión del Espectro --- */
    --color-7: #0D3A16;
    --color-8: #76C283;
    --color-9: #FFA447;
    --color-10: #7A583F;
    --color-11: #F4F6F4;
    --color-12: #5A6B7C;

    --bg-main: #99c9f7;
    --bg-gradient: linear-gradient(135deg, #0b0f19 0%, #1e1b4b 50%, #0f172a 100%);
    --bg-card: rgba(22, 28, 45, 0.65);
    --bg-card-hover: rgba(30, 41, 59, 0.8);
    --border-glow: rgba(99, 102, 241, 0.15);
    --border-light: rgba(255, 255, 255, 0.07);

    --color-primary: #5898eb;
    /* Indigo */
    --color-secondary: #5898eb;
    /* Cyan */
    --color-accent: #10b981;
    /* Emerald */
    --color-danger: #da121cd0;
    /* Red */
    --color-warning: #f59e0b;
    /* Amber */

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;

    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    --sidebar-width: 280px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.5), 0 1px 1px 0 rgba(255, 255, 255, 0.05) inset;

    /* Variables parametrizadas del tema (Valores por defecto en modo oscuro) */
    --bg-input: rgba(15, 23, 42, 0.6);
    --bg-input-focus: rgba(15, 23, 42, 0.85);
    --input-focus-glow: rgba(99, 102, 241, 0.25);
    --bg-sidebar: rgba(15, 23, 42, 0.85);
    --bg-menu-hover: rgba(255, 255, 255, 0.05);
    --bg-menu-active: rgba(99, 102, 241, 0.15);
    --border-menu-active: rgba(99, 102, 241, 0.25);
    --bg-icon-circle: rgba(255, 255, 255, 0.03);

    --badge-role-1-bg: rgba(99, 102, 241, 0.15);
    --badge-role-1-text: #818cf8;
    --badge-role-1-border: rgba(99, 102, 241, 0.3);

    --badge-role-2-bg: rgba(6, 182, 212, 0.15);
    --badge-role-2-text: #22d3ee;
    --badge-role-2-border: rgba(6, 182, 212, 0.3);

    --badge-role-3-bg: rgba(148, 163, 184, 0.15);
    --badge-role-3-text: #cbd5e1;
    --badge-role-3-border: rgba(148, 163, 184, 0.3);

    --badge-role-4-bg: rgba(139, 92, 246, 0.15);
    --badge-role-4-text: #a78bfa;
    --badge-role-4-border: rgba(139, 92, 246, 0.3);

    --badge-role-5-bg: rgba(245, 158, 11, 0.15);
    --badge-role-5-text: #fbbf24;
    --badge-role-5-border: rgba(245, 158, 11, 0.3);

    --badge-role-6-bg: rgba(239, 68, 68, 0.15);
    --badge-role-6-text: #f87171;
    --badge-role-6-border: rgba(239, 68, 68, 0.3);

    --btn-bg: linear-gradient(135deg, var(--color-primary) 0%, #4338ca 100%);
    --btn-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
    --btn-shadow-hover: 0 6px 20px rgba(99, 102, 241, 0.5);

    --btn-logout-text: #ff5e1f;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-main);
    background-image: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* =============================================================================
   PÁGINA DE LOGIN (Glassmorphism & Estilo Premium)
   ============================================================================= */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-light);
    border-radius: 20px;
    width: 100%;
    max-width: 440px;
    padding: 40px;
    box-shadow: var(--shadow-premium);
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.login-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, var(--border-glow) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

.login-header {
    position: relative;
    z-index: 1;
    text-align: center;
    margin-bottom: 30px;
}

.login-logo {
    font-size: 2.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--color-secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
    letter-spacing: -0.05em;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 300;
}

.login-form {
    position: relative;
    z-index: 1;
}

.form-group {
    margin-bottom: 22px;
    position: relative;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-wrapper {
    position: relative;
}

.form-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 1rem;
    transition: var(--transition-smooth);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 15px var(--input-focus-glow);
    background: var(--bg-input-focus);
}

.form-input:disabled {
    opacity: 0.85;
    color: var(--text-primary);
    font-weight: 600;
    cursor: not-allowed;
    background: rgba(15, 23, 42, 0.45);
}

/* Alertas de Mensajes */
.alert {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.9rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 4px solid transparent;
}

.alert-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-left-color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.alert-success {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-left-color: var(--color-accent);
    border: 1px solid rgba(16, 185, 129, 0.25);
}

/* Botones con micro-animaciones */
.btn {
    width: 100%;
    background: var(--btn-bg);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    box-shadow: var(--btn-shadow);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--btn-shadow-hover);
    filter: brightness(1.1);
}

.btn:active {
    transform: translateY(0);
}

/* =============================================================================
   DISEÑO DEL DASHBOARD (Sidebar + Main Panel)
   ============================================================================= */
.dashboard-container {
    display: flex;
    min-height: 100vh;
}

/* Barra Lateral (Sidebar) */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: var(--transition-smooth);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--color-secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.03em;
}

/* Info del Usuario Logueado en Sidebar */
.user-panel {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    background: rgba(255, 255, 255, 0.01);
}

.user-avatar-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 1.2rem;
    box-shadow: 0 4px 10px rgba(6, 182, 212, 0.2);
}

.user-info {
    overflow: hidden;
}

.user-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.user-role-global {
    font-size: 0.75rem;
    color: var(--color-secondary);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Menú Dinámico de Navegación */
.sidebar-menu {
    list-style: none;
    padding: 20px 16px;
    flex-grow: 1;
    overflow-y: auto;
}

.menu-item {
    margin-bottom: 8px;
}

.menu-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.menu-link:hover {
    background: var(--bg-menu-hover);
    color: var(--text-primary);
    transform: translateX(4px);
}

.menu-link.active {
    background: var(--bg-menu-active);
    border: 1px solid var(--border-menu-active);
    color: var(--color-primary);
}

.menu-link-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-bullet {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--text-muted);
    transition: var(--transition-smooth);
}

.menu-link:hover .menu-bullet {
    background-color: var(--color-secondary);
    box-shadow: 0 0 8px var(--color-secondary);
}

/* Badge de Rol Específico del Módulo */
.badge-role {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-role-1 {
    background: var(--badge-role-1-bg);
    color: var(--badge-role-1-text);
    border: 1px solid var(--badge-role-1-border);
}

/* Admin */
.badge-role-2 {
    background: var(--badge-role-2-bg);
    color: var(--badge-role-2-text);
    border: 1px solid var(--badge-role-2-border);
}

/* Editor */
.badge-role-3 {
    background: var(--badge-role-3-bg);
    color: var(--badge-role-3-text);
    border: 1px solid var(--badge-role-3-border);
}

/* Lector */

/* Limit 1 */
.badge-role-4 {
    background: var(--badge-role-4-bg);
    color: var(--badge-role-4-text);
    border: 1px solid var(--badge-role-4-border);
}

/* Limit 2 */
.badge-role-5 {
    background: var(--badge-role-5-bg);
    color: var(--badge-role-5-text);
    border: 1px solid var(--badge-role-5-border);
}

/* Inhabilitado */
.badge-role-6 {
    background: var(--badge-role-6-bg);
    color: var(--badge-role-6-text);
    border: 1px solid var(--badge-role-6-border);
}

.badge-uf {
    background: rgba(6, 182, 212, 0.15);
    color: #22d3ee;
    border: 1px solid rgba(6, 182, 212, 0.3);
}

.badge-pesos {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Footer Sidebar (Cierre Sesión) */
.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-light);
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--color-danger);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 10px;
    border-radius: 10px;
    width: 100%;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition-smooth);
}

.btn-logout:hover {
    background: var(--color-danger);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Área Principal de Contenido */
.main-content {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    padding: 40px;
    transition: var(--transition-smooth);
}

/* Cabecera del Contenido */
.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    position: relative;
}

.welcome-section h1 {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 6px;
    background: linear-gradient(135deg, var(--text-primary) 40%, var(--text-secondary) 100%);
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-section p {
    color: var(--text-muted);
    font-size: 1rem;
}

/* Grid de Módulos (Tarjetas Principal) */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.module-card {
    background: var(--bg-card);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 200px;
    position: relative;
    overflow: hidden;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    text-decoration: none;
    color: inherit;
}

.module-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    transform: scaleX(0);
    transform-origin: left;
    transition: var(--transition-smooth);
}

.module-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-5px);
    border-color: rgba(99, 102, 241, 0.3);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.module-card:hover::after {
    transform: scaleX(1);
}

.module-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.module-icon-circle {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--bg-icon-circle);
    border: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-secondary);
    font-size: 1.3rem;
    transition: var(--transition-smooth);
}

.module-card:hover .module-icon-circle {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.module-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 16px;
    color: var(--text-primary);
}

.module-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
    flex-grow: 1;
}

.module-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 15px;
}

/* Botón de Menú Móvil (Hamburguesa) */
.mobile-menu-toggle {
    display: none;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    width: 44px;
    height: 44px;
    border-radius: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: var(--transition-smooth);
}

.mobile-menu-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* =============================================================================
   RESPONSIVIDAD Y LAYOUTS ADAPTABLES
   ============================================================================= */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.7);
    }

    .main-content {
        margin-left: 0;
        padding: 30px 20px;
    }

    .mobile-menu-toggle {
        display: flex;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 30px 20px;
    }

    .welcome-section h1 {
        font-size: 1.8rem;
    }

    .modules-grid {
        grid-template-columns: 1fr;
    }
}

/* =============================================================================
   BOTÓN DE LOGOUT EN CABECERA (Visible & Responsive)
   ============================================================================= */
.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-header-logout {
    width: auto !important;
    padding: 10px 20px !important;
    font-size: 0.9rem !important;
    background: rgba(239, 68, 68, 0.08) !important;
    border: 1px solid rgba(239, 68, 68, 0.25) !important;
    color: var(--btn-logout-text) !important;
    box-shadow: none !important;
    transition: var(--transition-smooth) !important;
}

.btn-header-logout:hover {
    background: var(--color-danger) !important;
    color: white !important;
    border-color: var(--color-danger) !important;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4) !important;
    transform: translateY(-2px) !important;
}

@media (max-width: 576px) {
    .btn-header-logout span {
        display: none;
    }

    .btn-header-logout {
        padding: 10px !important;
        border-radius: 10px !important;
    }
}