:root {
    /* Color Palette - Inspirado en Los Nogales */
    --primary-color: #004a99;
    --primary-hover: #003670;
    --bg-dark: #f0f4f8; /* Fondo claro azulado */
    --bg-card: #ffffff; /* Tarjetas blancas */
    --bg-sidebar: #003e8c; /* Azul corporativo sidebar */
    --text-main: #1a2b4b; /* Azul muy oscuro para texto */
    --text-muted: #627d98;
    --border-color: #d9e2ec;
    
    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed: 78px;
    --header-height: 70px;
    --transition-speed: 0.25s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Typography & Utilities */
h1, h2, h3, h4, h5, h6 { font-weight: 700; color: var(--text-main); }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; outline: none; transition: 0.2s; }

input, select, textarea { 
    background: #fff; 
    border: 1px solid var(--border-color); 
    color: var(--text-main); 
    padding: 12px;
    border-radius: 8px;
    outline: none;
    font-size: 14px;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0,74,153,0.1); }

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    padding: 0;
    z-index: 100;
    color: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sidebar.close { width: var(--sidebar-collapsed); }

.sidebar .logo {
    display: flex;
    align-items: center;
    padding: 20px;
    height: var(--header-height);
    background: rgba(0,0,0,0.1);
    margin-bottom: 0px; /* Eliminamos margen para optimizar espacio */
    flex: 0 0 70px; /* Tamaño fijo para el logo */
}

.sidebar .logo img {
    max-height: 40px;
    width: auto;
    object-fit: contain;
}

.sidebar .logo i {
    min-width: 45px;
    font-size: 28px;
    color: #fff;
}

.sidebar .logo span {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.sidebar.close .logo span { opacity: 0; pointer-events: none; }

.nav-links { 
    list-style: none;
    flex: 1 1 auto; /* Permite crecer y encogerse correctamente */
    overflow-y: scroll !important;
    overflow-x: hidden;
    padding-top: 10px;
    padding-bottom: 100px; /* Mucho espacio al final para asegurar visibilidad */
    height: 100%;
}

.nav-links li, .nav-links li a {
    overflow: visible !important; /* Asegurar que no hay scroll por cada módulo */
}

/* Scrollbar Visibility Overrides */
.nav-links::-webkit-scrollbar { 
    width: 6px !important;
    display: block !important;
}
.nav-links::-webkit-scrollbar-track { 
    background: rgba(0,0,0,0.3) !important; 
}
.nav-links::-webkit-scrollbar-thumb { 
    background: #ffffff !important; 
    border-radius: 4px;
}
.nav-links::-webkit-scrollbar-thumb:hover { 
    background: #edf2f7 !important; 
}

/* Firefox scrollbar always on */
.nav-links { 
    scrollbar-width: thin; 
    scrollbar-color: #ffffff rgba(0,0,0,0.2); 
}
.nav-links li {
    padding: 0 15px;
    margin-bottom: 4px;
}
.nav-links li a {
    display: flex;
    align-items: center;
    padding: 12px 12px;
    border-radius: 8px;
    transition: 0.2s;
    color: rgba(255,255,255,0.8);
    font-weight: 500;
}
.sidebar .nav-links li a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--primary-color);
}

/* Sidebar Groups */
.nav-group {
    margin-top: 5px;
}

.group-title {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 8px;
    margin: 0 10px;
    user-select: none;
}

.group-title:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.group-title i {
    min-width: 45px;
    font-size: 20px;
    text-align: center;
}

.group-title span {
    font-size: 14px;
    font-weight: 500;
    flex-grow: 1;
}

.group-title .arrow {
    min-width: 20px;
    font-size: 16px;
    transition: transform 0.3s ease;
}

.nav-group.open .arrow {
    transform: rotate(180deg);
}

.sub-menu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    padding-left: 15px;
}

.nav-group.open .sub-menu {
    max-height: 500px; /* Large enough for all items */
}

.sub-menu li a {
    padding: 10px 15px !important;
    font-size: 13px !important;
    margin-left: 10px !important;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .group-title {
        padding: 18px 15px; /* Larger touch targets */
    }
    .sub-menu li a {
        padding: 15px 15px !important;
    }
}

.sidebar .nav-links li a.active {
    background: #eff6ff; /* Fondo claro para activo */
    color: var(--primary-color);
    position: relative;
}
.nav-links li a.active::before {
    content: '';
    position: absolute;
    left: 0; top: 20%; bottom: 20%;
    width: 4px;
    background: var(--primary-color);
    border-radius: 0 4px 4px 0;
}

.nav-links li a i {
    min-width: 35px;
    font-size: 20px;
}

.sidebar.close .nav-links li a span { display: none; }

/* Main Content */
.main-content {
    position: relative;
    left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    transition: all var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
}
.sidebar.close ~ .main-content {
    left: var(--sidebar-collapsed);
    width: calc(100% - var(--sidebar-collapsed));
}

