:root {
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --paper: #f3f4f6;
    --panel: #ffffff;
    --brand: #2563eb;
    --brand-dark: #1e40af;
    --accent: #0f766e;
    --warning: #f59e0b;
    --rose: #e11d48;
    --soft: #eff6ff;
    --gradient: linear-gradient(135deg, #0f172a 0%, #1e3a8a 52%, #0f766e 100%);
    --shadow: 0 18px 45px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .09), transparent 34%),
        linear-gradient(180deg, #ffffff 0%, var(--paper) 100%);
}
a { color: inherit; }
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; }
.brand.horizontal { min-width: 240px; }
.brand-mark, .logo-placeholder {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: var(--gradient);
    color: #fff;
    font-weight: 800;
}
.brand span { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.main {
    width: min(1280px, 100%);
    margin: 0 auto;
    min-height: 100vh;
    padding: 24px;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    background: rgba(255,255,255,.88);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 16px 34px rgba(37, 99, 235, .08);
}
.topbar h1 { margin: 0; font-size: 26px; letter-spacing: 0; }
.page-title { flex: 1; }
.user-pill {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border: 1px solid var(--line);
    padding: 9px 12px;
    border-radius: 8px;
}
.back-link {
    border: 0;
    background: #eef2ff;
    color: #1e40af;
    padding: 8px 10px;
}
.user-pill small { color: var(--muted); text-transform: capitalize; }
.user-pill a { color: var(--brand); text-decoration: none; font-weight: 700; }
.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.metric-card, .panel, .auth-card, .login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.metric-card { padding: 18px; position: relative; overflow: hidden; }
.metric-card .bi {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: #f8fafc;
    color: var(--brand);
    margin-bottom: 14px;
}
.metric-card span { color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin-top: 10px; font-size: 32px; }
.metric-card:nth-child(1) { border-top: 4px solid #2563eb; }
.metric-card:nth-child(2) { border-top: 4px solid #0f766e; }
.metric-card:nth-child(3) { border-top: 4px solid #f59e0b; }
.metric-card:nth-child(4) { border-top: 4px solid #7c3aed; }
.dashboard-hero {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
    padding: 22px;
    color: #fff;
    background: var(--gradient);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.dashboard-hero h2 { margin: 5px 0 8px; font-size: 28px; }
.dashboard-hero p { margin: 0; color: #dbeafe; max-width: 820px; }
.parent-brand {
    margin: 0 auto;
    text-align: center;
}
.parent-brand .brand-mark {
    margin: 0 auto;
}
body:has(.parent-brand) .topbar {
    justify-content: center;
    flex-wrap: wrap;
}
body:has(.parent-brand) .dashboard-hero {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
}
body:has(.parent-brand) .dashboard-hero p {
    margin-left: auto;
    margin-right: auto;
}
.eyebrow {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,.16);
    font-size: 12px;
    text-transform: uppercase;
}
.school-emblem {
    display: grid;
    place-items: center;
    width: 84px;
    height: 84px;
    border-radius: 8px;
    background: #fff;
    color: var(--brand-dark);
    font-weight: 800;
    overflow: hidden;
}
.school-emblem img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.menu-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin: 0 0 18px;
}
.menu-tile {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 92px;
    text-decoration: none;
    color: var(--ink);
    border-radius: 8px;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.menu-tile::after {
    display: none;
}
.menu-tile strong { position: relative; z-index: 1; font-size: 15px; }
.menu-tile:hover { transform: translateY(-2px); border-color: #bfdbfe; }
.tile-icon {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: 8px;
    background: #eff6ff;
    color: var(--brand);
    border: 1px solid #dbeafe;
    font-weight: 800;
}
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
.section-bars { display: grid; gap: 15px; }
.bar-label {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
}
.bar-label strong { color: var(--ink); }
.bar-track {
    height: 11px;
    border-radius: 999px;
    background: #eef2f7;
    overflow: hidden;
}
.bar-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #2563eb, #0f766e);
}
.subject-track span {
    background: linear-gradient(90deg, #7c3aed, #f59e0b);
}
.panel { padding: 18px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 15px; font-size: 18px; }
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 15px;
}
.panel-head h2 { margin: 0; }
.grid-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.grid-form.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 6px; color: #344054; font-size: 13px; font-weight: 700; }
.check { display: flex; align-items: center; gap: 8px; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 11px;
    font: inherit;
    background: #fff;
}
textarea { resize: vertical; }
select[multiple] { min-height: 145px; }
button, .button {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    padding: 10px 13px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 700;
}
button.primary, .primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}
button.primary:hover, .primary:hover { background: var(--brand-dark); }
table { width: 100%; border-collapse: collapse; }
th, td {
    border-bottom: 1px solid var(--line);
    padding: 11px 9px;
    text-align: left;
    font-size: 14px;
}
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--soft);
    color: #075985;
    font-size: 12px;
    text-transform: capitalize;
}
.inline { display: inline; }
.actions-row, .table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.collapsible-panel, .collapsible-row {
    display: none;
}
.collapsible-panel.open, .collapsible-row.open {
    display: block;
}
tr.collapsible-row.open {
    display: table-row;
}
.school-edit-row td {
    background: #f8fafc;
    border-bottom: 1px solid #bfdbfe;
}
.school-edit-row form {
    padding: 6px 0;
}
.school-edit-row .actions-row {
    align-self: end;
}
.score-box {
    min-width: 0;
}
.score-sheet {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}
.score-card {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(0, 2.2fr);
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}
.score-card h3 {
    margin: 0;
    font-size: 15px;
}
.score-inputs {
    display: grid;
    grid-template-columns: repeat(4, minmax(64px, 1fr));
    gap: 8px;
}
.score-inputs label {
    font-size: 12px;
}
.score-record-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.score-record-table {
    min-width: 920px;
    border-collapse: separate;
    border-spacing: 0;
}
.score-record-table th,
.score-record-table td {
    min-width: 72px;
    text-align: center;
    border-right: 1px solid var(--line);
    background: #fff;
}
.score-record-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    color: #344054;
}
.score-record-table .sticky-student {
    position: sticky;
    left: 0;
    z-index: 3;
    min-width: 230px;
    text-align: left;
    box-shadow: 8px 0 16px rgba(15, 23, 42, .04);
}
.score-record-table tbody .sticky-student {
    background: #fff;
}
.score-record-table small {
    color: var(--muted);
}
.ltc-box {
    background: #eef2f7;
}
.fixed-save {
    margin-top: 10px;
}
.inline-control {
    display: grid;
    grid-template-columns: minmax(110px, 1fr) auto;
    gap: 6px;
    align-items: center;
}
.inline-control input[type="date"] { min-width: 135px; }
.status-active { background: #ecfdf5; color: #065f46; }
.status-locked, .status-expired { background: #fff7ed; color: #9a3412; }
.status-deactivated { background: #fef2f2; color: #991b1b; }
.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
}
.alert.success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert.error { background: #fff1f2; color: #9f1239; border: 1px solid #fecdd3; }
.auth-shell, .login-layout {
    min-height: 100vh;
    display: grid;
    justify-items: center;
    align-items: center;
    align-content: center;
    gap: 16px;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .22), transparent 45%),
        #eef5ff;
}
.auth-card, .login-panel {
    width: min(470px, 100%);
    padding: 28px;
}
.login-panel-centered {
    display: grid;
    justify-items: center;
    align-items: center;
    text-align: center;
    margin: 0 auto;
}
.login-panel-centered .logo-placeholder,
.login-panel-centered .school-logo {
    margin-left: auto;
    margin-right: auto;
}
.login-form {
    display: grid;
    gap: 13px;
    width: 100%;
    margin-top: 12px;
    justify-items: center;
}
.login-form label {
    text-align: left;
    width: 100%;
}
.login-form button {
    width: min(260px, 100%);
    justify-self: center;
}
.auth-card.wide { width: min(760px, 100%); }
.login-panel h1, .auth-card h1 { margin: 16px 0 5px; }
.login-panel p, .auth-card p { color: var(--muted); }
.login-note {
    margin-top: -2px;
    font-size: 13px;
}
.login-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px 16px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}
.login-footer details {
    position: relative;
}
.login-footer summary {
    color: var(--brand);
    cursor: pointer;
    font-weight: 700;
    list-style: none;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.login-footer summary::-webkit-details-marker {
    display: none;
}
.login-footer a {
    color: var(--brand);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.school-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--line);
}
pre {
    overflow-x: auto;
    background: #101820;
    color: #fff;
    padding: 12px;
    border-radius: 8px;
}
@media (max-width: 900px) {
    .main { padding: 16px; }
    .topbar, .panel-head { align-items: flex-start; flex-direction: column; }
    .brand.horizontal { min-width: 0; }
    .metrics, .grid-form, .grid-form.compact { grid-template-columns: 1fr; }
    .dashboard-hero, .dashboard-grid { grid-template-columns: 1fr; }
    .menu-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span-2 { grid-column: auto; }
    table { display: block; overflow-x: auto; }
    .score-card { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .menu-tiles { grid-template-columns: 1fr; }
    .user-pill { flex-wrap: wrap; }
    .dashboard-hero h2 { font-size: 22px; }
    .score-inputs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .score-inputs input { padding: 9px 6px; text-align: center; }
    .fixed-save {
        position: sticky;
        bottom: 12px;
        width: 100%;
        padding: 14px;
        z-index: 20;
        box-shadow: 0 10px 24px rgba(15,23,42,.22);
    }
}

.app-footer {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    color: var(--muted);
    font-size: 13px;
    padding: 14px 4px 4px;
}
.app-footer a {
    color: var(--brand);
    font-weight: 700;
    text-decoration: none;
}
.support-hero {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 18px;
    align-items: center;
    background: var(--gradient);
    color: #fff;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 18px 34px rgba(37, 99, 235, .22);
}
.support-hero h2 { margin: 0 0 8px; }
.support-hero p { margin: 0 0 16px; color: #e0f2fe; }
.support-mark {
    display: grid;
    place-items: center;
    width: 76px;
    height: 76px;
    border-radius: 8px;
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.34);
    font-weight: 800;
    font-size: 22px;
}

.report-sheet {
    width: 210mm;
    max-width: 100%;
    min-height: 297mm;
    margin: 0 auto 24px;
    background: #fff;
    color: #202020;
    border: 1px solid #8c8c8c;
    padding: 12mm;
    overflow-x: auto;
    page-break-after: always;
}
.report-inline-form {
    display: contents;
}
.report-protected {
    user-select: none;
}
.report-header {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 18px;
    align-items: center;
    text-align: center;
    margin-bottom: 12px;
}
.report-header img, .crest {
    width: 82px;
    height: 82px;
    object-fit: contain;
    border: 0;
}
.report-header h2 { margin: 0; font-size: 30px; letter-spacing: 1px; }
.report-header h3 {
    margin: 8px 0 0;
    background: #545454;
    color: #fff;
    font-size: 34px;
}
.dotted-lines p, .comment-lines p {
    margin: 6px 0;
    border-bottom: 2px dotted #555;
    min-height: 24px;
    font-weight: 700;
}
.dotted-lines span { display: inline-block; min-width: 170px; font-weight: 400; }
.report-sheet h4 { margin: 8px 0 2px; font-size: 18px; }
.report-table th, .report-table td,
.mini-table th, .mini-table td {
    border: 1px solid #555;
    padding: 5px 7px;
    font-size: 13px;
}
.report-table th { color: #222; text-transform: none; }
.lower-score-table th:first-child { font-size: 28px; }
.lower-score-table td:first-child { font-weight: 700; }
.domain-grid {
    display: grid;
    grid-template-columns: 1fr .9fr 1.4fr;
    gap: 24px;
    align-items: start;
    margin-top: 18px;
}
.mini-table {
    width: 100%;
    border-collapse: collapse;
}
.mini-table caption {
    background: #555;
    color: #fff;
    padding: 5px;
    font-weight: 800;
    text-transform: uppercase;
}
.secondary-report {
    padding: 9mm 10mm;
    font-family: "Times New Roman", Times, serif;
    overflow: hidden;
}
.secondary-report .report-header {
    grid-template-columns: 34mm 1fr;
    gap: 7mm;
    align-items: center;
    margin-bottom: 7mm;
}
.secondary-report .report-header img,
.secondary-report .crest {
    width: 31mm;
    height: 31mm;
    border: 0;
}
.secondary-report .report-header h2 {
    font-size: 19pt;
    line-height: 1.05;
    letter-spacing: .5px;
}
.secondary-report .report-header p {
    margin: 2px 0;
    font-size: 8.5pt;
    font-weight: 700;
}
.secondary-report .report-header h3 {
    margin: 4mm 0 0;
    padding: 1mm 0;
    font-size: 23pt;
    line-height: 1;
}
.secondary-summary-grid {
    display: grid;
    grid-template-columns: 75mm 37mm 45mm;
    gap: 9mm;
    align-items: start;
    margin-bottom: 7mm;
}
.secondary-center-boxes {
    display: grid;
    gap: 7mm;
}
.secondary-report .mini-table caption {
    padding: 3px 4px;
    font-size: 8.5pt;
    line-height: 1.1;
    caption-side: top;
}
.secondary-box td,
.secondary-side-table td {
    height: 5.4mm;
}
.secondary-report .mini-table td,
.secondary-report .mini-table th {
    padding: 2px 4px;
    font-size: 8.5pt;
    line-height: 1.1;
}
.secondary-box td:first-child,
.secondary-side-table td:first-child {
    font-weight: 700;
}
.secondary-box td:last-child,
.secondary-side-table td:last-child {
    text-align: center;
    font-weight: 700;
}
.secondary-body-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44mm;
    gap: 7mm;
    align-items: start;
}
.secondary-main-column,
.secondary-side-column {
    min-width: 0;
}
.secondary-side-column {
    display: grid;
    gap: 10mm;
}
.secondary-score-table th {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    height: 35mm;
    white-space: nowrap;
    text-align: center;
    vertical-align: middle;
}
.secondary-score-table th:nth-child(1),
.secondary-score-table th:nth-child(2),
.secondary-score-table th:nth-child(11) {
    writing-mode: horizontal-tb;
    transform: none;
    height: auto;
}
.secondary-score-table th,
.secondary-score-table td {
    padding: 2px 3px;
    font-size: 7.8pt;
    line-height: 1.1;
}
.secondary-score-table th:nth-child(1),
.secondary-score-table td:nth-child(1) { width: 7mm; }
.secondary-score-table th:nth-child(2),
.secondary-score-table td:nth-child(2) { width: 30mm; }
.secondary-score-table th:nth-child(11),
.secondary-score-table td:nth-child(11) { width: 23mm; }
.secondary-score-table td {
    height: 6.2mm;
    text-align: center;
}
.secondary-score-table td:nth-child(2) {
    text-align: left;
    font-weight: 700;
}
.secondary-score-table td:nth-child(11) {
    font-weight: 700;
}
.secondary-comment-list {
    display: grid;
    gap: 6mm;
    margin-top: 20mm;
}
.comment-box {
    display: grid;
    grid-template-columns: 30mm 1fr;
    border: 1px solid #555;
    min-height: 10mm;
}
.comment-box strong {
    display: grid;
    place-items: center;
    background: #555;
    color: #fff;
    text-transform: uppercase;
    text-align: center;
    padding: 4px;
    font-size: 8pt;
    line-height: 1.15;
}
.comment-box span {
    display: grid;
    place-items: center;
    padding: 4px 8px;
    text-align: center;
    font-size: 9pt;
    font-weight: 700;
}
.principal-comment-box span {
    align-items: stretch;
    justify-items: stretch;
    text-transform: uppercase;
}
.principal-comment-box textarea {
    width: 100%;
    height: 100%;
    min-height: 12mm;
    border: 0;
    padding: 0;
    resize: vertical;
    text-align: center;
    text-transform: uppercase;
    font-family: "Times New Roman", Times, serif;
    font-size: 9pt;
    font-weight: 700;
}
.verdict-stamp {
    justify-self: center;
    min-width: 40mm;
    padding: 2mm 7mm;
    border: 2px solid #b91c1c;
    color: #b91c1c;
    text-align: center;
    font-size: 12pt;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}
.verdict-stamp select {
    width: auto;
    min-width: 35mm;
    border: 0;
    background: transparent;
    color: #b91c1c;
    text-align: center;
    text-transform: uppercase;
    font-family: "Times New Roman", Times, serif;
    font-size: 11pt;
    font-weight: 900;
}
.report-inline-save {
    display: flex;
    justify-content: center;
}
@media (max-width: 900px) {
    .report-sheet { padding: 12px; }
    .report-header { grid-template-columns: 64px 1fr; gap: 10px; }
    .report-header img, .crest { width: 60px; height: 60px; }
    .report-header h2 { font-size: 20px; }
    .report-header h3 { font-size: 24px; }
    .domain-grid, .secondary-summary-grid, .secondary-body-grid { grid-template-columns: 1fr; }
    .secondary-report { overflow-x: auto; }
}
@media print {
    @page { size: A4; margin: 0; }
    body { background: #fff; }
    .topbar, .app-footer, .no-print, .alert { display: none !important; }
    .main { margin: 0; padding: 0; }
    .report-sheet {
        width: 210mm;
        height: 297mm;
        min-height: 297mm;
        border: 0;
        margin: 0;
        padding: 12mm;
        box-shadow: none;
        overflow: visible;
        page-break-after: always;
    }
    .secondary-report { padding: 9mm 10mm; overflow: hidden; }
    body.report-protected .report-sheet,
    body.report-protected .panel {
        display: none !important;
    }
    body.report-protected::before {
        content: "Printing and saving report cards is restricted for teacher accounts.";
        display: block;
        padding: 24px;
        font: 16px Arial, Helvetica, sans-serif;
        color: #111827;
    }
}
