:root {
    --paper:   #EEF1F4;
    --surface: #FFFFFF;
    --ink:     #1C2430;
    --muted:   #5B6675;
    --line:    #C9D1DB;
    --accent:  #2F5D8A;
    --error:   #A23B2A;
    --notice:  #2F6B4F;
    --period:  #C62828;
    --planned:   #E3F3E0;
    --unplanned: #FBE3E1;
    --part:      #FDF0D2;
    --rule:      #8C97A4;
    --match:     #FFF1A8;
    --radius:  6px;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper:   #161B22;
        --surface: #1F2630;
        --ink:     #E3E8EE;
        --muted:   #9AA5B3;
        --line:    #354050;
        --accent:  #7FA9D6;
        --error:   #E08A7A;
        --notice:  #7FC4A0;
        --period:  #FF6B6B;
        --planned:   #1F3A27;
        --unplanned: #45211F;
        --part:      #463613;
        --rule:      #6A7788;
        --match:     #5C4F0E;
    }
}

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

body {
    margin: 0;
    background: var(--surface);
    color: var(--ink);
    font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1.25rem; }

/* ---- Sign-in ---------------------------------------------------------- */
body.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-panel {
    width: 100%;
    max-width: 22rem;
    border-left: 4px solid var(--accent);
    padding: 0.25rem 0 0.25rem 1.5rem;
}

form { display: grid; gap: 0.35rem; }

label { font-size: 0.9rem; color: var(--muted); margin-top: 0.6rem; }

input[type="text"],
input[type="password"],
input[type="date"],
select {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.6rem 0.7rem;
}

button {
    font: inherit;
    font-weight: 600;
    margin-top: 1.1rem;
    padding: 0.65rem 1rem;
    border: 0;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--surface);
    cursor: pointer;
}

button:hover { filter: brightness(1.08); }

input:focus-visible,
button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.message {
    margin: 0 0 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    background: var(--surface);
    border-left: 3px solid currentColor;
    font-size: 0.95rem;
}
.message--error  { color: var(--error); }
.message--notice { color: var(--notice); }

/* ---- Signed-in pages -------------------------------------------------- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    font-size: 0.95rem;
    position: sticky;      /* stays at the top of the window while the page scrolls */
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 4px rgb(0 0 0 / 0.08);
}

/* Keep anything scrolled to (e.g. today on the planning page) clear of the fixed top bar */
html { scroll-padding-top: 4.5rem; }
.topbar__account { display: flex; align-items: center; gap: 1rem; }
.topbar__user { color: var(--muted); font-size: 0.9rem; }
.topbar form { display: block; }

.button--quiet {
    margin: 0;
    padding: 0.35rem 0.75rem;
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--line);
    font-weight: 500;
}

.content {
    max-width: 60rem;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.empty { color: var(--muted); max-width: 38rem; }

/* ---- Main menu -------------------------------------------------------- */
.menubar,
.submenu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.menubar { display: flex; flex-wrap: wrap; }

.has-sub { position: relative; }

.mainnav a,
.mainnav button {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0.8rem 0.9rem;
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--ink);
    font: inherit;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.mainnav a:hover,
.mainnav button:hover,
.mainnav button[aria-expanded="true"] {
    background: var(--paper);
    filter: none;
}

.mainnav a:focus-visible,
.mainnav button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
}

/* Arrows: down on the top bar, right inside dropdowns */
.menubar > .has-sub > button::after {
    content: "\25BE";
    margin-left: 0.4rem;
    color: var(--muted);
    font-size: 0.85em;
}
.submenu .has-sub > button {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
}
.submenu .has-sub > button::after {
    content: "\25B8";
    color: var(--muted);
}

.submenu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 12rem;
    padding: 0.3rem 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 20px rgb(0 0 0 / 0.14);
}

/* Nested submenus fly out to the right */
.submenu .submenu {
    top: calc(-0.3rem - 1px);
    left: 100%;
}

.submenu a,
.submenu button { padding: 0.55rem 1rem; }

/* Open by click/tap/keyboard... */
.has-sub > button[aria-expanded="true"] + .submenu { display: block; }

/* ...or by hovering with a mouse */
@media (hover: hover) and (pointer: fine) {
    .has-sub:hover > .submenu { display: block; }
}