/* Header */
header {
    height: var(--header-height);
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 99;
}
.toggle-sidebar { font-size: 26px; cursor: pointer; color: var(--text-main); }

.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg-dark);
    border-radius: 10px;
    padding: 2px 15px;
    width: 350px;
    border: 1px solid var(--border-color);
}
.search-bar i { color: var(--text-muted); }
.search-bar input {
    border: none;
    background: transparent;
    width: 100%;
    padding: 10px;
    box-shadow: none;
}

.user-profile { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.user-profile i { font-size: 24px; color: var(--primary-color); }

.dropdown-menu {
    position: absolute;
    top: 55px; right: 20px;
    background: #fff;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    border-radius: 12px;
    padding: 8px 0;
    width: 180px;
    display: none;
    z-index: 200;
}
.dropdown-menu.show { display: block; animation: fadeIn 0.15s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.dropdown-menu a {
    display: flex; align-items: center; padding: 10px 20px; color: var(--text-main); font-size: 14px;
}
.dropdown-menu a:hover { background: #f8fafc; color: var(--primary-color); }

/* App View Container */
#app-view {
    padding: 35px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    flex: 1;
}

/* Header UI Elements */
.view-header {
    margin-bottom: 35px;
}
.view-header h1 { font-size: 28px; letter-spacing: -0.5px; }
.view-header p {
    color: var(--text-muted);
    margin-top: 5px;
    font-size: 15px;
}

/* Rediseño de Métricas - Dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
}
.stat-card {
    background: #fff;
    padding: 25px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 20px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    transition: 0.3s;
}
.stat-card:hover { transform: translateY(-5px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }

.icon-wrapper {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}
.icon-wrapper.blue { background: #eff6ff; color: #1e61cc; }
.icon-wrapper.orange { background: #fffaf0; color: #d97706; }
.icon-wrapper.green { background: #f0fdf4; color: #15803d; }

.stat-info h3 { font-size: 15px; color: var(--text-muted); font-weight: 500; margin-bottom: 8px; }
.stat-info h2 { font-size: 30px; color: var(--text-main); }

/* Buttons Forms & Tables */
.btn {
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    transition: 0.3s;
}
.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,74,153,0.2); }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    background: #fff;
    padding: 40px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-main); text-transform: uppercase; letter-spacing: 0.5px; }

.form-actions { display: flex; justify-content: flex-end; gap: 15px; margin-top: 20px; }
.back-btn { font-size: 24px; cursor: pointer; vertical-align: middle; margin-right: 15px; color: var(--primary-color); }

/* Tables */
.table-responsive {
    background: #fff;
    border-radius: 16px;
    padding: 10px;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.data-table th, .data-table td {
    padding: 18px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.data-table th { background: #f8fafc; color: var(--text-main); font-weight: 600; font-size: 13px; text-transform: uppercase; }
.data-table tbody tr:hover { background: #f1f5f9; }
.data-table tbody tr:last-child td { border-bottom: none; }

.badge { padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.bg-blue { background: #eff6ff; color: #1e61cc; border: 1px solid #bfdbfe; }
.bg-gray { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.empty-state { text-align: center; color: var(--text-muted); padding: 60px 0; }
.btn-icon { background: transparent; color: var(--primary-color); font-size: 22px; padding: 8px; border-radius: 8px; }
.btn-icon:hover { background: #eff6ff; }

/* Login Screen */
.login-wrapper {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    display: flex; z-index: 1000; background: var(--bg-dark);
}
.login-image {
    flex: 1; background: url('../cover.png') center/cover no-repeat;
    position: relative;
    display: none; /* hidden on small screens */
}
@media(min-width: 768px){ .login-image { display: block; } }
.login-overlay {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.9));
    padding: 40px;
}
.login-overlay h1 { font-size: 48px; color: var(--primary-color); }
.login-overlay p { font-size: 18px; color: #fff; margin-top: 10px; }
.login-form-container {
    flex: 1; max-width: 500px; padding: 40px; display: flex; align-items: center; justify-content: center;
    background: var(--bg-card);
}
.login-box { width: 100%; }
.login-box h2 { font-size: 28px; margin-bottom: 5px; }
.login-box p { color: var(--text-muted); margin-bottom: 30px; }

/* Mobile Reponsive */
@media (max-width: 768px) {
    .sidebar { left: calc(-1 * var(--sidebar-width)); }
    .sidebar.mobile-open { left: 0; }
    .main-content { left: 0; width: 100%; }
    .search-bar { width: 150px; }
}

/* Print View */
@media print {
    .sidebar, header { display: none !important; }
    .main-content { left: 0; width: 100%; margin: 0; padding: 0; }
    body { background: #fff; color: #000; }
}
