* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background: var(--page);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--font-size-md);
    line-height: var(--line-height);
}

button, input, select, textarea { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }

.icon {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-current-width) minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns .2s ease;
}

.button {
    display: inline-flex;
    min-height: var(--button-height);
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: var(--surface-secondary);
    color: var(--text);
    cursor: pointer;
    font-weight: 650;
    box-shadow: var(--button-shadow);
    transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}

.button:hover { background: var(--surface-hover); box-shadow: var(--shadow-xs); }
.button:focus-visible, .icon-button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 1px;
}
.tab:focus-visible,.text-link:focus-visible,.quick-link:focus-visible,.dropdown-item:focus-visible,.auth-switch button:focus-visible {
    border-radius: var(--radius-sm);
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}
.button-primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); box-shadow: none; }
.button-primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.button-danger { border-color: transparent; background: transparent; color: var(--danger); }
.button-danger:hover { background: var(--danger-soft); }
.button-ghost { background: transparent; }
.button-ghost:hover { background: var(--surface-secondary); }
.button-block { width: 100%; }
.button-small { min-height: var(--button-height-sm); padding: 4px 10px; font-size: 13px; }
.button:disabled { transform: none; opacity: .55; cursor: not-allowed; box-shadow: none; }

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.settings-card {
    padding: 24px;
}

.settings-grid > .settings-card:last-child {
    grid-column: 1 / -1;
}

.ai-card { padding: 20px; }

.ai-placeholder { display: grid; min-height: 110px; place-items: center; color: var(--muted); text-align: center; }
.ai-mode { display: grid; justify-items: end; gap: 4px; }

.ai-answer {
    margin-top: 20px;
    padding: 18px;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--surface-muted);
}

.ai-summary p {
    margin: 8px 0 0;
    line-height: 1.65;
}

.ai-insight-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    margin-top: 20px;
}

.ai-insight-grid h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.insight-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding-left: 22px;
    line-height: 1.5;
}

.ai-answer-meta { margin: 20px 0 0; }
.ai-request-error { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.ai-request-error .button { flex: none; }

.integration-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, .8fr);
    gap: 20px;
}

.provider-card {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 18px;
    margin-bottom: 22px;
    padding: 24px;
}

.provider-logo {
    display: grid;
    width: 52px;
    height: 52px;
    place-items: center;
    border-radius: var(--radius-lg);
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 24px;
    font-weight: 800;
}

.provider-content { min-width: 0; }
.provider-content .section-heading { margin-bottom: 18px; }

.provider-details {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.provider-details > div {
    display: grid;
    gap: 4px;
    padding: 12px 14px;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}

.provider-details strong { font-size: 13px; }
.provider-details span { color: var(--muted); font-size: 12px; line-height: 1.45; }
.provider-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.provider-card .card-note { margin: 12px 0 0; }

.setup-card {
    margin-bottom: 20px;
    padding: 22px;
    scroll-margin-top: 20px;
}

.setup-roadmap {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.setup-roadmap li {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
    min-height: 132px;
    padding: 14px;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}

.setup-roadmap li > div { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; }
.setup-roadmap strong { line-height: 1.35; }
.setup-roadmap small { margin: 4px 0 12px; color: var(--muted); line-height: 1.4; }
.setup-roadmap a { margin-top: auto; color: var(--accent); font-size: 12px; font-weight: 700; }

.setup-number {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 800;
}

.setup-roadmap li.done {
    border-color: color-mix(in srgb, var(--success) 45%, var(--border));
    background: var(--success-soft);
}

.setup-roadmap li.done .setup-number {
    background: var(--success);
    color: var(--on-accent);
}

.setup-roadmap li.done .setup-number::before { content: "✓"; }
.setup-roadmap li.done .setup-number { font-size: 0; }
.setup-roadmap li.done .setup-number::before { font-size: 14px; }

.import-progress {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 0 0 20px;
    padding: 0;
    list-style: none;
}

.import-progress li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    color: var(--muted);
    border: 0;
    border-radius: var(--radius-md);
    background: var(--surface);
}

.import-progress li > span {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--surface-muted);
    font-weight: 700;
}

.import-progress li div {
    display: grid;
}

.import-progress li small {
    margin-top: 2px;
}

.import-progress li.active {
    color: var(--text);
    background: var(--primary-soft);
}

