:root {
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-blue: #38bdf8;
    --accent-indigo: #818cf8;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-xl: 0 10px 20px rgba(0,0,0,0.25);
    --transition:
        transform 0.25s ease,
        opacity 0.25s ease,
        background-color 0.25s ease,
        border-color 0.25s ease,
        color 0.25s ease;

    /* Escalas de tipografía responsiva */
    --fs-xs:   0.78rem;
    --fs-sm:   0.875rem;
    --fs-base: 1rem;
    --fs-lg:   1.125rem;
    --fs-xl:   1.35rem;
    --fs-2xl:  1.75rem;
    --fs-3xl:  2.25rem;
    --fs-4xl:  3rem;

    /* Espaciado */
    --space-xs:  0.5rem;
    --space-sm:  0.75rem;
    --space-md:  1.25rem;
    --space-lg:  2rem;
    --space-xl:  3rem;
    --space-2xl: 4rem;
}

/* ── 1440p / pantallas grandes ─────────────────────────────── */
@media (min-width: 1440px) {
    :root {
        --fs-xs:   0.85rem;
        --fs-sm:   0.95rem;
        --fs-base: 1.08rem;
        --fs-lg:   1.25rem;
        --fs-xl:   1.5rem;
        --fs-2xl:  2rem;
        --fs-3xl:  2.75rem;
        --fs-4xl:  3.75rem;

        --space-md:  1.5rem;
        --space-lg:  2.5rem;
        --space-xl:  4rem;
        --space-2xl: 5.5rem;
    }
}

/* ── 1080p ──────────────────────────────────────────────────── */
@media (min-width: 1080px) and (max-width: 1439px) {
    :root {
        --fs-base: 1.04rem;
        --fs-lg:   1.2rem;
        --fs-xl:   1.4rem;
        --fs-2xl:  1.85rem;
        --fs-3xl:  2.5rem;
        --fs-4xl:  3.4rem;
        --space-lg:  2.25rem;
        --space-xl:  3.5rem;
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: var(--fs-base);
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(at 0% 0%, hsla(253,16%,7%,1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225,39%,30%,0.2) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339,49%,30%,0.1) 0, transparent 50%);
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulseGlow {
    0%   { box-shadow: 0 0 0 0   rgba(56, 189, 248, 0.4); }
    70%  { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
    100% { box-shadow: 0 0 0 0   rgba(56, 189, 248, 0); }
}

.fade-in  { animation: fadeInUp 0.6s ease-out both; will-change: transform, opacity; }
.delay-1  { animation-delay: 0.15s; }
.delay-2  { animation-delay: 0.3s; }

/* ── Layout ─────────────────────────────────────────────────── */
.container {
    width: 90%;
    max-width: 1280px;
    margin: 0 auto;
    padding: var(--space-lg) 0;
}

@media (min-width: 1440px) {
    .container { max-width: 1480px; }
}

@media (min-width: 1920px) {
    .container { max-width: 1700px; }
}

/* ── Navbar ─────────────────────────────────────────────────── */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-xl);
}

.navbar-brand {
    font-size: var(--fs-xl);
    font-weight: 800;
    letter-spacing: -0.5px;
}

.navbar-brand span { color: var(--accent-blue); }

/* ── Cards ──────────────────────────────────────────────────── */
.glass-card,
.form-wrapper,
.module-card {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
}

.module-card {
    text-align: center;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.module-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 4px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-indigo));
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s ease;
}

.module-card:hover { transform: translateY(-10px); box-shadow: var(--shadow-xl); }
.module-card:hover::before { transform: scaleX(1); }

/* ── Index grid ─────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-lg);
    margin-top: var(--space-xl);
}

@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

/* ── Form grid ──────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.input-group {
    display: flex;
    flex-direction: column;
    margin-bottom: var(--space-sm);
}

.input-group.full-width { grid-column: 1 / -1; }

.input-group label {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

input, select {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.9rem 1rem;
    border-radius: 0.75rem;
    transition: var(--transition);
    font-size: var(--fs-base);
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
    color-scheme: dark;
    -webkit-text-fill-color: var(--text-primary);
    box-sizing: border-box;
    min-width: 0;
}

/* Autofill: fuerza fondo oscuro en Chrome, Safari, iOS */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px #0f172a inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    caret-color: var(--text-primary);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

/* ── Subject list ───────────────────────────────────────────── */
.subject-list { display: grid; gap: 1rem; margin-top: 1rem; }