.menu-empty {
    display: block;
    padding: 0.55rem 1rem;
    color: var(--muted);
    font-style: italic;
    white-space: nowrap;
}

/* Small screens: nested menus open below instead of to the side */
@media (max-width: 40rem) {
    .topbar { padding: 0 0.75rem; }
    .submenu .submenu {
        position: static;
        border: 0;
        box-shadow: none;
        padding-left: 1rem;
    }
}

/* ---- Edit forms ------------------------------------------------------- */
.edit-form { max-width: 26rem; }

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    color: var(--ink);
    font-size: 1rem;
}
.checkbox input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.field-note { margin: 1rem 0 0; color: var(--muted); }

.message p { margin: 0; }
.message p + p { margin-top: 0.35rem; }
.content > .message { max-width: 38rem; }


/* ---- Class form ------------------------------------------------------- */
.colour-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 0.6rem;
}
.colour-field { display: grid; gap: 0.35rem; }
.colour-field label { margin-top: 0; }

input[type="color"] {
    width: 4rem;
    height: 2.5rem;
    padding: 0.15rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
}

.class-preview {
    margin-top: 1.1rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-weight: 600;
}

.field-note--warn { color: var(--error); }

/* ---- Menu extras -------------------------------------------------------- */
.submenu--scroll {
    max-height: 70vh;
    overflow-y: auto;
}

.menu-swatch {
    display: inline-block;
    width: 0.7rem;
    height: 0.7rem;
    margin-right: 0.5rem;
    border-radius: 50%;
    border: 1px solid rgb(0 0 0 / 0.2);
    vertical-align: 0;
}

/* ---- Set Academic Year choices ---------------------------------------- */
.menu-form { display: block; margin: 0; }

.mainnav .menu-choice {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.mainnav .menu-choice[aria-current="true"] { font-weight: 600; }

.menu-tick {
    display: inline-block;
    width: 1rem;
    color: var(--accent);
    font-weight: 700;
}

.topbar__year {
    padding: 0.15rem 0.55rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    font-size: 0.85rem;
    font-weight: 500;
}

/* ---- Timetable form & menu -------------------------------------------- */
.date-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 0.6rem;
}
.date-field { display: grid; gap: 0.35rem; }
.date-field label { margin-top: 0; }

.menu-detail {
    margin-left: 0.6rem;
    color: var(--muted);
    font-size: 0.85em;
}

/* ---- Set Periods grid --------------------------------------------------- */
.tt-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 1rem 2rem;
}
.tt-control { display: grid; gap: 0.35rem; min-width: 12rem; }
.tt-control label { margin-top: 0; }
.tt-control button { margin-top: 0; }

.tt-help { max-width: 44rem; }

.tt-status { min-height: 1.5rem; margin: 0.5rem 0; color: var(--notice); }
.tt-status--error { color: var(--error); }

.tt-wrap { overflow-x: auto; }

.tt-grid {
    width: 100%;
    min-width: 40rem;
    max-width: 60rem;
    border-collapse: collapse;
    table-layout: fixed;
}
.tt-grid th,
.tt-grid td {
    padding: 0;
    border: 1px solid var(--line);
}
.tt-grid thead th {
    padding: 0.4rem 0.5rem;
    background: var(--paper);
    font-weight: 600;
    text-align: left;
}
.tt-grid thead th:first-child { width: 6.5rem; }
.tt-grid tbody th {
    padding: 0.4rem 0.5rem;
    background: var(--paper);
    text-align: right;
    vertical-align: bottom;
    font-weight: 600;
}

.tt-grid .slot {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.15rem;
    width: 100%;
    min-height: 5rem;
    margin: 0;
    padding: 0.5rem;
    border: 0;
    border-radius: 0;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 400;
    text-align: left;
    cursor: pointer;
}
.tt-grid .slot:hover {
    filter: none;
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}
.tt-grid .slot:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
}
.slot-class { font-weight: 600; }
.slot-room { font-size: 0.9em; opacity: 0.85; }
.tt-grid .slot--saving { opacity: 0.55; cursor: progress; }

