:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #eef4f8;
    --text: #172033;
    --muted: #667085;
    --line: #d9e2ec;
    --primary: #0b579a;
    --primary-strong: #08467d;
    --accent: #e3eef9;
    --danger: #b42318;
    --warning: #8a4b08;
    --shadow: 0 12px 34px rgba(30, 53, 76, 0.08);
    --radius: 16px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f1722;
    --surface: #182331;
    --surface-soft: #202e3d;
    --text: #edf4f7;
    --muted: #a8b7c7;
    --line: #344558;
    --primary: #72afe5;
    --primary-strong: #9ac9ef;
    --accent: #173653;
    --danger: #ff8a80;
    --warning: #ffd08a;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 80% -10%, var(--accent), transparent 30rem), var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.15rem; height: 1.15rem; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.skip-link { position: fixed; left: 1rem; top: -4rem; z-index: 100; padding: .7rem 1rem; background: var(--surface); border-radius: 8px; }
.skip-link:focus { top: 1rem; }
.topbar { height: 68px; padding: 0 clamp(1rem, 4vw, 3rem); display: flex; align-items: center; justify-content: space-between; background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px); }
.brand { display: inline-flex; align-items: center; gap: .7rem; color: var(--text); font-weight: 750; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 42px; height: 42px; object-fit: cover; border-radius: 10px; box-shadow: var(--shadow); }
.topnav { display: flex; align-items: center; gap: 1.25rem; font-size: .92rem; }
.topnav a { color: var(--text); }
.nav-link { display: inline-flex; align-items: center; gap: .42rem; }
.nav-link .icon { color: var(--primary); }
.user-name { color: var(--muted); border-left: 1px solid var(--line); padding-left: 1.25rem; }
.theme-toggle, .menu-toggle { display: inline-grid; place-items: center; border: 1px solid var(--line); color: var(--text); background: var(--surface); border-radius: 9px; min-width: 38px; height: 38px; cursor: pointer; }
.theme-toggle:hover, .menu-toggle:hover { color: var(--primary); border-color: var(--primary); }
.theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-sun { display: block; }
[data-theme="dark"] .theme-icon-moon { display: none; }
.menu-toggle { display: none; }
.mobile-nav { padding: 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.mobile-nav a { display: flex; padding: .75rem; color: var(--text); }

.page-shell { width: min(1440px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.page-heading, .journal-header, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-heading, .journal-header { margin-bottom: 1.25rem; }
.heading-with-icon { display: flex; align-items: center; gap: 1rem; }
.heading-icon { display: inline-grid; place-items: center; width: 3.2rem; height: 3.2rem; color: var(--primary); background: var(--accent); border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--line)); border-radius: 14px; }
.heading-icon .icon { width: 1.55rem; height: 1.55rem; }
h1, h2, h3 { margin-top: 0; letter-spacing: -.025em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin-bottom: .3rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: .95rem; margin-bottom: .45rem; }
p { line-height: 1.55; }
.muted { color: var(--muted); margin-top: .25rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--primary); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.back-link { display: inline-flex; align-items: center; gap: .35rem; margin-bottom: .8rem; font-size: .9rem; }
.back-link .icon { width: 1rem; height: 1rem; transition: transform .15s ease; }
.back-link:hover .icon { transform: translateX(-2px); }

.messages { display: grid; gap: .5rem; margin-bottom: 1rem; }
.message { padding: .85rem 1rem; border-radius: 10px; background: var(--accent); border: 1px solid var(--line); }
.message-error { color: var(--danger); }
.message-warning { color: var(--warning); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 1rem; }
.class-card, .panel, .metric, .login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.class-card { position: relative; display: block; overflow: hidden; padding: 1.35rem; color: var(--text); transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; }
.class-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: linear-gradient(180deg, var(--primary), color-mix(in srgb, var(--primary) 35%, transparent)); }
.class-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--primary) 55%, var(--line)); box-shadow: 0 16px 38px rgba(11, 87, 154, .14); text-decoration: none; }
.class-card-icon { display: inline-grid; place-items: center; width: 2.7rem; height: 2.7rem; margin-bottom: .85rem; color: var(--primary); background: var(--accent); border-radius: 11px; }
.class-card-icon .icon { width: 1.35rem; height: 1.35rem; }
.class-card-arrow { position: absolute; top: 1.25rem; right: 1.2rem; color: var(--muted); transition: transform .15s ease, color .15s ease; }
.class-card:hover .class-card-arrow { color: var(--primary); transform: translateX(3px); }
.class-card h2 { margin: .6rem 0 .2rem; font-size: 1.35rem; }
.class-card p { margin: 0; color: var(--muted); }
.class-day { color: var(--primary); font-size: .78rem; font-weight: 750; }
.panel { padding: clamp(1rem, 2vw, 1.5rem); margin-top: 1rem; }
.panel-heading { margin-bottom: 1rem; }
.panel-heading h2 { margin-bottom: 0; }
.panel-footnote { text-align: right; margin: 1rem 0 0; }
.empty-state { padding: 2rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-cell { text-align: center; color: var(--muted); padding: 2rem !important; }

.tabs { display: flex; gap: .35rem; overflow-x: auto; padding: .35rem; margin-bottom: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; scrollbar-width: thin; }
.tabs a { display: inline-flex; align-items: center; gap: .42rem; flex: 0 0 auto; padding: .65rem .85rem; border-radius: 9px; color: var(--muted); font-size: .86rem; font-weight: 650; white-space: nowrap; }
.tabs a:hover, .tabs a.active { color: var(--text); background: var(--surface-soft); text-decoration: none; }
.tabs a.active .icon { color: var(--primary); }
.management-tabs { margin-top: -.5rem; }
.badge { display: inline-flex; padding: .28rem .55rem; border-radius: 99px; background: var(--surface-soft); border: 1px solid var(--line); color: var(--muted); font-size: .73rem; font-weight: 700; }
.badge-locked { color: var(--warning); }
.sharepoint-status { color: var(--primary); white-space: nowrap; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin: 1rem 0; }
.metric { position: relative; display: flex; flex-direction: column; min-height: 8.5rem; padding: 1.1rem; color: var(--text); transition: transform .15s ease, border-color .15s ease; }
a.metric:hover { transform: translateY(-2px); border-color: var(--primary); text-decoration: none; }
.metric-icon { display: inline-grid; place-items: center; align-self: flex-end; width: 2.35rem; height: 2.35rem; margin-bottom: .3rem; color: var(--primary) !important; background: var(--accent); border-radius: 10px; font-size: inherit !important; }
.metric-icon .icon { width: 1.2rem; height: 1.2rem; }
.metric strong { font-size: 1.55rem; }
.metric span { color: var(--muted); font-size: .82rem; }
.compact-grid { grid-template-columns: repeat(2, 1fr); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 2rem; }
.detail-grid p { margin: 0; }
.span-two { grid-column: 1 / -1; }
.sensitive { padding: 1rem; background: color-mix(in srgb, var(--warning) 8%, var(--surface)); border-left: 3px solid var(--warning); border-radius: 8px; }

.table-wrap { max-width: 100%; overflow-x: auto; }
.entra-directory-table { margin-top: 1rem; max-height: 32rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .045em; }
th, td { padding: .8rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; align-items: center; gap: .7rem; white-space: nowrap; }
.row-actions form { display: inline; }
.grade { display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; background: var(--accent); font-weight: 800; }
pre { max-width: 34rem; overflow: auto; white-space: pre-wrap; font-size: .75rem; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: .42rem; min-height: 42px; padding: .65rem 1rem; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 700; text-decoration: none; }
.button:hover { text-decoration: none; }
.button-primary { color: white; background: var(--primary); }
[data-theme="dark"] .button-primary { color: #071419; }
.button-primary:hover { background: var(--primary-strong); }
.button-secondary { color: var(--text); background: var(--surface-soft); border-color: var(--line); }
.button-ghost { color: var(--muted); background: transparent; }
.button-danger { color: white; background: var(--danger); }
.button-small { min-height: 34px; padding: .4rem .7rem; font-size: .8rem; }
.button-wide { width: 100%; margin-top: 1.25rem; }
.link-danger { padding: 0; color: var(--danger); background: none; border: 0; cursor: pointer; }

.stack-form { display: grid; gap: 1rem; }
.stack-form > div, .field { display: grid; gap: .35rem; }
.stack-form label, .inline-form label { font-size: .82rem; font-weight: 720; }
.form-control, .stack-form input, .stack-form select, .stack-form textarea { width: 100%; padding: .68rem .75rem; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; outline: 0; }
.form-control:focus, .stack-form input:focus, .stack-form select:focus, .stack-form textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
.stack-form input[type="checkbox"] { width: auto; }
.stack-form select[multiple] { min-height: 12rem; }
.stack-form ul.errorlist { margin: .25rem 0 0; padding-left: 1.1rem; color: var(--danger); font-size: .8rem; }
.bulk-grade-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .75rem; }
.bulk-grade-fields > div { display: grid; gap: .35rem; }
.grade-entry-table { max-width: 48rem; }
.grade-entry-table td:last-child, .grade-entry-table th:last-child { width: 10rem; }
.assignment-details summary { color: var(--primary); cursor: pointer; font-weight: 700; }
.assignment-details ul { margin: .65rem 0 0; padding-left: 1.25rem; }
.form-actions { display: flex !important; flex-direction: row; gap: .5rem !important; margin-top: .5rem; }
.inline-form, .search-form { display: flex; align-items: center; gap: .55rem; }
.inline-form { margin-bottom: 1rem; }
.inline-form .form-control { width: min(26rem, 100%); }
.compact { min-width: 12rem; padding: .45rem .55rem; }
.split-layout { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(0, 1.7fr); gap: 1rem; align-items: start; }
.form-panel { max-width: 760px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }
.setup-list { display: grid; gap: .7rem; padding-left: 1.4rem; }

.login-shell { min-height: calc(100vh - 68px); display: grid; place-items: center; }
.login-card { width: min(430px, 100%); padding: clamp(1.5rem, 6vw, 2.5rem); text-align: center; }
.login-school-logo { width: 112px; height: 112px; margin: 0 auto 1rem; object-fit: cover; border-radius: 22px; box-shadow: var(--shadow); }
.dev-login { margin-top: 1.5rem; text-align: left; color: var(--muted); }
.dev-login .stack-form { margin-top: 1rem; color: var(--text); }

@media (max-width: 900px) {
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .split-layout { grid-template-columns: 1fr; }
    .topnav { display: none; }
    .menu-toggle { display: inline-grid; }
    .page-shell { width: min(100% - 1rem, 1000px); padding-top: 1rem; }
    .bulk-grade-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
    .topbar { height: 60px; padding: 0 .75rem; }
    .brand { font-size: .9rem; }
    .brand-logo { width: 36px; height: 36px; }
    .page-heading, .journal-header, .panel-heading { align-items: flex-start; flex-direction: column; }
    .metric-grid, .compact-grid, .detail-grid { grid-template-columns: 1fr; }
    .span-two { grid-column: auto; }
    .panel { border-radius: 12px; padding: .9rem; }
    th, td { padding: .7rem .55rem; }
    .search-form, .inline-form { width: 100%; align-items: stretch; flex-direction: column; }
    .inline-form .form-control { width: 100%; }
    .form-actions { flex-wrap: wrap; }
    .bulk-grade-fields { grid-template-columns: 1fr; }
}

@media print {
    .topbar, .tabs, .messages, .button, .row-actions, .back-link { display: none !important; }
    body, .page-shell, .panel { background: white; color: black; box-shadow: none; }
    .page-shell { width: 100%; padding: 0; }
    .panel { border: 0; }
}