.subject-item {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.subject-item:hover { border-color: var(--accent-indigo); background: rgba(30, 41, 59, 0.8); }
.subject-item.selected { border-color: var(--accent-blue); background: rgba(56, 189, 248, 0.05); }

.subject-info { display: flex; align-items: center; gap: 1rem; }
.subject-info h4 { font-size: var(--fs-lg); }
.subject-info p  { font-size: var(--fs-xs); color: var(--text-secondary); }

.subject-controls { display: flex; gap: 1rem; align-items: center; }

/* ── Checkbox ───────────────────────────────────────────────── */
.custom-checkbox {
    appearance: none;
    width: 24px; height: 24px;
    border: 2px solid var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
}
.custom-checkbox:checked { background-color: var(--accent-blue); border-color: var(--accent-blue); }
.custom-checkbox:checked::after {
    content: '✓';
    position: absolute;
    color: #000;
    font-weight: bold;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
}

.modality-select {
    padding: 0.5rem;
    border-radius: 0.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: var(--fs-sm);
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    padding: 0.9rem 1.8rem;
    border-radius: 0.75rem;
    border: none;
    font-weight: 700;
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-family: inherit;
}

@media (min-width: 1080px) {
    .btn { padding: 1rem 2rem; }
}

.btn-primary { background: var(--accent-blue); color: #000; }
.btn-primary:hover { background: #7dd3fc; transform: scale(1.03); }

.btn-outline {
    background: var(--accent-danger);
    border: 1px solid var(--accent-danger);
}

.btn-inscripciones { background: transparent; border: 1px solid; }

.modal-overlay,
.glass-card,
.form-wrapper {
    transform: translate3d(0,0,0);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-danger);
    border: 1px solid var(--accent-danger);
}

.btn-correct {
    background: var(--accent-success);
    border: 1px solid var(--accent-success);
}

.btn-block { width: 100%; margin-top: 1.5rem; }

/* ── Tables ─────────────────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    font-size: var(--fs-sm);
}

th, td { padding: 1rem; border-bottom: 1px solid var(--border-color); }

@media (min-width: 1080px) {
    th, td { padding: 1.1rem 1.25rem; font-size: var(--fs-base); }
}

tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: var(--fs-xs);
    text-transform: uppercase;
}

.badge-presencial { color: var(--accent-blue); }
.badge-virtual    { color: var(--accent-success); }
.badge-libre      { color: var(--accent-warning); }

/* ── Visibility helpers ─────────────────────────────────────── */
.hidden       { display: none !important; }
.modal-hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    overscroll-behavior: contain;
    transform: translateZ(0);
    isolation: isolate;
}

.modal-overlay .glass-card {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: #1e293b !important;
    transform: translateY(10px);
    will-change: transform, opacity;
    transition: transform 0.18s ease-out, opacity 0.18s ease-out;
    opacity: 0;
    overscroll-behavior: contain;
}

.modal-overlay.active .glass-card {
    transform: translateY(0);
    opacity: 1;
    overscroll-behavior: contain;
}

#modalHistorial .glass-card,
#modalNotas .glass-card,
#successModal .glass-card,
#modalAlerta .glass-card {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: #1e293b !important;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
    overscroll-behavior: contain;
}

/* ── Toasts ─────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 20px; right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(5px);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    border-left: 4px solid var(--accent-blue);
    box-shadow: var(--shadow-xl);
    transform: translateX(150%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: var(--fs-sm);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.show { transform: translateX(0); }

.toast-success { border-left-color: var(--accent-success); }
.toast-warning { border-left-color: var(--accent-warning); }
.toast-danger  { border-left-color: var(--accent-danger); }

/* ── Select options ─────────────────────────────────────────── */
select option {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-weight: 500;
    padding: 10px;
}

/* ── Filtros ────────────────────────────────────────────────── */
.filtro-elegante {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.8rem;
    border-radius: 0.5rem;
    width: 100%;
    transition: var(--transition);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--fs-sm);
}

.filtro-elegante:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

input[type="text"].filtro-elegante { cursor: text; }

#modalGestorNotas div[style*="overflow-y: auto"] {
    transform: translateZ(0);
    will-change: transform;
}