/* ---- Link styled as a button ------------------------------------------- */
.button-link {
    display: inline-block;
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--surface);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.button-link:hover { filter: brightness(1.08); }
.button-link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.tt-control--action { min-width: 0; margin-left: auto; }

/* ---- Period times ------------------------------------------------------- */
.period-cell {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    min-height: 4.2rem;
}
.period-number {
    color: var(--period);
    font-weight: 700;
}
.period-time {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 400;
    white-space: nowrap;
}

.heading-detail {
    margin-left: 0.5rem;
    color: var(--muted);
    font-weight: 400;
}

.period-times {
    border-collapse: collapse;
    margin-bottom: 0.25rem;
}
.period-times th,
.period-times td {
    padding: 0.35rem 0.75rem 0.35rem 0;
    text-align: left;
}
.period-times thead th {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 500;
}
.period-times tbody th { font-weight: 600; padding-right: 1.5rem; }

input[type="time"] {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.5rem 0.6rem;
}
.period-times-form { max-width: 26rem; }

/* ---- Lessons ------------------------------------------------------------- */
input[type="number"],
textarea {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.6rem 0.7rem;
}
textarea { resize: vertical; line-height: 1.45; }
.input--short { max-width: 8rem; }
.edit-form--wide { max-width: 44rem; }

.menu-divider {
    height: 1px;
    margin: 0.3rem 0;
    background: var(--line);
}

.menu-detail--clip {
    display: inline-block;
    max-width: 22rem;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
}

/* Delete (lessons only) */
.danger-zone {
    max-width: 44rem;
    margin-top: 2.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}
.danger-zone summary { cursor: pointer; color: var(--error); font-weight: 500; }
.danger-zone p { color: var(--muted); }
.danger-zone button { margin-top: 0; }
.button--danger { background: var(--error); }

/* ---- Planning: current week ------------------------------------------- */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.plan-day h3 {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.4rem 0.75rem;
    margin: 1.5rem 0 0.4rem;
    font-size: 1.3rem;
}
.plan-weekblock:first-child .plan-day:first-child h3,
.plan-weekblock:first-child .plan-week-heading { margin-top: 0.25rem; }
.plan-week-heading {
    margin: 2.5rem 0 0;
    padding-bottom: 0.3rem;
    border-bottom: 2px solid var(--ink);
    font-size: 1.45rem;
}
.plan-week-heading + .plan-day h3 { margin-top: 0.75rem; }
.plan-date sup { font-size: 0.6em; line-height: 0; vertical-align: super; }
.plan-today {
    padding: 0.1rem 0.5rem;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--surface);
    font-size: 0.8rem;
    font-weight: 600;
}
.plan-note { color: var(--muted); font-size: 0.85rem; font-weight: 400; }

.plan-table {
    width: 100%;
    min-width: 44rem;
    border-collapse: collapse;
    table-layout: fixed;
}
.plan-col-period { width: 10rem; }
.plan-col-tick   { width: 3.75rem; }

.plan-table th,
.plan-table td {
    padding: 0;
    border: 2px solid var(--rule);
    vertical-align: top;
}
.plan-table thead th {
    padding: 0.3rem 0.5rem;
    background: var(--paper);
    font-size: 0.85rem;
    text-align: left;
}

.plan-period {
    padding: 0.4rem 0.5rem !important;
    background: var(--surface);
    text-align: left;
    font-weight: 400;
}
.plan-p    { display: inline; margin-right: 0.35rem; font-weight: 700; font-size: 1.05rem; }
.plan-class {
    display: inline-block;
    margin: 0.15rem 0;
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    font-weight: 600;
}
.plan-room { display: block; font-weight: 600; }
.plan-free { display: inline; color: var(--muted); font-style: italic; }
.plan-time { display: block; color: var(--muted); font-size: 0.8rem; }

/* Row states: free stays white, timetabled is red until ticked, then green */
.plan-row td:not(.plan-tick-cell)           { background: var(--surface); }
.plan-row--unplanned td:not(.plan-tick-cell) { background: var(--unplanned); }
.plan-row--planned td:not(.plan-tick-cell)   { background: var(--planned); }
.plan-row--part td:not(.plan-tick-cell)      { background: var(--part); }