.import-progress li.active > span {
    color: var(--on-accent);
    background: var(--accent);
}

.integration-steps {
    display: grid;
    gap: 14px;
    padding-left: 22px;
    line-height: 1.5;
}

.file-input {
    padding: 9px 12px;
}

.file-drop {
    display: grid;
    min-height: 150px;
    place-items: center;
    align-content: center;
    gap: 6px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-muted);
    transition: border-color .2s ease, background .2s ease;
}

.file-drop:hover,
.file-drop.dragging {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.file-drop input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.file-drop-icon {
    display: grid;
    width: 52px;
    height: 52px;
    place-items: center;
    color: var(--on-accent);
    border-radius: var(--radius-lg);
    background: var(--accent);
    font-size: 13px;
    font-weight: 800;
}

.file-drop small {
    color: var(--muted);
}

.import-preview {
    margin-top: 20px;
    padding: 24px;
}

.import-result {
    margin-top: 20px;
    padding: 24px;
}

.compact-summary {
    margin-top: 16px;
}

.fallback-import {
    margin-top: 20px;
    overflow: hidden;
}

.fallback-import > summary {
    padding: 18px 24px;
    cursor: pointer;
    font-weight: 700;
}

.fallback-import > summary:hover {
    background: var(--surface-muted);
}

.fallback-import-body {
    padding: 0 24px 24px;
    border-top: 1px solid var(--border);
}

.fallback-import-body > p {
    color: var(--muted);
}

.fallback-import-body .import-preview,
.fallback-import-body .import-result {
    padding-right: 0;
    padding-left: 0;
}

@media (max-width: 760px) {
    .settings-grid { grid-template-columns: 1fr; }
    .settings-card:last-child { grid-column: auto; }
    .ai-mode { justify-items: start; }
    .ai-insight-grid { grid-template-columns: 1fr; gap: 18px; }
    .ai-request-error { align-items: stretch; flex-direction: column; }
    .integration-layout { grid-template-columns: 1fr; }
    .import-progress { grid-template-columns: 1fr; }
    .provider-details { grid-template-columns: 1fr; }
    .setup-roadmap { grid-template-columns: 1fr 1fr; }
    .workflow-hint { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 560px) {
    .provider-card { grid-template-columns: 1fr; }
    .setup-roadmap { grid-template-columns: 1fr; }
}
.avatar { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 750; }

.mobile-header { display: none; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 226px; gap: 24px; width: 100%; max-width: var(--content-max-width); margin: 0 auto; padding: var(--content-padding-y) var(--content-padding-x) 40px; }
.main-column { min-width: 0; }
.app-shell > .main-column { width: 100%; max-width: var(--content-max-width); margin: 0 auto; padding: var(--content-padding-y) var(--content-padding-x) 40px; }
.gradebook-filters > .button { align-self: end; }
.form-errors { overflow-wrap: anywhere; }
.metric-value { font-variant-numeric: tabular-nums; }
#attendance-body td:nth-child(2) { min-width: 190px; }
#attendance-body td:nth-child(3) { min-width: 220px; }
.analytics-workspace { min-width: 0; width: 100%; max-width: var(--content-max-width); margin: 0 auto; padding: var(--content-padding-y) var(--content-padding-x) 40px; }
.analytics-insight-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 11px; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
h1 { margin: 0; color: var(--text); font-family: var(--font-display); font-size: var(--font-size-title); font-weight: 700; line-height: 1.15; letter-spacing: -.025em; }
h2 { margin: 0; font-size: 16px; font-weight: 720; line-height: 1.35; letter-spacing: -.008em; }
.lead { margin: 7px 0 0; color: var(--muted); font-size: 15px; }

.field-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; font-weight: 650; }
.input, .select {
    width: 100%;
    min-height: var(--control-height);
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    outline: 0;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.input:hover, .select:hover { border-color: color-mix(in srgb, var(--accent) 42%, var(--border)); }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.input::placeholder { color: var(--muted); opacity: .8; }
.input[aria-invalid="true"],.select[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb,var(--danger) 14%,transparent); }
.input:disabled,.select:disabled,textarea:disabled { background: var(--surface-secondary); color: var(--text-tertiary); cursor: not-allowed; opacity: .8; }
input[type="checkbox"],input[type="radio"] { accent-color: var(--primary); }
.select-compact { width: 210px; }
.search-box { position: relative; }
.search-box .icon { position: absolute; top: 10px; left: 11px; width: 19px; height: 19px; color: var(--muted); pointer-events: none; }
.search-box .input { padding-left: 40px; }

.card { border: 0; border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--card-shadow); }
.panel { border: 0; border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--card-shadow); }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.alert { padding: 12px 14px; border: 0; border-radius: var(--radius-md); background: var(--surface-secondary); color: var(--text); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.tab { min-height: 36px; padding: 7px 10px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-weight: 650; }
.tab:hover { color: var(--text); }
.tab.active, .tab[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent); }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; border: 0; border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--popup-shadow); }
.card + .card, .section-block + .section-block { margin-top: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px; }
.card-note { color: var(--muted); font-size: 13px; }