/* ────────────────────────────────────────────────────────────── */
/* MOBILE (≤768px)                                               */
/* ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {

    /* Mostrar bloqueo en mobile (solo existe en admin.html) */
    .mobile-block { display: flex; }

    .container { width: 95%; padding: 0.75rem 0 2rem; }

    .navbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
        margin-bottom: 1.5rem;
        padding: 0.75rem 0;
    }

    .navbar-brand { font-size: 1.15rem; }

    .navbar > div:last-child { font-size: 0.8rem; }

    .glass-card,
    .form-wrapper,
    .module-card {
        padding: 1.25rem;
        border-radius: 1rem;
    }

    /* Index: cards apiladas */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin-top: 1.5rem;
    }

    /* Form: una columna */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .input-group.full-width { grid-column: 1; }

    /* Evita scroll horizontal */
    body { overflow-x: hidden; }
    .container { overflow-x: hidden; }
    .form-wrapper { max-width: 100%; overflow-x: hidden; }
    .form-grid { max-width: 100%; }

    /* Form en mobile */
    .form-wrapper { padding: 1.5rem 1.1rem; }

    .form-grid.glass-card {
        padding: 1.1rem;
        border-radius: 0.85rem;
        gap: 0.25rem;
    }

    .input-group { margin-bottom: 0.6rem; }

    .input-group label {
        font-size: 0.72rem;
        margin-bottom: 0.35rem;
    }

    input, select {
        padding: 0.8rem 0.9rem;
        font-size: 1rem;   /* evita zoom automático en iOS (mínimo 16px) */
        border-radius: 0.65rem;
    }
    #dashboardSection header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem;
    }

    #dashboardSection header > div:last-child {
        width: 100%;
        display: flex;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    #dashboardSection header .btn { width: 100%; text-align: center; }

    /* Tabla más compacta */
    table { font-size: 0.78rem; }
    th, td { padding: 0.55rem 0.45rem; }

    /* Overflow en tablas */
    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #seccionDiaria  { overflow-x: auto; }
    #seccionDiaria table { min-width: 560px; }
    #seccionPlanilla { overflow-x: auto; }

    /* Modales full-width */
    .modal-overlay > .glass-card,
    .modal-overlay > div {
        width: 95% !important;
        max-width: 100% !important;
        padding: 1.25rem !important;
        border-radius: 1rem !important;
        margin: 0 auto;
        overscroll-behavior: contain;
    }

    #modalAsistencia .glass-card,
    #modalHistorial .glass-card,
    #modalNotas .glass-card {
        max-height: 88vh !important;
        overflow-y: auto !important;
    }

    #modalNotas div[style*="overflow-x: auto"] { font-size: 0.75rem; }
    #modalNotas th, #modalNotas td { padding: 0.45rem 0.3rem; }

    .btn-block { margin-top: 1rem; }

    /* Toasts full-width */
    .toast-container { top: 10px; right: 10px; left: 10px; }
    .toast { font-size: 0.8rem; padding: 0.7rem 0.9rem; }

    /* Subject items apilados */
    .subject-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .subject-controls {
        width: 100%;
        justify-content: flex-end;
    }

    /* Modal éxito */
    #successModal .glass-card { padding: 1.75rem 1.25rem !important; }
    #claveGenerada { font-size: 1.8rem !important; letter-spacing: 4px !important; }

    /* Grids inline a 1 col */
    #modalPadron div[style*="grid-template-columns: 2fr"] {
        grid-template-columns: 1fr !important;
    }

    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Glass card headers stacked */
    .glass-card > div[style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .glass-card > div[style*="justify-content: space-between"] > div[style*="gap: 1rem"] {
        width: 100%;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.5rem !important;
    }

    #filtroCondicion { width: 100%; }

    #selectorAcademicoSection {
        align-items: flex-start !important;
        padding: 1rem 0;
        min-height: unset !important;
    }

    /* Buttons inside tables */
    #tablaMaterias .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.72rem;
        white-space: nowrap;
    }

    /* Index header text */
    header h1 { font-size: 2rem !important; }
}

/* ── Muy pequeño (≤400px) ───────────────────────────────────── */
@media (max-width: 400px) {
    .navbar-brand { font-size: 0.95rem; }
    h2 { font-size: 1.2rem; }
    .btn { padding: 0.7rem 0.9rem; font-size: 0.8rem; }
    header h1 { font-size: 1.6rem !important; }
}

/* ── Tablet (769px – 1024px) ───────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-grid { grid-template-columns: 1fr 1fr; }
    .form-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Mobile block: oculto en desktop, visible en mobile (solo admin) ── */
.mobile-block {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-base);
    z-index: 99999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
    gap: 1rem;
}
.mobile-block .icon { font-size: 4rem; }
.mobile-block h2 { color: var(--accent-blue); font-size: 1.4rem; margin: 0; }
.mobile-block p  { color: var(--text-secondary); font-size: 0.95rem; max-width: 300px; line-height: 1.6; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }

::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
    border-radius: 100px;
}

::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.3);
    border: 2px solid rgba(15, 23, 42, 1);
    border-radius: 100px;
    transition: var(--transition);
}

::-webkit-scrollbar-thumb:hover  { background: rgba(56, 189, 248, 0.6); }
::-webkit-scrollbar-thumb:active { background: rgba(56, 189, 248, 0.9); }

html {
    scrollbar-width: thin;
    scrollbar-color: rgba(56, 189, 248, 0.3) rgba(15, 23, 42, 0.6);
}