.plan-table textarea {
    display: block;
    width: 100%;
    min-height: 4.5rem;
    margin: 0;
    padding: 0.5rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    line-height: 1.4;
    resize: vertical;
    overflow: hidden;
}
.plan-table textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.plan-save {
    display: block;
    min-height: 1rem;
    padding: 0 0.5rem 0.25rem;
    color: var(--muted);
    font-size: 0.75rem;
}
.plan-save--error { color: var(--error); font-weight: 600; }

.plan-table .plan-tick-cell {
    border: 0;
    background: transparent;
    text-align: center;
    vertical-align: middle;
}
.plan-table thead .plan-tick-cell { background: transparent; }

.plan-tick {
    width: 2.4rem;
    height: 2.4rem;
    margin: 0;
    padding: 0;
    border: 1px solid #3E6FA8;
    border-radius: 7px;
    background: #7AA6DA;
    color: rgb(255 255 255 / 0.55);
    font-size: 1.3rem;
    line-height: 1;
}
.plan-tick[aria-pressed="true"] {
    background: #2F6B4F;
    border-color: #245440;
    color: #FFFFFF;
}
.plan-tick[aria-pressed="mixed"] {
    background: #D99A1E;
    border-color: #B07A10;
    color: #FFFFFF;
}
.plan-tick:disabled { opacity: 0.6; cursor: progress; }

/* Full-width pages (e.g. Planning) */
.content--wide {
    max-width: none;
    padding-top: 1rem;
}
.content--wide > h1 { margin-bottom: 0.25rem; }
.content--wide .tt-status { min-height: 0; margin: 0 0 0.25rem; }

/* Clicked class: every period box for that class turns yellow */
.plan-period[data-class] { cursor: pointer; }
.plan-period[data-class]:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.plan-period[data-class]:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.plan-table .plan-period--match { background: var(--match); }

/* Planning title row with the Print button on the right */
.plan-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
}
.plan-header h1 { margin: 0; }

/* ---- Planning right-click menu -------------------------------------------- */
.ctx-menu {
    position: fixed;
    z-index: 50;
    min-width: 12rem;
    max-width: min(28rem, 92vw);
    padding: 0.3rem 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 10px 24px rgb(0 0 0 / 0.18);
    font-size: 0.95rem;
}
.ctx-menu--scroll { max-height: 70vh; overflow-y: auto; }

.ctx-menu .ctx-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1.25rem;
    width: 100%;
    margin: 0;
    padding: 0.45rem 0.9rem;
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--ink);
    font: inherit;
    font-weight: 400;
    text-align: left;
    cursor: pointer;
}
.ctx-menu .ctx-item:hover,
.ctx-menu .ctx-item:focus-visible,
.ctx-menu .ctx-item[aria-expanded="true"] {
    background: var(--paper);
    outline: none;
    filter: none;
}
.ctx-menu .ctx-item:disabled { color: var(--muted); cursor: default; background: none; }
.ctx-item--sub::after { content: "\25B8"; color: var(--muted); }
.ctx-hint { color: var(--muted); font-size: 0.8em; white-space: nowrap; }
.ctx-divider { height: 1px; margin: 0.3rem 0; background: var(--line); }
.ctx-empty { padding: 0.45rem 0.9rem; color: var(--muted); font-style: italic; }

/* ---- Homework buttons and dialogs (planning page) ------------------------- */
.hwk-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.35rem;
}
.hwk-btns:empty { display: none; }

