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

/* ── VARIABLES ── */
:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-glow: rgba(16,185,129,.18);
    --bg: #0f172a;
    --card: #1e293b;
    --card2: #243044;
    --border: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --label: #cbd5e1;
    --input-bg: #0f172a;
    --sidebar-w: 260px;
    --topbar-h: 60px;
    --radius: 12px;
    --shadow: 0 8px 32px rgba(0,0,0,.45);
}

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

html, body { height: 100%; }

body {
    font-family: 'Lexend', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ── LOGIN ── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

.orb {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
}
.orb-1 {
    width: 500px; height: 500px;
    background: radial-gradient(circle, var(--primary-glow) 0%, transparent 70%);
    top: -150px; left: -150px;
}
.orb-2 {
    width: 360px; height: 360px;
    background: radial-gradient(circle, rgba(16,185,129,.08) 0%, transparent 70%);
    bottom: -80px; right: -80px;
}

.login-card {
    background: var(--card);
    padding: 2.5rem;
    border-radius: 18px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 420px;
    border: 1px solid var(--border);
    position: relative;
    z-index: 1;
    animation: slideUp .4s cubic-bezier(.16,1,.3,1);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.login-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    margin-bottom: 2rem;
}

.school-badge {
    width: 58px; height: 58px;
    background: linear-gradient(135deg, #059669, #10b981);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    margin-bottom: .4rem;
    box-shadow: 0 8px 20px rgba(16,185,129,.35);
}

.school-name  { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.school-subtitle { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }

.login-divider { height: 1px; background: var(--border); margin-bottom: 1.75rem; opacity: .6; }

.form-group { margin-bottom: 1.2rem; }
.form-group label { display: block; margin-bottom: .4rem; font-size: .82rem; color: var(--label); font-weight: 500; }

.input-wrapper { position: relative; }
.input-icon {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: var(--muted);
    pointer-events: none;
}

.input-wrapper input {
    width: 100%;
    padding: .72rem 1rem .72rem 2.4rem;
    border: 1.5px solid var(--border);
    border-radius: 9px;
    background: var(--input-bg);
    color: var(--text);
    font-family: inherit;
    font-size: .9rem;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.input-wrapper input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.input-wrapper input::placeholder { color: var(--muted); opacity: .55; }

.toggle-pass {
    position: absolute;
    right: 10px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    color: var(--muted); padding: 4px;
    display: flex; align-items: center;
}
.toggle-pass svg { width: 18px; height: 18px; }
.toggle-pass:hover { color: var(--primary); }

#btnIngresar {
    width: 100%; padding: .82rem;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff; border: none; border-radius: 9px;
    font-family: inherit; font-size: .95rem; font-weight: 600;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: background .2s, transform .15s, box-shadow .2s;
    position: relative;
}
#btnIngresar:hover:not(:disabled) {
    background: linear-gradient(135deg, #059669, #047857);
    box-shadow: 0 6px 20px rgba(16,185,129,.4);
    transform: translateY(-1px);
}
#btnIngresar:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.btn-spinner {
    display: none;
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
#btnIngresar.loading .btn-spinner { display: block; }
#btnIngresar.loading #btnTexto { opacity: 0; position: absolute; }

@keyframes spin { to { transform: rotate(360deg); } }

#error-msg {
    color: #fca5a5; background: #450a0a;
    padding: 10px 14px; border-radius: 8px;
    font-size: .82rem; display: none;
    margin-top: 14px; text-align: center;
    border: 1px solid #7f1d1d;
    animation: shake .35s ease;
}
@keyframes shake {
    0%,100% { transform: translateX(0); }
    25%      { transform: translateX(-6px); }
    75%      { transform: translateX(6px); }
}

.captcha-container {
    margin: 1.5rem 0;
    display: flex;
    justify-content: center;
}

/* ── DASHBOARD LAYOUT ── */
.dashboard-body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* TOPNAV */
.topnav {
    position: sticky; top: 0; z-index: 200;
    background: #0b1120;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    height: 64px;
    flex-shrink: 0;
}

.topnav-brand {
    display: flex; align-items: center; gap: .65rem;
    text-decoration: none;
    flex-shrink: 0;
}
.brand-badge {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, #059669, #10b981);
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem; color: #fff;
    flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name  { font-size: .88rem; font-weight: 700; color: var(--text); }
.brand-sub   { font-size: .62rem; color: var(--muted); }

/* Separador flex */
.topnav-spacer { flex: 1; }

.topnav-docente {
    display: flex; align-items: center; gap: .65rem;
    flex: 1;
    justify-content: center;
}
.topnav-avatar {
    width: 36px; height: 36px;
    border-radius: 50%; object-fit: cover;
    border: 2px solid var(--primary);
    flex-shrink: 0;
}
.topnav-docente-info {
    display: flex; flex-direction: column; line-height: 1.2;
}
.topnav-nombre { font-size: .88rem; font-weight: 600; color: var(--text); }
.topnav-email  { font-size: .7rem;  color: var(--muted); }

.topnav-logout {
    display: inline-flex; align-items: center; gap: .45rem;
    background: none; border: 1px solid var(--border);
    color: var(--muted); border-radius: 8px;
    padding: .4rem .85rem; font-family: inherit;
    font-size: .8rem; font-weight: 500; cursor: pointer;
    transition: background .2s, color .2s, border-color .2s;
    flex-shrink: 0; white-space: nowrap;
}
.topnav-logout svg { width: 16px; height: 16px; }
.topnav-logout:hover { background: rgba(239,68,68,.1); color: #f87171; border-color: #f87171; }

/* Selector de período */
.periodo-wrapper {
    display: flex; align-items: center; gap: .45rem;
    flex-shrink: 0;
}
.periodo-label {
    font-size: .7rem; font-weight: 600;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: .5px; white-space: nowrap;
}
.periodo-select {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: .35rem .65rem;
    font-family: inherit; font-size: .82rem;
    cursor: pointer; outline: none;
    transition: border-color .2s;
    max-width: 200px;
}
.periodo-select:focus { border-color: var(--primary); }

/* MAIN */
.main-content {
    flex: 1;
    overflow-y: auto;
}

/* SECTIONS */
.content-section { display: none; padding: 1.75rem; }
.content-section.active { display: block; }

.section-header { margin-bottom: 1.5rem; }
.section-title { font-size: 1.4rem; font-weight: 700; margin-bottom: .35rem; }
.section-desc  { font-size: .85rem; color: var(--muted); }

.section-header-row {
    display: flex; align-items: center; gap: 1rem;
    margin-bottom: .35rem;
}
.section-header-row .section-title { margin-bottom: 0; }

.btn-back {
    display: inline-flex; align-items: center; gap: .4rem;
    background: none; border: 1px solid var(--border);
    color: var(--muted); border-radius: 8px;
    padding: .4rem .85rem; font-family: inherit;
    font-size: .8rem; font-weight: 500; cursor: pointer;
    transition: background .2s, color .2s, border-color .2s;
    white-space: nowrap; flex-shrink: 0;
}
.btn-back svg { width: 16px; height: 16px; }
.btn-back:hover { background: rgba(16,185,129,.1); color: var(--primary); border-color: var(--primary); }

.inas-summary { margin-top: .75rem; font-size: .82rem; color: var(--muted); }
.inas-summary.inas-ok    { color: #86efac; }
.inas-summary.inas-error { color: #fcd34d; }

/* Banner período anterior — solo lectura */
.banner-readonly {
    display: flex; align-items: center; gap: .5rem;
    background: rgba(217,119,6,.12);
    border: 1px solid rgba(217,119,6,.4);
    color: #fcd34d;
    border-radius: 8px;
    padding: .6rem 1rem;
    font-size: .82rem;
    margin-bottom: .85rem;
}

/* MATERIAS GRID */
.materias-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 1.1rem;
}

.materia-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    cursor: pointer;
    transition: border-color .2s, transform .2s, box-shadow .2s;
    display: flex; flex-direction: column; gap: .75rem;
    position: relative; overflow: hidden;
}
.materia-card::before {
    content: '';
    position: absolute; left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--primary);
    border-radius: 4px 0 0 4px;
}
.materia-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(16,185,129,.15);
}

.card-title { font-size: .95rem; font-weight: 600; line-height: 1.3; padding-left: .5rem; }
.card-carreras { display: flex; flex-wrap: wrap; gap: .3rem; padding-left: .5rem; }
.card-carrera-tag {
    font-size: .68rem; font-weight: 600;
    color: var(--primary); text-transform: uppercase;
    letter-spacing: .4px;
    background: rgba(16,185,129,.1);
    border: 1px solid rgba(16,185,129,.3);
    border-radius: 20px; padding: .15rem .55rem;
}

.card-meta {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: .4rem; padding-left: .5rem;
}
.card-meta-item { display: flex; align-items: center; gap: .35rem; font-size: .75rem; color: var(--muted); }
.card-meta-item svg { width: 13px; height: 13px; flex-shrink: 0; }

.card-bkp {
    display: flex; gap: .5rem;
    padding: .6rem .75rem;
    background: rgba(255,255,255,.04);
    border-radius: 8px; margin-top: .25rem;
}
.bkp-chip {
    flex: 1; text-align: center;
    padding: .3rem .4rem;
    border-radius: 6px; font-size: .72rem; font-weight: 600;
    border: 1px solid;
}
.bkp-ok    { border-color: #16a34a; color: #86efac; background: rgba(22,163,74,.12); }
.bkp-open  { border-color: #d97706; color: #fcd34d; background: rgba(217,119,6,.12); }
.bkp-chip em { font-style: normal; font-size: .85em; opacity: .9; margin-left: .2rem; }

.card-actions { display: flex; gap: .5rem; }
.btn-card {
    flex: 1; padding: .5rem;
    border-radius: 7px; border: 1px solid var(--border);
    background: none; color: var(--muted);
    font-family: inherit; font-size: .75rem; font-weight: 500;
    cursor: pointer; transition: background .2s, color .2s, border-color .2s;
    display: flex; align-items: center; justify-content: center; gap: .35rem;
}
.btn-card svg { width: 14px; height: 14px; }
.btn-card:hover { background: var(--card2); color: var(--text); border-color: var(--primary); }
.btn-card.primary { background: rgba(16,185,129,.12); color: var(--primary); border-color: var(--primary); }
.btn-card.primary:hover { background: var(--primary); color: #fff; }

/* LOADING */
.loading-placeholder {
    grid-column: 1/-1;
    display: flex; flex-direction: column;
    align-items: center; gap: 1rem;
    padding: 3rem;
    color: var(--muted);
}
.spinner-large {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

/* EMPTY STATE */
.empty-state {
    display: flex; flex-direction: column;
    align-items: center; gap: 1rem;
    padding: 4rem 2rem;
    color: var(--muted); text-align: center;
}
.empty-state svg { width: 56px; height: 56px; opacity: .4; }
.empty-state p { font-size: .9rem; max-width: 360px; line-height: 1.6; }

/* CONTROLS BAR */
.cal-controls, .inas-controls {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.25rem;
}
.cal-materia-info {
    font-size: .95rem; font-weight: 600;
    color: var(--primary); margin-bottom: .85rem;
}
.cal-controls-row {
    display: flex; align-items: flex-end; gap: .85rem; flex-wrap: wrap;
}
.select-group { display: flex; flex-direction: column; gap: .35rem; }
.select-group label { font-size: .78rem; color: var(--label); font-weight: 500; }

.select-styled {
    padding: .55rem .85rem;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit; font-size: .85rem;
    outline: none; cursor: pointer;
    transition: border-color .2s;
    min-width: 160px;
}
.select-styled:focus { border-color: var(--primary); }

.bkp-status { margin-top: .75rem; font-size: .78rem; color: var(--muted); display: flex; gap: 1rem; flex-wrap: wrap; }
.inas-summary { margin-top: .75rem; font-size: .82rem; color: var(--muted); }

/* BUTTONS */
.btn-primary {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .58rem 1.1rem;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff; border: none; border-radius: 8px;
    font-family: inherit; font-size: .85rem; font-weight: 600;
    cursor: pointer; transition: opacity .2s, transform .15s;
    white-space: nowrap;
}
.btn-primary svg { width: 16px; height: 16px; }
.btn-primary:hover { opacity: .9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-secondary {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .58rem 1rem;
    background: none; border: 1px solid var(--border);
    color: var(--muted); border-radius: 8px;
    font-family: inherit; font-size: .85rem; font-weight: 500;
    cursor: pointer; transition: background .2s, color .2s;
    white-space: nowrap;
}
.btn-secondary svg { width: 16px; height: 16px; }
.btn-secondary:hover { background: var(--card2); color: var(--text); }

.btn-ghost {
    background: none; border: none; cursor: pointer;
    color: var(--primary); font-family: inherit; font-size: .8rem;
    font-weight: 500; padding: .3rem .6rem;
    border-radius: 6px; transition: background .2s;
}
.btn-ghost:hover { background: rgba(16,185,129,.08); }

/* TABLE */
.table-wrapper {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.data-table {
    width: 100%; border-collapse: collapse; font-size: .83rem;
}
.data-table thead { background: rgba(255,255,255,.04); }
.data-table th {
    padding: .85rem 1rem;
    text-align: left;
    font-size: .72rem; font-weight: 600;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: .7rem 1rem;
    border-bottom: 1px solid rgba(51,65,85,.5);
    color: var(--text);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(255,255,255,.025); }

/* Columnas de parcial */
.col-parcial { text-align: center; }

.col-parcial.active-col { background: rgba(16,185,129,.07); color: var(--primary); }

/* Input de calificación */
.cal-input {
    width: 70px;
    padding: .35rem .5rem;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit; font-size: .85rem;
    text-align: center; outline: none;
    transition: border-color .2s;
    display: block; margin: 0 auto;
}
.cal-input:focus { border-color: var(--primary); }
.cal-input:disabled { opacity: .4; cursor: not-allowed; }

.cal-value { text-align: center; font-weight: 600; }
.cal-value.aprobado { color: var(--primary); }
.cal-value.reprobado { color: #f87171; }
.cal-value.vacio { color: var(--muted); }

/* Fila cuya lista ya fue publicada (Materias.cXbkp = 1) */
.row-locked { background: rgba(255,255,255,.015); }
.row-locked td { color: var(--muted); }

/* Calificación individual ya guardada (Alumnos.cXbkp = 1) */
.cal-locked { opacity: .75; cursor: help; }

.pond-badge {
    display: inline-block;
    font-size: .65rem; font-weight: 600;
    color: var(--primary);
    margin-left: 3px;
}

.th-check { width: 64px; text-align: center; }

.td-check { text-align: center; }

/* Checkbox custom */
.check-absent {
    width: 20px; height: 20px;
    accent-color: var(--primary);
    cursor: pointer;
}

.badge-baja {
    display: inline-block; padding: .2rem .55rem;
    border-radius: 20px; font-size: .68rem; font-weight: 600;
    background: rgba(239,68,68,.15); color: #f87171;
    border: 1px solid rgba(239,68,68,.3);
}

.inas-quick-actions {
    display: flex; align-items: center; gap: .5rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.inas-counter { margin-left: auto; font-size: .78rem; color: var(--muted); }

/* MODAL */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    z-index: 500;
    display: none; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    max-width: 380px; width: 90%;
    text-align: center;
    animation: slideUp .3s cubic-bezier(.16,1,.3,1);
}
.modal-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: .5rem; }
.modal-msg { font-size: .85rem; color: var(--muted); margin-bottom: 1.5rem; line-height: 1.6; }
.modal-actions { display: flex; gap: .75rem; }
.btn-modal-cancel {
    flex: 1; padding: .6rem;
    background: none; border: 1px solid var(--border);
    color: var(--muted); border-radius: 8px;
    font-family: inherit; font-size: .88rem; cursor: pointer;
    transition: background .2s;
}
.btn-modal-cancel:hover { background: var(--card2); }
.btn-modal-confirm {
    flex: 1; padding: .6rem;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff; border: none; border-radius: 8px;
    font-family: inherit; font-size: .88rem; font-weight: 600;
    cursor: pointer; transition: opacity .2s;
}
.btn-modal-confirm:hover { opacity: .9; }

/* RESPONSIVE */
@media (max-width: 640px) {
    .topnav-docente-info .topnav-email { display: none; }
    .topnav-logout span { display: none; }
    .topnav-logout { padding: .4rem; border-radius: 50%; }
    .cal-controls-row { flex-direction: column; align-items: stretch; }
    .btn-primary, .btn-secondary { width: 100%; justify-content: center; }
}

/* ── BOTÓN CONTADOR DE FALTAS ── */
.btn-faltas-count {
    background: rgba(239,68,68,.1);
    border: 1px solid rgba(239,68,68,.3);
    color: #f87171;
    border-radius: 6px;
    padding: .2rem .55rem;
    font-family: inherit; font-size: .83rem; font-weight: 600;
    cursor: pointer;
    transition: background .2s, border-color .2s;
    display: inline-flex; align-items: center; gap: .25rem;
}
.btn-faltas-count:hover { background: rgba(239,68,68,.2); border-color: #f87171; }
.faltas-arrow { font-size: .65rem; opacity: .7; }

/* Spinner de número de faltas por sesión */
.falta-num {
    width: 46px;
    margin-top: .3rem;
    padding: .2rem .35rem;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit; font-size: .8rem;
    text-align: center; outline: none;
    transition: border-color .2s;
    display: block;
}
.falta-num:focus { border-color: var(--primary); }

/* ── MODAL DETALLE DE FALTAS ── */
.modal-faltas-box {
    max-width: 560px; width: 95%;
    padding: 0; overflow: hidden; text-align: left;
}
.modal-faltas-header {
    display: flex; align-items: flex-start;
    justify-content: space-between; gap: 1rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.modal-faltas-title {
    display: flex; align-items: flex-start; gap: .75rem;
}
.modal-faltas-title .modal-title { font-size: 1rem; margin-bottom: .2rem; }
.modal-faltas-sub { font-size: .76rem; color: var(--muted); }

.btn-modal-x {
    background: none; border: none; cursor: pointer;
    color: var(--muted); font-size: 1.1rem; line-height: 1;
    padding: .2rem .4rem; border-radius: 6px; flex-shrink: 0;
    transition: background .2s, color .2s;
}
.btn-modal-x:hover { background: rgba(239,68,68,.1); color: #f87171; }

.modal-faltas-content { max-height: 55vh; overflow-y: auto; }
.modal-faltas-content .data-table { font-size: .82rem; }
.faltas-empty { padding: 2rem; text-align: center; color: var(--muted); font-size: .85rem; }

.badge-justificada {
    display: inline-block; padding: .18rem .55rem;
    border-radius: 20px; font-size: .68rem; font-weight: 600;
    background: rgba(16,185,129,.12); color: #86efac;
    border: 1px solid rgba(16,185,129,.3);
}
.badge-falta-chip {
    display: inline-block; padding: .18rem .55rem;
    border-radius: 20px; font-size: .68rem; font-weight: 600;
    background: rgba(239,68,68,.12); color: #f87171;
    border: 1px solid rgba(239,68,68,.3);
}
.btn-justificar { font-size: .78rem; padding: .25rem .6rem; color: #fcd34d; }
.btn-justificar:hover { background: rgba(217,119,6,.12); }

