:root {
    --primary: #0f3d6e;
    --primary-light: #1e56a0;
    --secondary: #f77f00;
    --success: #198754;
    --danger: #d62828;
    --warning: #fcbf49;
    --info: #4cc9f0;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark-mode {
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: var(--transition);
    min-height: 100vh;
}

/* Glassmorphism utility */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
}

/* Layout */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: var(--primary);
    color: white;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.topbar-left h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.topbar-left .sub {
    font-size: 0.75rem;
    opacity: 0.8;
}

.nav-right {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.navbtn, .logout, .btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: var(--transition);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.navbtn { background: rgba(255, 255, 255, 0.1); color: white; }
.navbtn:hover { background: rgba(255, 255, 255, 0.2); }

.logout { background: var(--danger); color: white; }
.logout:hover { filter: brightness(1.1); }

.theme-toggle {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: var(--transition);
}

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

/* Dashboard Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1.5rem 2rem;
}

.card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-decoration: none;
    color: var(--text);
    text-align: center;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: var(--shadow);
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
}

.card span {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card strong {
    font-size: 2.25rem;
    color: var(--primary);
}

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0 2rem 1.5rem;
    align-items: center;
}

.filters select, .filters input, .stack input, .stack select, textarea {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--surface);
    color: var(--text);
    font-size: 0.875rem;
    transition: var(--transition);
    outline: none;
}

.filters select:focus, .filters input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 61, 110, 0.1);
}

.filters input { min-width: 280px; }

.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--secondary); color: white; }
.btn-muted { background: var(--text-muted); color: white; }
.btn-success { background: var(--success); color: white; }

/* Table */
.table-wrap {
    padding: 0 2rem 2rem;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background-color: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

th, td {
    padding: 1rem;
    font-size: 0.875rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background-color: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background-color: rgba(0, 0, 0, 0.02); }
.dark-mode tr:hover td { background-color: rgba(255, 255, 255, 0.02); }

.status-vencido td { border-left: 1px solid #334155; background-color: rgba(51, 65, 85, 0.05); }
.status-por-vencer td { border-left: 1px solid #64748b; background-color: rgba(100, 116, 139, 0.05); }
.status-en-marcha td { border-left: 1px solid #94a3b8; background-color: rgba(148, 163, 184, 0.05); }
.status-sin-fecha td { border-left: 1px solid #cbd5e1; background-color: rgba(203, 213, 225, 0.05); }

/* Login */
.login-body {
    display: flex;
    height: 100vh; /* Strictly 100vh to prevent scrolling */
    max-height: 100vh;
    overflow: hidden; /* Hide any overflow */
    width: 100%;
    position: relative;
    /* Gemini-like airy radial background */
    background: radial-gradient(circle at center top, #e3f2fd 0%, #ffffff 40%, #eef5fc 100%);
}

/* Full screen watermark background */
.login-body::before {
    content: "";
    position: absolute;
    top: -5%; left: -5%; right: -5%; bottom: -5%; /* Overflow a bit to hide blurred edges */
    background: url('/static/images/Imagen_pantalla_Inicio.png');
    background-size: max(150vw, 200vh); /* Force it to zoom in significantly */
    background-position: center bottom; /* Align strictly to the bottom where the figures are */
    filter: blur(15px);
    opacity: 0.8; /* Increased visibility as requested */
    z-index: 0;
}

.login-image-pane {
    flex: 1; /* Takes up half the space */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0; /* Remove padding so there's no frame */
    position: relative;
    background-color: transparent; /* Remove blue color */
    z-index: 1;
}

.login-image-pane img {
    width: 100%;
    height: 100%;
    max-height: 100vh; /* Ensure image never exceeds screen height */
    object-fit: contain; /* Show the entire image */
    position: relative;
    z-index: 2;
    filter: drop-shadow(0 15px 25px rgba(0, 0, 0, 0.3)); /* Subtle shadow */
}

.login-form-pane {
    flex: 1; /* Takes up the other half */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 3rem 2.5rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.85); /* Slightly solid glass for light background */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 10px 40px -10px rgba(0,0,0,0.1);
}

/* Mobile responsive for split layout */
@media (max-width: 768px) {
    .login-body {
        flex-direction: column;
    }
    .login-image-pane {
        padding: 1rem;
    }
    .login-image-pane img {
        max-height: 40vh; /* Don't take up the whole screen on mobile */
    }
    .login-form-pane {
        padding: 1rem;
        align-items: flex-start;
    }
}

.login-card h2 {
    margin-bottom: 1.5rem;
    text-align: center;
    font-weight: 800;
    color: var(--primary);
}

/* Admin Panels */
.admin-grid {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 1.5rem;
    padding: 1.5rem 2rem;
}

.panel {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.panel h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
    color: var(--primary);
}

/* Forms */
.stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.card, tr, .panel {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Charts container */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
    padding: 0 2rem 1.5rem;
}

.chart-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    min-height: 300px;
    box-shadow: var(--shadow);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
}

.page-link {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: var(--transition);
}

.page-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-link:hover:not(.active) {
    background: var(--bg);
}

/* Flash Messages */
.pageflash {
    margin: 1rem 2rem;
}

.flash {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

.flash.danger { background-color: rgba(214, 40, 40, 0.1); color: var(--danger); border: 1px solid rgba(214, 40, 40, 0.2); }
.flash.success { background-color: rgba(25, 135, 84, 0.1); color: var(--success); border: 1px solid rgba(25, 135, 84, 0.2); }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Dropdown Export */
.export-dropdown {
    position: relative;
    display: inline-block;
    z-index: 1010; /* Higher than sticky headers */
}

.export-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 1011;
    min-width: 180px;
    padding: 5px 0; /* Padding instead of margin */
    overflow: hidden;
}

/* Invisible bridge to prevent menu from closing when moving mouse */
.export-menu::before {
    content: "";
    position: absolute;
    top: -10px;
    left: 0;
    width: 100%;
    height: 10px;
}

.export-dropdown:hover .export-menu {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

.export-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    transition: var(--transition);
}

.export-item:hover {
    background: var(--bg);
    color: var(--primary);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .admin-grid { grid-template-columns: 1fr; }
    .topbar { padding: 1rem; flex-direction: column; gap: 1rem; }
    .filters { padding: 0 1rem 1rem; }
    .cards { grid-template-columns: 1fr 1fr; padding: 1rem; }
}