:root {
    --ink: #15202b;
    --navy: #1e334d;
    --navy-2: #2a4668;
    --paper: #f7f4ee;
    --card: #fffcf7;
    --line: #e4ddd2;
    --gold: #9c7a32;
    --gold-soft: #d8c39a;
    --text: #2c3038;
    --muted: #6d675f;
    --success: #2d6a4f;
    --warn: #9a6b12;
    --danger: #8e3a3a;
    --info: #2a5f73;
    --shadow: 0 10px 30px rgba(21, 32, 43, 0.08);
    --radius: 14px;
    --sidebar: 260px;
    --font: "Source Sans 3", "Segoe UI", sans-serif;
    --serif: "Libre Baskerville", Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--font);
    color: var(--text);
    background: var(--paper);
    line-height: 1.5;
}
a { color: var(--navy-2); }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; color: var(--ink); margin: 0 0 0.6rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.mb-0 { margin-bottom: 0; }
.mt { margin-top: 1.25rem; }
.lead { font-size: 1.05rem; color: var(--muted); max-width: 48rem; }
code, .error-detail {
    background: #efe8dc;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    overflow: auto;
    font-size: 0.9rem;
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(circle at top right, rgba(156, 122, 50, 0.18), transparent 32%),
        linear-gradient(160deg, #1e334d 0%, #15202b 55%, #2a4668 100%);
}
.auth-card {
    width: min(420px, 100%);
    background: var(--card);
    padding: 2rem 1.75rem;
    border-radius: 18px;
    box-shadow: var(--shadow);
}
.brand-kicker {
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-size: 0.72rem;
    color: var(--gold);
    margin-bottom: 0.35rem;
}
.auth-card .brand-kicker { text-align: center; }
.auth-logo {
    height: 72px;
    width: auto;
    display: block;
    margin: 0 auto 1rem;
}
.auth-card h1 { font-size: 1.45rem; line-height: 1.25; text-align: center; }
.auth-lead { text-align: center; }
.auth-alt-action { margin-top: 0.35rem; }

.password-field {
    position: relative;
    display: block;
}
.password-field input { padding-right: 2.8rem; }
.password-toggle {
    position: absolute;
    right: 0.3rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2.25rem;
    height: 2.25rem;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border-radius: 8px;
    padding: 0;
}
.password-toggle:hover,
.password-toggle:focus-visible { color: var(--navy); outline: none; }
.password-toggle .icon-hide { display: none; }
.password-toggle.is-visible .icon-show { display: none; }
.password-toggle.is-visible .icon-hide { display: block; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar);
    background: var(--ink);
    color: #f3eee4;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.brand-logo {
    height: 52px;
    width: auto;
    max-width: 178px;
    display: block;
    flex: 1;
    object-fit: contain;
    object-position: left center;
}
.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--gold);
    color: #fff;
    font-family: var(--serif);
    font-weight: 700;
}
.sidebar-brand strong { display: block; }
.sidebar-brand small { color: var(--gold-soft); }
.sidebar-close { display: none; margin-left: auto; color: #fff; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.3rem; }
.sidebar-nav a {
    color: #efe8dc;
    text-decoration: none;
    padding: 0.65rem 0.8rem;
    border-radius: 10px;
}
.sidebar-nav a:hover,
.sidebar-nav a.is-active {
    background: rgba(255,255,255,0.08);
}
.sidebar-nav a.is-active {
    background: var(--navy-2);
}
.sidebar-foot {
    margin-top: auto;
    font-size: 0.8rem;
    color: #b7b1a6;
}
.app-main { flex: 1; min-width: 0; }
.topbar {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.9rem 1.4rem;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 1.15rem; margin: 0; }
.topbar-user { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.topbar-name { font-weight: 600; }
.menu-btn { display: none; }
.page { padding: 1.4rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 0;
    border-radius: 10px;
    padding: 0.55rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.9rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:disabled,
.btn-primary[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}
.btn-primary:hover { background: var(--navy-2); }
.btn-secondary { background: #ece5d8; color: var(--ink); }
.btn-ghost { background: transparent; color: var(--navy); }
.btn-danger { background: var(--danger); color: #fff; }
.icon-btn {
    border: 0;
    background: transparent;
    font-size: 1.4rem;
    cursor: pointer;
    color: inherit;
}

.stack { display: grid; gap: 1rem; }
.stack label, .form-grid label { display: grid; gap: 0.35rem; font-weight: 600; }
input, select, textarea {
    font: inherit;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    width: 100%;
}
input:disabled, select:disabled, textarea:disabled {
    background: #f4f1ea;
    color: var(--muted);
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    background: var(--card);
    padding: 1.2rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.form-narrow { max-width: 720px; }
.js-grade-entry { margin-bottom: 1.1rem; }
.panel > .section-title:first-child { margin-top: 0; }
.full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: end; }
.field-error { color: var(--danger); font-weight: 500; }
.field-hint { font-weight: 500; color: var(--muted); font-size: 0.85rem; }
.inline-form { display: inline; }
.inline-form.compact { display: block; }
.form-grid [hidden] { display: none !important; }
.check-option {
    display: flex !important;
    flex-direction: row;
    align-items: flex-start;
    gap: 0.55rem;
    font-weight: 500;
}
.check-option input[type="checkbox"] {
    width: auto;
    flex: none;
    margin-top: 0.25rem;
}
.check-option .field-hint { display: block; margin-top: 0.15rem; }
.choice-head {
    margin: 0 0 0.45rem;
}
.choice-list {
    max-height: 260px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.35rem 0.75rem;
    background: #fff;
    display: grid;
    gap: 0;
}
.form-grid label.choice-row,
.choice-list label.choice-row {
    display: flex !important;
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    font-weight: 500;
    padding: 0.4rem 0;
    margin: 0;
}
.form-grid label.choice-row input[type="checkbox"],
.choice-list label.choice-row input[type="checkbox"] {
    width: 1.05rem;
    height: 1.05rem;
    min-width: 1.05rem;
    flex: 0 0 1.05rem;
    margin: 0;
    padding: 0;
}
.choice-list label.choice-row span {
    flex: 1 1 auto;
    line-height: 1.35;
}
.panel .form-grid {
    background: transparent;
    border: 0;
    padding: 0;
}
.pay-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

.toolbar, .action-row, .filter-bar {
    display: flex;
    gap: 0.7rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 1rem;
}
.toolbar { justify-content: space-between; }
.filter-bar { flex: 1; }
.filter-bar input, .filter-bar select { max-width: 240px; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.9rem;
    margin: 1.2rem 0;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}
.stat-card span { color: var(--muted); display: block; }
.stat-card strong { font-size: 1.7rem; font-family: var(--serif); }

.notice, .panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    margin-bottom: 1.1rem;
}
.notice-warn { border-color: #ead7a3; background: #fff8e8; }
.payment-account { margin-bottom: 1.6rem; }
.payment-account-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.85rem;
    margin-bottom: 0.35rem;
}
.payment-subject {
    font-size: 1.15rem;
    margin: 0;
}
.payment-student { font-weight: 600; color: var(--ink); }
.payment-account-summary { margin-bottom: 0.75rem; }
.payment-tx-list { display: grid; gap: 0.7rem; }
.payment-tx { margin-bottom: 0; }
.payment-tx.is-current { border-color: var(--gold-soft); }
.payment-tx-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.7rem;
}
.payment-tx-meta { margin-top: 0.15rem; }
.payment-tx-actions { margin-top: 0.7rem; }
.payment-account-actions { margin-top: 0.75rem; }
.section-title { font-size: 1.15rem; margin: 1.4rem 0 0.8rem; }
.card-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.8rem; }
.card-link {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
}
.card-link h3 { font-size: 1.05rem; }

.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
}
.data-table th, .data-table td {
    text-align: left;
    padding: 0.8rem 0.9rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    overflow-wrap: break-word;
}
.data-table th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.data-table td.row-actions {
    display: table-cell;
    white-space: nowrap;
}
.data-table td.row-actions a,
.data-table td.row-actions .inline-form {
    display: inline-flex;
    vertical-align: middle;
    margin-right: 0.35rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.15rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 700;
    background: #ece5d8;
    color: var(--ink);
}
.badge-success, .badge-activo, .badge-activa, .badge-inscripto, .badge-pagado, .badge-aprobado { background: #dcefe4; color: var(--success); }
.badge-muted, .badge-inactivo, .badge-anulado { background: #ececec; color: #666; }
.badge-warn, .badge-borrador, .badge-pendiente, .badge-abierta { background: #fff0cc; color: var(--warn); }
.badge-danger, .badge-cerrado, .badge-cerrada, .badge-vencido, .badge-desinscripto, .badge-rechazado { background: #f6dede; color: var(--danger); }
.badge-info, .badge-entregado, .badge-corregido, .badge-en_curso { background: #d7ecf2; color: var(--info); }

.flash-stack { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.alert {
    padding: 0.8rem 1rem;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
}
.alert-success { background: #dcefe4; color: var(--success); }
.alert-error { background: #f6dede; color: var(--danger); }
.alert-info { background: #d7ecf2; color: var(--info); }
.alert-close { border: 0; background: transparent; cursor: pointer; font-size: 1.1rem; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(21,32,43,0.45);
    z-index: 20;
}

@media (max-width: 900px) {
    .menu-btn { display: inline-flex; }
    .sidebar {
        position: fixed;
        z-index: 30;
        transform: translateX(-110%);
        transition: transform 0.2s ease;
    }
    .sidebar.is-open { transform: none; }
    .sidebar-close { display: inline-flex; }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .form-grid, .pay-details { grid-template-columns: 1fr; }
    .grade-item { grid-template-columns: 1fr; }
    .topbar-name { display: none; }
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr {
        border: 1px solid var(--line);
        border-radius: 12px;
        margin-bottom: 0.8rem;
        padding: 0.35rem 0;
    }
    .data-table td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        border-bottom: 0;
    }
    .data-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 600;
        padding-right: 0.5rem;
    }
    .data-table td.row-actions {
        display: flex;
        flex-wrap: wrap;
        white-space: normal;
        justify-content: flex-end;
        align-items: center;
    }
    .data-table td.row-actions::before {
        margin-right: auto;
    }
    .data-table td:not([data-label])::before,
    .data-table td[data-label=""]::before {
        content: none;
    }
    .data-table td.row-actions a,
    .data-table td.row-actions .inline-form {
        margin-right: 0;
    }
    .toolbar,
    .action-row,
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar { justify-content: flex-start; }
    .filter-bar { flex: none; width: 100%; }
    .filter-bar input,
    .filter-bar select,
    .filter-bar .btn,
    .toolbar > .btn,
    .action-row > .btn,
    .action-row > .inline-form,
    .action-row > .inline-form .btn {
        width: 100%;
        max-width: none;
    }
    .toolbar > .row-actions,
    .toolbar > .action-row {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar > .row-actions .btn {
        width: 100%;
        margin-right: 0;
    }
}

html { scroll-behavior: smooth; }
textarea { min-height: 88px; resize: vertical; }
.check { display: flex !important; flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 600; }
.check input { width: auto; }
.subsection { font-size: 1rem; margin: 1.2rem 0 0.6rem; font-family: var(--serif); }
.jump-nav { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.jump-nav a {
    background: #ece5d8;
    color: var(--ink);
    text-decoration: none;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
}
.video-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 1rem; }
.video-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem; }
.video-frame { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; border-radius: 10px; background: #000; }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.progress { height: 8px; background: #ece5d8; border-radius: 99px; overflow: hidden; margin: 0.4rem 0 0.8rem; }
.progress > span { display: block; height: 100%; background: var(--navy); }
.grade-card, .thread {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.9rem;
    margin-bottom: 0.8rem;
    background: #fff;
}
.thread.reply { margin: 0.6rem 0 0 1rem; background: var(--paper); }
.reply-form { margin-top: 0.6rem; }
.compact-form { margin-top: 0.6rem; }
.grade-scheme { display: grid; gap: 1.1rem; }
.grade-kind {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.85rem 1rem 1rem;
    background: #fff;
}
.grade-kind legend { padding: 0 0.25rem; }
.grade-count {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
    max-width: 220px;
    margin: 0.85rem 0 0.6rem;
}
.grade-rows { display: grid; gap: 0.7rem; }
.grade-item {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(110px, 1fr);
    gap: 0.8rem;
}
.grade-item label { display: grid; gap: 0.35rem; font-weight: 600; }
.grade-subtotal, .grade-total { margin: 0.75rem 0 0; }
.grade-total { font-size: 1.08rem; }
.grade-subtotal strong, .grade-total strong { font-family: var(--serif); }
.msg-thread { display: grid; gap: 0.7rem; margin-bottom: 1rem; }
.msg-bubble { max-width: 42rem; padding: 0.75rem 0.9rem; border-radius: 12px; }
.msg-bubble header { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.msg-mine { margin-left: auto; background: #dce6f2; }
.msg-theirs { background: #fff; border: 1px solid var(--line); }
.badge-calificado { background: #dcefe4; color: var(--success); }
.badge-no_entregado { background: #ececec; color: #666; }
.badge-tarde { background: #fff0cc; color: var(--warn); }
.js-receipt-field.is-optional input { opacity: 0.7; }

body.confirm-open { overflow: hidden; }
.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    background: rgba(21, 32, 43, 0.5);
}
.confirm-dialog {
    width: min(420px, 100%);
    background: var(--card);
    border-radius: 16px;
    padding: 1.4rem 1.3rem 1.2rem;
    box-shadow: var(--shadow);
    text-align: center;
}
.confirm-message {
    font-size: 1.05rem;
    color: var(--ink);
    margin: 0 0 1.15rem;
    line-height: 1.45;
}
.confirm-actions {
    display: flex;
    justify-content: center;
    gap: 0.7rem;
    flex-wrap: wrap;
}
.confirm-yes { background: var(--success); color: #fff; min-width: 6.5rem; }
.confirm-yes:hover { filter: brightness(0.95); }
.confirm-no { background: var(--danger); color: #fff; min-width: 6.5rem; }
.confirm-no:hover { filter: brightness(0.95); }