.plan-table .hwk-btn {
    margin: 0;
    padding: 0.15rem 0.45rem;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: var(--surface);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
}
.plan-table .hwk-btn--check { border-color: #B26A00; color: #8A5300; }
.plan-table .hwk-btn:hover { filter: brightness(0.95); }

/* Flashing once a second (half a second on, half off) */
.plan-table .hwk-flash-set   { animation: hwk-flash-set 1s steps(1, end) infinite; }
.plan-table .hwk-flash-check { animation: hwk-flash-check 1s steps(1, end) infinite; }
@keyframes hwk-flash-set {
    0%   { background: var(--accent); color: #FFFFFF; }
    50%  { background: var(--surface); color: var(--accent); }
}
@keyframes hwk-flash-check {
    0%   { background: #FFB300; color: #1C2430; border-color: #B26A00; }
    50%  { background: var(--surface); color: #8A5300; }
}

.hwk-dialog {
    width: min(34rem, 92vw);
    padding: 1.25rem 1.4rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 16px 40px rgb(0 0 0 / 0.25);
}
.hwk-dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.hwk-dialog h2 { margin: 0 0 0.5rem; font-size: 1.2rem; }
.hwk-dialog label { display: block; margin: 0.8rem 0 0.3rem; }
.hwk-dialog textarea,
.hwk-dialog select { width: 100%; }
.hwk-dialog .field-note { margin: 0; }
.hwk-dialog .message { margin: 0.75rem 0 0; }
.message--warning { color: #8A5300; }

.hwk-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 1.1rem;
}
.hwk-actions button { margin-top: 0; }
.hwk-spacer { flex: 1; }

.hwk-item {
    margin-top: 0.9rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.hwk-item--done { opacity: 0.7; }
.hwk-item button { margin-top: 0.6rem; }
.hwk-meta { margin: 0; color: var(--muted); font-size: 0.9rem; }
.hwk-notes { margin: 0.4rem 0 0; white-space: pre-wrap; }

/* ---- Student days off on the planning page -------------------------------- */
.plan-closed {
    max-width: none;
    margin: 0 0 0.4rem;
    padding: 0.4rem 0.75rem;
    border-left: 4px solid #B26A00;
    background: #FFECB3;
    color: #1C2430;
    font-weight: 600;
}
.plan-closed-reason { display: block; color: var(--muted); font-size: 0.8rem; font-style: italic; }
.plan-warning { margin: 0 0 0.4rem; }

/* ---- Students ------------------------------------------------------------ */
.import-heading { margin-top: 2rem; font-size: 1.2rem; }
.import-table { border-collapse: collapse; min-width: 36rem; }
.import-table th,
.import-table td {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
.import-table thead th { background: var(--paper); font-size: 0.9rem; }
.import-row--new td      { background: var(--planned); }
.import-row--existing td { background: #E6EEF8; }
.import-row--error td    { background: var(--unplanned); }
.import-row--already td  { color: var(--muted); }
.import-confirm { margin-top: 0.5rem; }

/* Grouped form sections (homework days, a student's classes) */
.hw-days {
    margin: 1.1rem 0 0;
    padding: 0.4rem 0.9rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.hw-days legend { padding: 0 0.35rem; color: var(--muted); font-size: 0.9rem; }
.hw-days .checkbox { margin-top: 0.5rem; }

/* Chk hwk: student list */
.hwk-dialog--wide { width: min(40rem, 94vw); }
.hwk-students-wrap { max-height: 50vh; overflow-y: auto; margin-top: 0.6rem; border: 1px solid var(--line); border-radius: var(--radius); }
.hwk-students { width: 100%; border-collapse: collapse; }
.hwk-students th,
.hwk-students td { padding: 0.3rem 0.6rem; border-bottom: 1px solid var(--line); text-align: left; }
.hwk-students thead th { position: sticky; top: 0; background: var(--paper); font-size: 0.85rem; }
.hwk-students th:not(:first-child),
.hwk-students .hwk-tick { width: 5.5rem; text-align: center; }
.hwk-students input[type="checkbox"] { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); cursor: pointer; }
.hwk-students tbody tr:hover { background: var(--paper); }
.hwk-dialog--wide .hwk-item--done { opacity: 1; background: var(--paper); }

/* Today button in the top bar */
.today-link {
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--surface);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.today-link:hover { filter: brightness(1.08); }
.today-link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- Homework list ---------------------------------------------------------- */
.hwl-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem 1.25rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
}
.hwl-field { display: grid; gap: 0.3rem; }
.hwl-field label { margin: 0; }
.hwl-field--button { display: flex; align-items: center; gap: 0.75rem; }
.hwl-field--button button { margin: 0; }
.hwl-group { margin: 0; padding: 0.25rem 0.6rem 0.4rem; border: 1px solid var(--line); border-radius: var(--radius); }
.hwl-group legend { padding: 0 0.3rem; color: var(--muted); font-size: 0.85rem; }
.hwl-option { display: inline-flex; align-items: center; gap: 0.3rem; margin-right: 0.8rem; color: var(--ink); font-size: 0.95rem; }
.hwl-reset { color: var(--accent); }
.hwl-summary { margin: 1rem 0; color: var(--muted); }

.hwl-card {
    margin: 0 0 0.8rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--line);
    border-left: 4px solid var(--notice);
    border-radius: var(--radius);
}
.hwl-card--open { border-left-color: #B26A00; }
.hwl-head { display: flex; flex-wrap: wrap; gap: 0.3rem 1.2rem; align-items: baseline; }
.hwl-state { margin-left: auto; color: var(--muted); font-size: 0.9rem; }
.hwl-notes { margin: 0.4rem 0 0.5rem; white-space: pre-wrap; }
.hwl-group-line { margin: 0.3rem 0 0; }
.hwl-badge {
    display: inline-block;
    margin-right: 0.4rem;
    padding: 0.05rem 0.45rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}
.hwl-badge--done    { background: var(--planned); }
.hwl-badge--notdone { background: var(--unplanned); }
.hwl-badge--notin   { background: #E6EEF8; }

.hwl-actions { display: inline-flex; gap: 0.4rem; }
.hwl-actions button { margin: 0; padding: 0.3rem 0.8rem; font-size: 0.9rem; }
.hwl-state + .hwl-actions { margin-left: 0.5rem; }

/* Excellent homework */
.hwl-badge--excellent { background: #FFE08A; }
.hwk-students .hwk-tick--excellent input { accent-color: #B8860B; }

/* Class name on the planning sheet is a link to the class list */
a.plan-class { text-decoration: none; }
a.plan-class:hover { text-decoration: underline; }

/* Class list */
.cls-table { border-collapse: collapse; width: 100%; max-width: 70rem; }
.cls-table th, .cls-table td { padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.cls-table thead th { background: var(--paper); font-size: 0.9rem; }
.cls-conc { font-weight: 600; color: #8A5300; white-space: pre-wrap; }
.cls-notes { color: var(--muted); white-space: pre-wrap; }
.cls-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.cls-header h1 { margin: 0; }
.cls-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }
@media (max-width: 40rem) {
    .cls-table thead { display: none; }
    .cls-table tr { display: block; padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
    .cls-table td { display: block; border: 0; padding: 0.1rem 0; }
    .cls-table td[data-label]:not(:empty)::before { content: attr(data-label) ": "; color: var(--muted); font-size: 0.85rem; }
}

/* Find student */
.search-form { display: flex; gap: 0.5rem; max-width: 32rem; margin-bottom: 1rem; }
.search-form input[type="search"] {
    flex: 1; font: inherit; color: var(--ink); background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 0.7rem;
}
.search-form button { margin: 0; }

/* Class list: tick boxes, removing, comparing with a list */
.cls-table .cls-tick { width: 2.5rem; text-align: center; }
.cls-table .cls-tick input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); cursor: pointer; }
.cls-table + button, .tt-wrap + button { margin-top: 0.75rem; }
.cmp { margin: 1rem 0 2rem; padding: 0.75rem 1rem 1rem; border: 2px solid var(--accent); border-radius: var(--radius); }
.cmp h2 { margin-top: 0; }
.cmp h3 { margin: 1.25rem 0 0.4rem; font-size: 1.05rem; }
.cmp-problems { color: var(--error); }
.cmp-box { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.cmp-box summary { cursor: pointer; font-weight: 600; color: var(--accent); }
@media (max-width: 40rem) {
    .cls-table td.cls-tick { display: inline-block; width: auto; padding-right: 0.5rem; }
    .cls-table td.cls-tick + td { display: inline-block; }
}

.import-row--withdraw td  { background: #FDEBD3; }
.import-row--withdrawn td { color: var(--muted); }

/* ---- Seating template and seating plan ---------------------------------------- */
.st-pickers { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.st-pickers label { margin: 0; }
.st-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1.5rem;
    margin: 0.75rem 0 0.25rem; padding: 0.6rem 0.8rem;
    border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper);
}
.st-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.st-group--end { margin-left: auto; }
.st-toolbar button, .st-toolbar .button-link { margin: 0; padding: 0.4rem 0.8rem; font-size: 0.9rem; }
.st-toolbar .is-on { background: var(--accent); color: var(--surface); }
.st-toolbar .is-dirty { box-shadow: 0 0 0 3px #FFB300; }
.st-label { color: var(--muted); font-size: 0.85rem; }
.st-num { width: 3.6rem; font: inherit; padding: 0.3rem 0.4rem; border: 1px solid var(--line); border-radius: var(--radius); text-align: center; }
.st-toolbar .st-step { padding: 0.3rem 0.6rem; }
.st-linkbtn {
    display: inline-block; padding: 0.4rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius);
    color: var(--accent); font-size: 0.9rem; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.st-help { margin: 0.25rem 0; max-width: 60rem; }
.st .tt-status { margin: 0.25rem 0; }

.st-body { display: flex; gap: 1rem; align-items: flex-start; }
.st-list {
    flex: 0 0 13rem; max-height: 80vh; overflow-y: auto;
    padding: 0.5rem; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--paper);
}
.st-list h2 { margin: 0 0 0.4rem; font-size: 1rem; }
.st-count { color: var(--muted); font-weight: 400; }
.st-chips { display: flex; flex-direction: column; gap: 0.3rem; }
.st-chip {
    display: flex; justify-content: space-between; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.55rem; border: 1px solid var(--line); border-radius: 4px;
    background: var(--surface); cursor: grab; user-select: none; touch-action: none; font-size: 0.9rem;
}
.st-chip-ec, .desk-ec {
    padding: 0 0.25em; border-radius: 3px; background: #FFB300; color: #1C2430;
    font-size: 0.7rem; font-weight: 700; line-height: 1.3;
}
.st-area { flex: 1; min-width: 0; }

.st-stage { display: inline-flex; flex-direction: column; align-items: stretch; gap: 4px; }
.st-stage--bottom { flex-direction: column-reverse; }
.st-stage--left  { flex-direction: row; }
.st-stage--right { flex-direction: row-reverse; }
.st-front {
    display: flex; align-items: center; justify-content: center; min-height: 28px; min-width: 28px;
    background: #2F5D8A; color: #FFFFFF; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; border-radius: 4px;
}
.st-stage--left .st-front, .st-stage--right .st-front { writing-mode: vertical-rl; }
.st-stage--left .st-front { transform: rotate(180deg); }

.st-grid {
    position: relative; touch-action: none; user-select: none;
    border: 1px solid var(--line); background-color: var(--surface);
    background-image:
        linear-gradient(to right, rgb(140 151 164 / 0.25) 1px, transparent 1px),
        linear-gradient(to bottom, rgb(140 151 164 / 0.25) 1px, transparent 1px);
    background-size: var(--cell) var(--cell);
}
.st-grid.is-adding { cursor: crosshair; }

.desk { position: absolute; padding: calc(var(--cell) * 0.04); box-sizing: border-box; }   /* % padding would follow the grid's width */
.st--template .desk { cursor: grab; }
.desk-body {
    position: relative; width: 100%; height: 100%; box-sizing: border-box;
    border: 2px solid #8C97A4; border-radius: 4px; background: #F7F9FB;
}
.desk--teacher .desk-body { background: #E6EEF8; border-color: #2F5D8A; }
.desk.is-selected .desk-body { outline: 3px solid var(--accent); outline-offset: 1px; }
.desk.is-target .desk-body { background: var(--planned); border-color: var(--notice); }
.desk.is-outside .desk-body { border-color: var(--error); background: var(--unplanned); }

/* Monitor bar at the back, writing area in front of it, EC badge in a back corner */
.desk-monitor { position: absolute; background: #3C4654; border-radius: 2px; }
.desk-area { position: absolute; overflow: hidden; }
.desk-ec { position: absolute; display: flex; align-items: center; justify-content: center; padding: 0; }
.desk-r0   .desk-monitor { top: 6%;    left: 24%; width: 52%;  height: 12%; }
.desk-r0   .desk-area    { top: 26%;   left: 4%;  right: 4%;   bottom: 4%; }
.desk-r0   .desk-ec      { top: 4%;    left: 3%;  width: 18%;  height: 16%; }
.desk-r90  .desk-monitor { right: 6%;  top: 24%;  height: 52%; width: 12%; }
.desk-r90  .desk-area    { right: 26%; top: 4%;   bottom: 4%;  left: 4%; }
.desk-r90  .desk-ec      { right: 3%;  top: 3%;   width: 18%;  height: 16%; }
.desk-r180 .desk-monitor { bottom: 6%; left: 24%; width: 52%;  height: 12%; }
.desk-r180 .desk-area    { bottom: 26%; left: 4%; right: 4%;   top: 4%; }
.desk-r180 .desk-ec      { bottom: 4%; right: 3%; width: 18%;  height: 16%; }
.desk-r270 .desk-monitor { left: 6%;   top: 24%;  height: 52%; width: 12%; }
.desk-r270 .desk-area    { left: 26%;  top: 4%;   bottom: 4%;  right: 4%; }
.desk-r270 .desk-ec      { left: 3%;   bottom: 3%; width: 18%; height: 16%; }

.seat-name {
    position: absolute; display: flex; align-items: center; justify-content: center; box-sizing: border-box;
    text-align: center; line-height: 1.05; font-weight: 600; color: #1C2430;
    overflow-wrap: normal; word-break: keep-all; transform-origin: center;
}
.desk--teacher .seat-name { color: #2F5D8A; font-style: italic; }
.seat-name.is-student { cursor: grab; touch-action: none; }

.st-ghost { position: fixed; z-index: 60; pointer-events: none; opacity: 0.85; box-shadow: 0 6px 16px rgb(0 0 0 / 0.2); }
.st-ghost--desk { position: absolute; border: 2px dashed var(--accent); background: rgb(47 93 138 / 0.15); box-shadow: none; }
.st-ghost--desk.is-bad { border-color: var(--error); background: rgb(162 59 42 / 0.15); }

.st-ec-list { margin-top: 1rem; color: var(--muted); font-size: 0.8rem; max-width: 70rem; }

@media (max-width: 40rem) {
    .st-body { flex-direction: column; }
    .st-list { flex-basis: auto; width: 100%; max-height: 30vh; }
    .st-group--end { margin-left: 0; }
}

/* Room name on the planning sheet opens the seating plan */
a.plan-room { color: inherit; text-decoration: none; width: fit-content; max-width: 100%; }   /* clickable on the text only */
a.plan-room:hover { text-decoration: underline; }

/* Seated names: first name over surname, each line sized separately */
.seat-name--split { flex-direction: column; }
.sn-line { display: block; white-space: nowrap; line-height: 1.1; }

/* Seating template: grow or shrink the room on any side */
.st-size { gap: 0.35rem 0.6rem; }
.st-edge { display: inline-flex; align-items: center; gap: 0.2rem; padding-left: 0.4rem; border-left: 1px solid var(--line); }

/* Homework counts on the class list and the student record */
.cls-table .cls-num { text-align: center; white-space: nowrap; }
.cls-table .cls-num--bad { color: var(--error); font-weight: 600; }
.hw-record { max-width: 40rem; margin: 0 0 1.5rem; }
.hw-record h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }

/* A student's homework marks (student_hwk.php) and Admin > Homework Marks (hwk_marks.php) */
.muted { color: var(--muted); }
.shw-section { margin: 1.25rem 0 1.75rem; }
.shw-section h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
.shw-table .shw-date { white-space: nowrap; }
.shw-table .shw-notes { min-width: 16rem; }
.shw-mark { display: inline-block; padding: 0.05rem 0.45rem; border-radius: var(--radius); font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.shw-mark--excellent { background: #E3F1E6; color: #24663A; }
.shw-mark--notdone { background: #F7E3DF; color: var(--error); }
.shw-mark--notin { background: #ECEEF1; color: var(--muted); }
.cls-table .cls-num--bad a { color: inherit; }
.hm-class { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
.st-check { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0 0 0 0.4rem; font-size: 0.95rem; color: var(--ink); cursor: pointer; }

/* Sign-in-again dialog (relogin.js) */
.relogin-dialog { max-width: 24rem; }
.relogin-form { display: grid; gap: 0.35rem; }
.relogin-form label { margin-top: 0.4rem; }
.relogin-form input { width: 100%; box-sizing: border-box; }