.summary-card { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); margin-bottom: 18px; padding: var(--space-2); }
.group-summary { grid-template-columns: repeat(6,minmax(0,1fr)); }
.metric { min-width: 0; padding: 12px 16px; }
.metric + .metric { border-left: 1px solid var(--divider-subtle); }
.metric-label { display: block; color: var(--muted); font-size: 12px; }
.metric-value { display: block; margin-top: 4px; color: var(--color-blue-900); font-size: 22px; font-weight: 760; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
:root[data-theme="dark"] .metric-value { color: var(--text); }
.metric-value.warning { color: var(--warning); }

.analysis-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 24px; padding: 20px; }
.analysis-card p { margin: 7px 0 0; color: var(--muted); }
.analysis-status { display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: var(--radius-md); background: var(--warning-soft); color: var(--warning); font-weight: 650; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 26px 0 12px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); }
.text-link { border: 0; background: none; color: var(--accent); cursor: pointer; font-weight: 650; }

.empty-state { display: grid; min-height: 112px; place-items: center; padding: 20px; text-align: center; }
.empty-icon { display: grid; width: 48px; height: 48px; margin: 0 auto 14px; place-items: center; border-radius: 50%; background: var(--surface-soft); color: var(--muted); }
.empty-state h3 { margin: 0; font-size: 16px; }
.empty-state p { max-width: 440px; margin: 7px auto 0; color: var(--muted); }
.empty-state .button { margin-top: 16px; }

.utility-column { position: sticky; top: 30px; align-self: start; }
.utility-section { padding: 18px 0; border-bottom: 1px solid var(--border); }
.utility-section:first-child { padding-top: 0; }
.utility-section:last-child { border-bottom: 0; }
.utility-title { margin: 0 0 12px; font-size: 14px; }
.mini-group { padding: 14px; border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--card-shadow); }
.mini-group-name { font-weight: 700; }
.mini-group-meta { margin-top: 3px; color: var(--muted); font-size: 13px; }
.mini-row { display: flex; justify-content: space-between; gap: 16px; margin-top: 12px; }
.mini-row span { color: var(--muted); }
.notice { padding: 12px; border-radius: var(--radius-md); background: var(--warning-soft); color: var(--warning); }
.notice-title { font-weight: 700; }
.notice p { margin: 4px 0 0; font-size: 13px; }
.quick-actions { display: grid; gap: 8px; }
.quick-link { display: flex; align-items: center; gap: 10px; padding: 10px 2px; color: var(--muted); font-weight: 600; }
.quick-link:hover { color: var(--accent); }

.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 220px auto; gap: 12px; align-items: end; margin-bottom: 18px; padding: 0; border: 0; background: transparent; box-shadow: none; }
.students-toolbar { grid-template-columns: minmax(260px,1fr) 180px 170px auto; }
.table-sort { display: inline-flex; align-items: center; gap: 5px; padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; font-weight: inherit; text-align: left; }
.table-sort::after { color: var(--muted); content: "↕"; font-size: 10px; }
.table-sort.active[data-direction="asc"]::after { color: var(--accent); content: "↑"; }
.table-sort.active[data-direction="desc"]::after { color: var(--accent); content: "↓"; }
.clickable-row { cursor: pointer; }
.clickable-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.actions-column { text-align: right; }
.table-pagination { border-top: 1px solid var(--border); }
.risk-status.risk-none { color: var(--muted); }
.risk-status.risk-low { background: var(--success-soft); color: var(--success); }
.risk-status.risk-medium { background: var(--warning-soft); color: var(--warning); }
.risk-status.risk-high,.risk-status.risk-critical { background: var(--danger-soft); color: var(--danger); }
.grade-list { display: flex; min-width: 150px; flex-wrap: wrap; gap: 4px; }
.group-subject-page { min-width: 0; width: 100%; max-width: var(--content-max-width); margin: 0 auto; padding: var(--content-padding-y) var(--content-padding-x); }
.subject-assignment-actions { flex-wrap: wrap; }
.toolbar-two { grid-template-columns: minmax(240px, 1fr) auto; }
.textarea { min-height: 100px; resize: vertical; }
.heading-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.summary-three { grid-template-columns: repeat(3, 1fr); }
.summary-three .metric:nth-child(3) { border-left: 0; border-top: 0; }
.inline-action { display: inline-block; margin-top: 8px; padding: 0; }
.field-hint { margin-top: 5px; color: var(--muted); font-size: 12px; }

.form-more {
    margin-top: 4px;
    border-top: 1px solid var(--border);
}

.form-more summary {
    padding: 14px 0;
    color: var(--accent);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}

.form-more[open] summary { margin-bottom: 4px; }

.workflow-hint {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
    padding: 16px 18px;
    background: var(--surface-secondary);
}

.workflow-hint div { display: grid; gap: 4px; }
.workflow-hint span { color: var(--muted); font-size: 13px; line-height: 1.45; }
.workflow-hint a { flex: 0 0 auto; }

.stack-list { overflow: hidden; }
.stack-row { display: flex; min-height: 70px; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 18px; }
.stack-row + .stack-row { border-top: 1px solid var(--border); }
.stack-title { font-weight: 700; }
a.stack-title:hover { color: var(--accent); }
.stack-meta { margin-top: 3px; color: var(--muted); font-size: 13px; }
.compact-empty { min-height: 150px; }
.muted-list { color: var(--muted); }
.muted-list p { margin: 8px 0; }

.gradebook-workspace { min-width: 0; width: 100%; max-width: 1800px; margin: 0 auto; padding: var(--content-padding-y) var(--content-padding-x) 40px; }
.gradebook-filters { display: grid; grid-template-columns: minmax(170px, 1.2fr) minmax(180px, 1.5fr) minmax(130px, .8fr) minmax(150px, 1fr); gap: 12px; margin-bottom: 18px; padding: 16px; }
.gradebook-card { overflow: hidden; }
.grade-average { display: flex; flex-direction: column; align-items: flex-end; color: var(--muted); font-size: 12px; }
.grade-average strong { color: var(--text); font-size: 22px; }
.gradebook-scroll { max-height: calc(100vh - 320px); overflow: auto; }
.gradebook-table { min-width: 760px; width: 100%; border-collapse: separate; border-spacing: 0; }
.gradebook-table th, .gradebook-table td { min-width: 150px; padding: 12px; border-right: 1px solid var(--divider-subtle); border-bottom: 1px solid var(--divider-subtle); background: var(--surface); text-align: center; }
.gradebook-table th { position: sticky; z-index: 3; top: 0; background: var(--surface-soft); font-size: 13px; text-align: left; }
.gradebook-table th:last-child, .gradebook-table td:last-child { border-right: 0; }
.gradebook-table tr:last-child td { border-bottom: 0; }
.gradebook-table .sticky-student { position: sticky; z-index: 2; left: 0; min-width: 230px; max-width: 230px; text-align: left; }
.gradebook-table th.sticky-student { z-index: 4; background: var(--surface-soft); }
.gradebook-table td.sticky-student { background: var(--surface); }
.gradebook-table .sticky-student strong, .gradebook-table .sticky-student span { display: block; }
.student-number { margin-top: 3px; color: var(--muted); font-size: 12px; }
.assignment-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 500; }
.average-column { min-width: 100px; font-weight: 700; }
.grade-cell { width: 100%; min-height: 38px; padding: 7px; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--surface-soft); cursor: pointer; font-weight: 650; }
.grade-cell:hover { border-color: var(--accent); }
.grade-late { background: var(--warning-soft); color: var(--warning); }
.grade-excused { color: var(--muted); }
.grade-dirty { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.modal-backdrop { position: fixed; z-index: 40; inset: 0; display: grid; place-items: center; padding: 18px; background: var(--overlay); }
.compact-modal { width: min(520px, 100%); max-height: calc(100vh - 36px); overflow-y: auto; border: 0; border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--popup-shadow); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-header p { margin: 3px 0 0; color: var(--muted); }
.compact-modal form { padding: 20px; }
.switch-field { display: flex; min-height: 40px; align-items: center; gap: 9px; white-space: nowrap; }
.switch { position: relative; width: 38px; height: 22px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; }
.switch-track { position: absolute; inset: 0; border-radius: var(--radius-lg); background: var(--border); cursor: pointer; transition: .15s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--on-accent); transition: .15s; box-shadow: var(--button-shadow); }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); }

.table-card { overflow: hidden; border-radius: var(--radius-lg); box-shadow: var(--card-shadow); }
.table-scroll { overflow-x: auto; }
.table-responsive { overflow-x: auto; }
.table-responsive table { width: 100%; border-collapse: collapse; }
.table-responsive th { position: sticky; z-index: 2; top: 0; height: var(--table-header-height); padding: 8px 12px; background: var(--table-header); color: var(--muted); font-size: 11px; letter-spacing: .055em; text-align: left; text-transform: uppercase; }
.table-responsive td { height: var(--table-row-height); padding: 9px 12px; border-top: 1px solid var(--divider-subtle); vertical-align: middle; transition: background-color .15s ease; }
.table-responsive tbody tr:hover td { background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { position: sticky; z-index: 2; top: 0; height: var(--table-header-height); padding: 8px 12px; background: var(--table-header); color: var(--muted); font-size: 11px; letter-spacing: .055em; text-align: left; text-transform: uppercase; }
.data-table td { height: var(--table-row-height); padding: 9px 12px; border-top: 1px solid var(--divider-subtle); vertical-align: middle; transition: background-color .15s ease; }
.data-table tbody tr:hover td { background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
.student-cell { display: flex; align-items: center; gap: 11px; min-width: 210px; }
.student-cell .avatar { width: 34px; height: 34px; font-size: 12px; }
.student-name { font-weight: 650; }
.student-email { color: var(--muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-active { background: var(--success-soft); color: var(--success); }
.status-inactive { background: var(--surface-soft); color: var(--muted); }
.status-success, .status-low { background: var(--success-soft); color: var(--success); }
.status-warning, .status-medium { background: var(--warning-soft); color: var(--warning); }
.status-danger, .status-high, .status-critical { background: var(--danger-soft); color: var(--danger); }
.badge { display: inline-flex; min-height: 24px; align-items: center; padding: 3px 8px; border: 0; border-radius: var(--radius-pill); background: var(--surface-soft); color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.kpi { min-width: 0; padding: 12px 16px; border-right: 0; }
.kpi:last-child { border-right: 0; }
.kpi-label { color: var(--muted); font-size: 11px; font-weight: 650; }
.kpi-value { display: block; margin-top: 3px; font-size: 21px; font-weight: 750; font-variant-numeric: tabular-nums; }
.pagination { display: flex; justify-content: flex-end; gap: 4px; margin-top: 12px; }
.pagination button,.pagination a { display: inline-grid; min-width: 30px; height: 30px; place-items: center; padding: 0 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.pagination .active,.pagination button.active { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; z-index: 20; top: calc(100% + 4px); right: 0; min-width: 190px; padding: 4px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--popup-shadow); }
.dropdown-item { display: flex; width: 100%; min-height: 32px; align-items: center; padding: 6px 9px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); text-align: left; }
.dropdown-item:hover { background: var(--surface-hover); }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--surface-soft); color: var(--text); }
.icon-button.danger:hover { background: var(--danger-soft); color: var(--danger); }

.loading-state, .error-state { padding: 42px 20px; text-align: center; }
.loader { width: 26px; height: 26px; margin: 0 auto 12px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-state { color: var(--danger); }
.error-state p { margin: 0 0 12px; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 20; visibility: hidden; background: var(--overlay); opacity: 0; transition: opacity .2s, visibility .2s; }
.drawer { position: fixed; z-index: 21; top: 0; right: 0; width: min(480px, 100%); height: 100vh; overflow-y: auto; transform: translateX(100%); border-left: 1px solid var(--border); background: var(--surface); transition: transform .22s ease; }
body.drawer-open { overflow: hidden; }
body.drawer-open .drawer-backdrop { visibility: visible; opacity: 1; }
body.drawer-open .drawer { transform: translateX(0); }
.drawer-header { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.drawer-header p { margin: 4px 0 0; color: var(--muted); }
.drawer-body { padding: 22px 24px 32px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field.full { grid-column: 1 / -1; }
.required { color: var(--danger); }
.field-error { display: none; margin-top: 5px; color: var(--danger); font-size: 12px; }
.form-errors { margin-bottom: 16px; padding: 12px; border-radius: var(--radius-md); background: var(--danger-soft); color: var(--danger); }
.save-error { margin: 12px 18px; }
.drawer-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }

.toast-region { position: fixed; z-index: 30; right: 22px; bottom: 22px; }
.toast { min-width: 260px; padding: 12px 14px 12px 18px; border: 0; border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--popup-shadow), inset 3px 0 0 var(--info); font-weight: 600; }
.toast.success { box-shadow: var(--popup-shadow), inset 3px 0 0 var(--success); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
[hidden] { display: none !important; }

.today-workspace { min-width: 0; width: 100%; max-width: var(--content-max-width); margin: 0 auto; padding: var(--content-padding-y) var(--content-padding-x) 40px; }
.start-work-card { margin-bottom: 28px; padding: 24px; background: var(--surface); }
.start-work-copy p { margin: 5px 0 0; color: var(--muted); }
.start-work-controls { display: grid; grid-template-columns: minmax(220px, .75fr) minmax(480px, 1.5fr); align-items: end; gap: 18px; margin-top: 18px; }
.start-work-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.start-work-actions .button { flex: 1 1 150px; justify-content: center; }
.button.disabled, .button[aria-disabled="true"] { opacity: .48; cursor: not-allowed; pointer-events: none; }
.work-steps { display: flex; gap: 0; margin: 18px 0 0; padding: 14px 0 0; border-top: 1px solid var(--border); list-style: none; }
.work-steps li { display: flex; flex: 1; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; font-weight: 650; }
.work-steps li:not(:last-child)::after { height: 1px; flex: 1; margin: 0 14px; background: var(--border); content: ""; }
.work-steps span { display: grid; width: 24px; height: 24px; flex: 0 0 auto; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
.start-work-message { margin: 14px 0 0; color: var(--warning); font-size: 13px; }
.start-work-message a { color: var(--accent); font-weight: 700; }
.today-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.attention-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.risk-card { position: relative; padding: 18px 18px 18px 22px; --signal-color: var(--warning); }
.risk-card::before { position: absolute; inset: 16px auto 16px 0; width: 3px; border-radius: 3px; background: var(--signal-color); content: ""; }
.risk-card.risk-critical,.risk-card.risk-high { --signal-color: var(--danger); }
.risk-card.risk-medium { --signal-color: var(--warning); }
.risk-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.risk-student-name { color: var(--text); font-size: 17px; font-weight: 750; }
.risk-student-name:hover { color: var(--accent); }
.risk-badge { padding: 5px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 750; white-space: nowrap; }
.risk-badge-medium { background: var(--warning-soft); color: var(--warning); }
.risk-badge-high, .risk-badge-critical { background: var(--danger-soft); color: var(--danger); }
.reason-list { display: grid; gap: 7px; margin: 16px 0; padding-left: 20px; line-height: 1.45; }
.risk-meta { color: var(--muted); font-size: 13px; }
.risk-actions { justify-content: flex-start; flex-wrap: wrap; margin-top: 16px; }
.text-button { padding: 5px 2px; border: 0; background: transparent; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; font-weight: 650; }
.text-button:hover { text-decoration: underline; }
.text-button:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.action-feed { overflow: hidden; }
.case-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.case-risk, .case-metrics, .note-card, .plan-card { padding: 22px; }
.risk-score { margin: 16px 0 4px; font-size: 34px; font-weight: 800; }
.plan-list { display: grid; gap: 14px; }
.plan-card h3 { margin: 0; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--page); }
.auth-shell { width: min(440px, 100%); }
.auth-brand { display: block; margin-bottom: 20px; color: var(--text); font-size: 22px; font-weight: 800; text-align: center; }
.auth-card { padding: 28px; box-shadow: var(--card-shadow); }
.auth-card h1 { margin-bottom: 8px; }
.auth-card .lead { margin-bottom: 22px; }
.auth-card form { display: grid; gap: 16px; }
.auth-switch { margin-top: 18px; color: var(--muted); font-size: 13px; text-align: center; }
.auth-switch button { border: 0; background: transparent; color: var(--accent); cursor: pointer; font-weight: 700; }

@media (max-width: 900px) {
    .attention-grid, .today-columns, .case-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .icon-button { width: 44px; height: 44px; }
    .button { min-height: 44px; }
}

/* Teacher gradebook spreadsheet */
.gradebook-filters-primary { grid-template-columns: minmax(220px, 1fr) auto minmax(260px, 1.25fr) minmax(180px, auto); align-items: end; }
.filter-arrow { padding-bottom: 11px; color: var(--muted); font-size: 22px; }
.period-summary { align-self: center; color: var(--muted); font-size: 13px; font-weight: 600; text-align: right; }
.gradebook-key-hint { display: inline-flex; gap: 5px; align-items: center; }
.gradebook-key-hint kbd { min-width: 27px; padding: 4px 7px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: var(--radius-md); background: var(--surface); color: var(--muted); font: 600 11px/1.2 inherit; text-align: center; }
.gradebook-table th.lesson-column, .gradebook-table td.spreadsheet-cell { min-width: 168px; width: 168px; }
.gradebook-table td.spreadsheet-cell { padding: 0; vertical-align: middle; }
.gradebook-scroll:focus-visible, .table-responsive:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.gradebook-table tbody tr:hover td, .gradebook-table tbody tr:hover td.sticky-student { background: color-mix(in srgb, var(--accent) 3%, var(--surface)); }
.lesson-date { display: inline-flex; margin: -3px 0 7px; padding: 4px 8px; border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border)); border-radius: var(--radius-sm); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); color: var(--accent); font: 700 12px/1.2 inherit; cursor: pointer; }
.lesson-date:hover, .lesson-date:focus-visible { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--focus); }
.lesson-title { display: block; min-height: 34px; color: var(--text); font-weight: 650; line-height: 1.3; }
.grid-editor { width: 100%; min-width: 0; border: 0; border-radius: 0; background: transparent; color: var(--text); font: inherit; outline: none; }
.grid-editor:focus { position: relative; z-index: 1; box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 1px var(--accent); }
.grade-editor { height: 38px; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 700; text-align: center; }
.attendance-editor { height: 34px; padding: 4px 24px 4px 7px; color: var(--muted); font-size: 11px; cursor: pointer; }
.attendance-present { background-color: var(--success-soft); color: var(--success); }
.attendance-absent { background-color: var(--danger-soft); color: var(--danger); }
.attendance-late { background-color: var(--warning-soft); color: var(--warning); }
.attendance-excused { background-color: var(--info-soft); color: var(--info); }
.grid-dirty { box-shadow: inset 3px 0 0 var(--accent); }
.grid-invalid { background: var(--danger-soft); box-shadow: inset 0 0 0 2px var(--danger); }
.topic-modal { width: min(520px, calc(100vw - 32px)); }
@media (max-width: 1050px) { .gradebook-filters-primary { grid-template-columns: 1fr auto 1fr; } .gradebook-filters-primary .period-summary { grid-column: 1 / -1; text-align: left; } }
@media (max-width: 720px) { .gradebook-filters-primary { grid-template-columns: 1fr; } .gradebook-filters-primary .filter-arrow { display: none; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* Shared layout: teaching workspace, accessible controls and readable data. */
.app-shell { grid-template-columns: var(--sidebar-current-width) minmax(0, 1fr); }
.app-shell > main, .workspace, .main-column { min-width: 0; }
.page-heading h1 { font-family: var(--font-display); font-size: clamp(26px, 2.4vw, 32px); letter-spacing: -.025em; }
.page-heading .lead { max-width: 680px; margin-top: 8px; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card, .panel, .table-card { border: 1px solid var(--divider); }
.button { min-height: 42px; padding: 9px 15px; }
.button[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
a:focus-visible, button:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.table-responsive { overflow-x: auto; }
table { font-variant-numeric: tabular-nums; }
table th { background: var(--table-header); color: var(--text-secondary); }
table tbody tr:hover { background: var(--surface-hover); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }
@media (max-width: 760px) {
    .app-shell { display: block; }
    .page-heading { flex-wrap: wrap; gap: 16px; }
    .heading-actions { width: 100%; }
    .heading-actions .button { flex: 1 1 auto; }
    .settings-grid, .case-grid { grid-template-columns: 1fr; }
}
