/* The app's own layer on top of tokens.css + components.css (both copied from the RU Design System,
   never edited): page frame, shell (topbar / sidebar / footer), data tables, cards, messages.
   Values come from the tokens; the few raw numbers are layout geometry (the 18rem sidebar of the Yii
   app, the 64px topbar) or type sizes the design system's own CSS writes as px. DESIGN.md is the spec. */

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-page-gradient), var(--bg-page);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.7;
    transition: background var(--dur-theme) var(--ease-out), color var(--dur-theme) var(--ease-out);
}

h1,
h2,
h3,
h4 {
    margin: 0 0 var(--s-4);
    color: var(--heading-color);
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: 0; /* the Tone Mark Rule: never negative on Thai */
}

h1 { font-size: 32px; line-height: 40px; }
h2 { font-size: 24px; line-height: 32px; }
h3 { font-size: 19px; line-height: 28px; }

p { margin: 0 0 var(--s-4); }

a {
    color: var(--ru-navy-600);
    text-underline-offset: 3px;
}

/* gold links in the dark theme, except the ones that are buttons: a button carries its own colours (a link-button's
   text was gold in dark whatever its kind) and a page number is not a link in the running text either */
[data-theme="dark"] a:where(:not(.btn, .page-btn)) { color: var(--ru-gold-300); }

/* Focus ring: gold 3px, 3px away, keyboard only (design system rule; components.css carries it for .btn) */
:focus-visible {
    outline: 3px solid var(--ru-gold-500);
    outline-offset: 3px;
}

/* Gold on the light surfaces is 1.8:1 (WCAG 1.4.11 asks 3:1): in the light sidebar and on the drawer toggle the ring is
   navy-600 (10:1); dark keeps gold (it is bright on navy) */
:root:not([data-theme="dark"]) .app-sidebar :focus-visible,
:root:not([data-theme="dark"]) .app-sidebar-toggle:focus-visible { outline-color: var(--ru-navy-600); }
:root:not([data-theme="dark"]) .app-sidebar .field-input:focus { border-color: var(--ru-navy-600); box-shadow: 0 0 0 4px rgba(30, 58, 138, 0.14), var(--shadow-sm); }
/* the design system pulses a focused field for as long as it has focus: motion that answers nothing; the menu search stays still */
.app-sidebar .field-input:focus { animation: none; }

/* the design system's placeholder is --text-disabled: 2.1:1 on white. A placeholder is text people read: 7.5:1 */
.field-input::placeholder, .field-textarea::placeholder { color: var(--text-secondary); opacity: 1; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: var(--s-3);
    left: var(--s-3);
    z-index: 200;
    padding: var(--s-2) var(--s-4);
    border-radius: var(--r-pill);
    background: var(--ru-gold-500);
    color: var(--ru-navy-900);
    font-weight: 600;
    transform: translateY(-200%);
}

.skip-link:focus { transform: none; }

.num,
.mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* ---- shell ------------------------------------------------------------------------------------ */

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 100; /* nothing overlaps the top bar */
    display: flex;
    align-items: center;
    gap: var(--s-4);
    height: 64px;
    padding: 0 var(--s-4);
    background: var(--topnav-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border-subtle);
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s-3);
    color: var(--heading-color);
    font-family: var(--font-display);
    font-weight: 700;
    text-decoration: none;
}

[data-theme="dark"] .app-brand { color: var(--heading-color); }

/* Phokhun logo 1:1.2; clear space of a quarter of its height on every side */
.app-logo {
    display: block;
    height: 40px;
    width: auto;
    margin: 10px;
}

.app-logo--dark { display: none; }
[data-theme="dark"] .app-logo--light { display: none; }
[data-theme="dark"] .app-logo--dark { display: block; }

.app-topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-left: auto;
}

.app-user {
    color: var(--text-secondary);
    font-size: 13px;
}

.app-sidebar-toggle { display: none; }

.app-sidebar {
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    z-index: 90;
    width: 18rem;
    overflow-y: auto;
    padding: var(--s-4) var(--s-3) var(--s-8);
    background: var(--glass-bg-strong);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-right: 1px solid var(--border-subtle);
}

.app-main {
    min-height: calc(100vh - 64px);
    padding: var(--s-6) 20px var(--s-12);
}

.app-shell--with-sidebar .app-main { margin-left: 18rem; }

.app-container {
    max-width: 1320px;
    margin: 0 auto;
}

.app-container--narrow { max-width: 32rem; }

.app-footer {
    padding: var(--s-6) 20px;
    color: var(--text-secondary);
    font-size: 13px;
    border-top: 1px solid var(--border-subtle);
}

.app-shell--with-sidebar .app-footer { margin-left: 18rem; }

/* the drawer's scrim: a real element (app.js closes the drawer on a click on it); desktop never shows it */
.app-scrim { display: none; }

/* the toggle shows a cross while the drawer is open (its label changes with it, app.js) */
.app-sidebar-toggle .icon-close,
.app-sidebar-toggle[aria-expanded="true"] .icon-open { display: none; }
.app-sidebar-toggle[aria-expanded="true"] .icon-close { display: block; }

@media (max-width: 767.98px) {
    .app-sidebar-toggle { display: grid; }
    /* closed = visibility:hidden after the slide-out, so Tab and screen readers never reach the off-screen links */
    .app-sidebar {
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform var(--dur-base) var(--ease-out), visibility 0s linear var(--dur-base);
        box-shadow: var(--shadow-xl);
    }
    body[data-sidebar-open] .app-sidebar {
        transform: none;
        visibility: visible;
        transition: transform var(--dur-base) var(--ease-out), visibility 0s;
    }
    /* the sidebar's own focus (app.js moves it there on opening) is not a control: no ring */
    .app-sidebar:focus { outline: none; }
    /* the glass of the desktop column lets the page's colour blobs through the labels over a drawer */
    [data-theme="dark"] .app-sidebar { background: var(--ru-navy-900); }
    .app-scrim {
        display: block;
        position: fixed;
        inset: 64px 0 0 0;
        z-index: 80;
        background: rgba(10, 26, 63, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--dur-base) var(--ease-out), visibility 0s linear var(--dur-base);
    }
    body[data-sidebar-open] .app-scrim {
        opacity: 1;
        visibility: visible;
        transition: opacity var(--dur-base) var(--ease-out), visibility 0s;
    }
    .app-shell--with-sidebar .app-main,
    .app-shell--with-sidebar .app-footer { margin-left: 0; }
    .app-main { padding: var(--s-5) var(--s-4) var(--s-10); }
    .app-user { display: none; }
}

/* ---- icons ({% icon %}, core/icons.py) -------------------------------------------------------------------------
   Heroicons outline, 1.5 stroke, drawn in the text colour. The size is the place's: 18px in a button (components.css
   `.btn svg`, which wins by specificity), 20px by default here (menus, service lists), 24px in a card badge. */
.icon { width: 20px; height: 20px; flex-shrink: 0; }
.icon-lg { width: 24px; height: 24px; }
/* the close mark of a toast and of a code chip: small, so the round target around it stays 44px / 24px */
.toast-close .icon, .bc-chip button .icon { width: 14px; height: 14px; }

/* ---- sidebar navigation ----------------------------------------------------------------------- */

.nav-section + .nav-section { margin-top: var(--s-4); }

.nav-section-title,
.nav-divider {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    padding: var(--s-2) var(--s-3);
    border: 0;
    background: none;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
}

button.nav-divider { cursor: pointer; border-radius: var(--r-md); }
button.nav-divider:hover { background: var(--surface-3); }

/* while the menu search is on, the groups are shown by the search, not by the person: no chevron to invite a click */
.app-sidebar[data-searching] .nav-divider-chevron { visibility: hidden; }
.app-sidebar[data-searching] button.nav-divider { cursor: default; }
.app-sidebar[data-searching] button.nav-divider:hover { background: transparent; }

.nav-divider-chevron { transition: transform var(--dur-fast) var(--ease-out); }
.nav-divider[aria-expanded="false"] .nav-divider-chevron { transform: rotate(-90deg); }

.nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-list[hidden], .nav-section[hidden], .nav-divider[hidden] { display: none; }

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    min-height: 44px;
    padding: var(--s-2) var(--s-4);
    border-radius: var(--r-pill);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

[data-theme="dark"] .nav-link { color: var(--text-primary); }

.nav-link:hover { background: var(--surface-3); }

/* the page being shown: a tinted fill, heavier type and a leading dot -- state is never colour alone. The royal / gold
   gradient with its halo that the design system gives a tab is the loudest object on a page and is kept for primary
   buttons (Brand Shadow Rule); dark mode takes no gold here either (The Gold Is Earned Rule: one emphasis per page) */
.nav-link { position: relative; text-wrap: pretty; }

.nav-link[aria-current="page"] {
    background: var(--ru-navy-100);
    color: var(--ru-navy-900);
    font-weight: 600;
}

/* the leading icon carries the state's colour (the dot this item used to have sits where the icon is now) */
.nav-link .icon { color: var(--text-secondary); }
.nav-link[aria-current="page"] .icon { color: var(--ru-navy-600); }

[data-theme="dark"] .nav-link[aria-current="page"] {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
}

[data-theme="dark"] .nav-link[aria-current="page"] .icon { color: var(--ru-navy-200); }

/* ---- surfaces --------------------------------------------------------------------------------- */

/* Solid card for numbers and tables (glass lowers contrast); .glass from components.css for summaries */
.surface-card {
    padding: var(--s-6);
    border-radius: var(--r-xl);
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .surface-card { background: var(--bg-page-2); }

.surface-card--lg { padding: var(--s-8); }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--s-6);
}

.stack > * + * { margin-top: var(--s-6); }

.section + .section { margin-top: var(--s-12); }

/* ---- data tables: dashed row rules, no zebra, rows at least 48px, scroll inside the card -------- */

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative; /* the containing block of .sr-only text inside, so it scrolls with the table, not the page */
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

.data-table th,
.data-table td {
    height: 48px;
    padding: var(--s-3) var(--s-4);
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px dashed var(--border-strong);
}

.data-table th {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    border-bottom-style: solid;
}

.data-table tbody tr:last-child td { border-bottom: 0; }

.data-table .num {
    text-align: right;
    white-space: nowrap;
}

/* ---- forms ------------------------------------------------------------------------------------ */

.field-error {
    margin-top: var(--s-2);
    color: var(--danger-fg);
    font-size: 13px;
}

/* a page whose data could not be fetched: a full tinted box (not a bar down one side), the cause and a way out */
.error-state { display: flex; gap: var(--s-4); align-items: flex-start; padding: var(--s-6); border: 1px solid var(--danger-border); border-radius: var(--r-md); background: var(--danger-bg); }
.error-state-icon { color: var(--danger-fg); flex-shrink: 0; }
.error-state-body > p { margin: 0; color: var(--text-secondary); }
.error-state-body > p + p { margin-top: var(--s-2); }
.error-state-body > p:last-child { margin-top: var(--s-4); }
.error-state-title { color: var(--text-primary); font-weight: 600; font-size: 16px; }

/* the note after a sign-in that was refused for want of a cookie: readable, not alarming (the student did nothing wrong) */
.login-expired { margin: 0; padding: var(--s-4); border-radius: var(--r-md); background: var(--warning-bg); color: var(--warning-fg); font-size: 14px; }

/* A table that becomes a list of cards on a phone (class data-table--cards; each figure's td carries data-label).
   A 460px table in a 356px card hid its one button behind a sideways scroll. The roles on the table put back what
   display:block takes away from a screen reader; the sort links stay, as a bar above the cards, at 44px.
   The break is where the table stops fitting, not where the phone ends: with the 288px sidebar beside it (from 768px) the
   card is only the viewport minus ~330px, and the table needs ~504px inside it, so up to 919px it scrolled in its card. */
@media (max-width: 919px) {
    .data-table--cards, .data-table--cards thead, .data-table--cards tbody, .data-table--cards tr { display: block; }
    .data-table--cards thead tr { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--s-2); border-bottom: 1px solid var(--border-strong); }
    .data-table--cards th { display: block; height: auto; padding: 0; border: 0; }
    .data-table--cards th:last-child { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); } /* the button in each card says what it does */
    .data-table--cards th .sa-sort { width: auto; min-height: 44px; padding: 0 var(--s-2); }
    .data-table--cards tbody tr { padding: var(--s-4) 0; border-bottom: 1px dashed var(--border-strong); }
    .data-table--cards tbody tr:last-child { border-bottom: 0; padding-bottom: 0; }
    .data-table--cards td { display: block; height: auto; min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; }
    .data-table--cards td + td { margin-top: var(--s-2); }
    .data-table--cards td:first-child { color: var(--text-primary); font-weight: 600; }
    .data-table--cards td[data-label] { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-4); }
    .data-table--cards td[data-label]::before { content: attr(data-label); color: var(--text-secondary); font-size: 13px; font-weight: 400; }
    .data-table--cards td .btn { display: flex; width: 100%; min-height: 44px; margin-top: var(--s-2); }
}

/* the "no student email yet?" help under the student Google button: quiet, so the sign-in stays the one loud thing */
.login-help { border-top: 1px solid var(--border-subtle); padding-top: var(--s-6); color: var(--text-secondary); font-size: 14px; }
.login-help h2 { margin: 0 0 var(--s-2); font-size: 16px; line-height: 24px; color: var(--text-primary); }
.login-help p { margin: 0; }
.login-help p + p, .login-help ul + p { margin-top: var(--s-4); }
.login-help ul { margin: var(--s-2) 0 0; padding-left: var(--s-6); }
/* the one thing this section is for, on a phone: a 44px target, though it reads as a text link */
.login-help-action a { display: inline-flex; align-items: center; min-height: 44px; }

.field-help {
    margin-top: var(--s-2);
    color: var(--text-secondary);
    font-size: 13px;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2); /* touch targets at least 8px apart */
    margin-top: var(--s-6);
}

/* ---- messages: toasts stacked at the bottom right ---------------------------------------------- */

.toast-stack {
    position: fixed;
    right: var(--s-4);
    bottom: var(--s-4);
    z-index: 150;
    display: grid;
    gap: var(--s-3);
    width: min(24rem, calc(100vw - 2 * var(--s-4)));
}

/* ---- error pages ------------------------------------------------------------------------------ */

.error-page {
    max-width: 40rem;
    margin: var(--s-12) auto;
    text-align: center;
}

.error-code {
    color: var(--ru-gold-800);
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 500;
}

[data-theme="dark"] .error-code { color: var(--ru-gold-300); }

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Touch targets: the design system's pager buttons (40px) and toast close (26px) are below its own 44px rule */
.page-btn { min-width: 44px; height: 44px; }
.toast-close { width: 44px; height: 44px; flex-shrink: 0; }

/* Accessible forms of the design system's checkbox and switch (it draws them as divs toggled by script):
   a real <input type="checkbox"> drawn as .checkbox, a real <button role="switch"> drawn as .toggle. */
.checkbox-row input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.checkbox-row input:checked + .checkbox { background: var(--grad-gold); border-color: transparent; }
.checkbox-row input:checked + .checkbox svg { stroke-dashoffset: 0; }
.checkbox-row input:focus-visible + .checkbox { outline: 3px solid var(--ru-gold-500); outline-offset: 3px; }
.checkbox-row { min-height: 44px; }
/* `.field label` (components.css) outweighs `.checkbox-row`: without this, a row inside a .field is a bold block with its box on its own line */
.field .checkbox-row { display: flex; font-weight: 400; margin-bottom: 0; }

.toggle[aria-checked="true"] { background: var(--grad-gold); border-color: transparent; box-shadow: var(--shadow-gold-soft); }
.toggle[aria-checked="true"]::before { left: calc(100% - 23px); }
.toggle-row label { flex: 1; min-height: 44px; display: flex; align-items: center; cursor: pointer; }

/* tabs driven by app.js: .tab buttons with aria-selected, panels toggled by hidden */
.tab[aria-selected="true"] { background: var(--grad-royal); color: #fff; box-shadow: var(--shadow-navy); }
[data-theme="dark"] .tab[aria-selected="true"] { background: var(--grad-gold); color: var(--ru-navy-900); box-shadow: var(--shadow-gold-soft); }
.tab { min-height: 44px; }
.tab-panel:not([hidden]) { display: block; }

.swatch-row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

/* Contrast (checked with axe-core): the design system draws the floating label and upcoming stepper steps in
   --text-tertiary (#7A8299 on white, 3.83:1), which fails WCAG AA for text and which DESIGN.md itself forbids for
   meaningful text. They use --text-secondary (7.52:1) here. */
.field-float label,
.step { color: var(--text-secondary); }
/* a two-line step label splits evenly ("พิมพ์ใบ / บาร์โค้ด") instead of inside a word ("พิมพ์ใบบาร์ / โค้ด") */
.step { text-wrap: balance; }

/* A table that scrolls sideways is focusable so keyboard users can scroll it (WCAG 2.1.1) */
.table-scroll:focus-visible { outline: 3px solid var(--ru-gold-500); outline-offset: 3px; border-radius: var(--r-md); }

/* Codes, numbers and headers keep one line; the table then grows past a narrow screen and scrolls in its card */
.data-table th,
.data-table td.mono,
.data-table td.num { white-space: nowrap; }
.data-table td { min-width: 8rem; }

.breadcrumb { margin: 0; padding: 0; }

/* Narrow phones: the logo alone carries the brand so the theme switch and sign-out fit at 360px */
@media (max-width: 479.98px) {
    /* hidden from sight only: the link keeps its accessible name */
    .app-brand-name {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
    .app-topbar { gap: var(--s-2); padding: 0 var(--s-3); }
    .app-logo { margin: 10px 4px; }
}

/* sidebar rows with a pin button (shown when the menu is long enough for pins and "recently used"). The 44px button
   floats over the end of the row, so a label keeps the whole width; it takes its own room only where it is always
   there: a pinned item, and a touch screen (no hover to bring it). */
.nav-row {
    position: relative;
    display: flex;
    align-items: center;
}

.nav-row .nav-link { flex: 1; }

.nav-pin {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    border: 0;
    background: var(--pin-bg, var(--surface-3));
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.nav-link[aria-current="page"] + .nav-pin { --pin-bg: var(--ru-navy-100); }
[data-theme="dark"] .nav-link[aria-current="page"] + .nav-pin { --pin-bg: transparent; }
.nav-pin svg { width: 18px; height: 18px; }
.nav-row:hover .nav-pin,
.nav-pin:focus-visible,
.nav-pin[aria-pressed="true"] { opacity: 1; }
.nav-pin[aria-pressed="true"] { color: var(--ru-gold-800); background: transparent; }
.nav-pin[aria-pressed="true"] svg { fill: currentColor; }
[data-theme="dark"] .nav-pin[aria-pressed="true"] { color: var(--ru-gold-400); }
.nav-row:has(.nav-pin[aria-pressed="true"]) .nav-link { padding-right: 48px; }
@media (hover: none) {
    .nav-pin { opacity: 1; background: transparent; }
    .nav-row .nav-link { padding-right: 48px; }
}

/* the TH / EN switch: 44px targets (the design system draws 36px) */
.lang-toggle { margin: 0; }
.lang-toggle button { min-height: 36px; min-width: 44px; }

/* ---- shared invoice list (core/templates/core/invoices/) --------------------------------------- */

.inv-muted { color: var(--text-secondary); font-size: 13px; margin: 0; }
.inv-note { margin-top: var(--s-3); }
.inv-small-title { font-size: 15px; line-height: 24px; margin-bottom: var(--s-3); }
.inv-page-head { margin-bottom: var(--s-6); }
.inv-page-head h1 { margin-bottom: var(--s-1); }
.inv-impersonation { margin-bottom: var(--s-6); }

.inv-share { display: flex; height: 10px; overflow: hidden; border-radius: var(--r-pill); background: var(--surface-3); margin-bottom: var(--s-4); }
.inv-share-seg { height: 100%; }
.inv-tone-warning { background: var(--warning-500); }
.inv-tone-info { background: var(--info-500); }
.inv-tone-success { background: var(--success-500); }
.inv-tone-navy { background: var(--ru-navy-400); }
.inv-tone-gold { background: var(--ru-gold-500); }

.inv-summary-card { display: grid; gap: var(--s-2); color: var(--text-primary); text-decoration: none; transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out); }
[data-theme="dark"] .inv-summary-card { color: var(--text-primary); }
.inv-summary-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.inv-summary-card.is-active { border: 2px solid var(--ru-gold-500); }

.inv-filter { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--s-4); align-items: end; }
.inv-filter .field { margin-bottom: 0; }
.inv-filter .form-actions { margin-top: 0; }
.inv-po-tabs { margin-bottom: var(--s-4); }
.tabs a.tab { display: inline-flex; align-items: center; text-decoration: none; }

.inv-card { display: grid; gap: var(--s-4); }
.inv-status { margin: 0; }
.inv-head { display: flex; flex-wrap: wrap; gap: var(--s-4); justify-content: space-between; }
.inv-head p { margin: 0; }
.inv-num { margin: 0; font-size: 19px; line-height: 28px; font-family: var(--font-mono); }
.inv-money { text-align: right; }
.inv-amount { font-size: 24px; line-height: 32px; font-weight: 700; }
.inv-amount span { font-size: 15px; font-weight: 400; color: var(--text-secondary); font-family: var(--font-body); }

.inv-steps { display: flex; list-style: none; margin: 0; padding: 0; overflow-x: auto; counter-reset: none; }
.inv-step { flex: 1 1 0; min-width: 6.5rem; display: grid; justify-items: center; gap: var(--s-1); text-align: center; position: relative; padding-top: 2px; font-size: 13px; line-height: 1.4; }
.inv-step + .inv-step::before { content: ""; position: absolute; top: 16px; left: -50%; width: 100%; height: 2px; background: var(--border-strong); z-index: 0; }
.inv-step.is-done + .inv-step::before { background: var(--grad-gold); }
.inv-step-dot { position: relative; z-index: 1; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; background: var(--surface-3); border: 1.5px solid var(--border-strong); color: var(--text-secondary); }
.inv-step.is-done .inv-step-dot { background: var(--grad-gold); border-color: transparent; color: var(--ru-navy-900); }
.inv-step.is-current .inv-step-dot { background: var(--surface-1); border: 3px solid var(--ru-gold-500); color: var(--text-primary); }
.inv-step.is-current .inv-step-label { font-weight: 600; }
.inv-step.is-pending .inv-step-label { color: var(--text-secondary); }
.inv-step-date { color: var(--ru-gold-800); }
[data-theme="dark"] .inv-step-date { color: var(--ru-gold-300); }
.inv-step-days { color: var(--text-secondary); }
.inv-step-by { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 1px var(--s-2); border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-secondary); font-size: 12px; }
.inv-step-note { color: var(--danger-fg); font-size: 12px; }
.inv-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); border-top: 1px dashed var(--border-strong); padding-top: var(--s-4); }

.inv-users { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.inv-users li { display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border-radius: var(--r-pill); background: var(--surface-3); }

.inv-dialog { width: min(48rem, calc(100vw - 2 * var(--s-4))); max-height: calc(100vh - 2 * var(--s-6)); overflow: auto; padding: var(--s-6); color: var(--text-primary); background: var(--glass-bg-strong); }
.inv-dialog::backdrop { background: rgba(5, 15, 43, 0.55); backdrop-filter: blur(4px); }
.inv-dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-4); }
.inv-dialog-head h2 { font-size: 19px; line-height: 28px; }
.inv-check-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--s-3); margin: 0 0 var(--s-4); }
.inv-check-info dt { color: var(--text-secondary); font-size: 13px; }
.inv-check-info dd { margin: 0; font-weight: 600; }

@media (max-width: 639.98px) {
    .inv-money { text-align: left; }
}

/* Narrow screens: the stage stepper runs down the card instead of scrolling sideways (nothing to scroll by
   keyboard, and every stage stays readable at 360px) */
@media (max-width: 639.98px) {
    .inv-steps { flex-direction: column; gap: var(--s-2); overflow: visible; }
    .inv-step { grid-template-columns: 30px 1fr; justify-items: start; text-align: left; column-gap: var(--s-3); min-width: 0; }
    .inv-step + .inv-step::before { display: none; }
    .inv-step-dot { grid-row: span 3; }
    .inv-step-label, .inv-step-date, .inv-step-by, .inv-step-note { grid-column: 2; }
}

/* pager entries rendered as links or spans: centred, no underline */
.page-btn { display: inline-grid; place-items: center; text-decoration: none; }

/* ---- supplier admin (wave 10) -------------------------------------------------------------- */
.sa-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s-3); }
.sa-crumbs { margin-bottom: var(--s-4); }
.sa-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.sa-actions form { margin: 0; }
.sa-btn-danger { background: transparent; color: var(--danger-fg); border: 1.5px solid var(--danger-border); }
.sa-btn-danger:hover { background: var(--danger-bg); }
.sa-search { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-4); }
.sa-search .field { flex: 1 1 16rem; margin-bottom: 0; }
.sa-search .form-actions { margin-top: 0; }
/* sortable column header: the whole cell is the link (48px), the chevron has its own room, the colour is the header's own
   (in the dark theme the global link gold would otherwise colour every sortable header) */
.data-table th:has(.sa-sort) { padding: 0; }
.data-table th .sa-sort { display: flex; align-items: center; gap: var(--s-1); width: 100%; min-height: 48px; padding: var(--s-3) var(--s-4); color: inherit; text-decoration: none; }
.data-table th.num .sa-sort { justify-content: flex-end; }
.data-table th .sa-sort:hover, .data-table th .sa-sort:focus-visible { text-decoration: underline; }
.data-table th[aria-sort] .sa-sort { color: var(--text-primary); }
.sa-sort-mark { display: inline-flex; flex-shrink: 0; }
.sa-sort-mark .icon { width: 16px; height: 16px; }

/* the row button of the OU tables: a 44px target (design rule), and no glow on the current page number (Brand Shadow) */
.data-table--cards td .btn-sm { min-height: 44px; }
/* the name is a link too (the row's button stays the keyboard and screen-reader way in), and the row answers the pointer */
.data-table .op-row-link { color: inherit; text-decoration: none; }
.data-table .op-row-link:hover { text-decoration: underline; text-underline-offset: 3px; }
@media (hover: hover) { .data-table--cards tbody tr:hover td { background: var(--surface-3); } }
.page-btn.active, [data-theme="dark"] .page-btn.active { box-shadow: none; }
/* a Thai column label in the mono face has no glyphs there and falls back to another face: mono is for figures */
.data-table th.num { font-family: var(--font-body); }
.field-help, .inv-muted { text-wrap: pretty; }
.sa-registrants { list-style: none; margin: var(--s-1) 0 0; padding: 0; font-size: 13px; }
.sa-email { font-weight: 400; }
.sa-dialog { width: min(32rem, calc(100vw - 2 * var(--s-4))); }
.sa-combobox { max-width: 32rem; }
.sa-combobox--wide { max-width: none; }
/* what floats over the page must be opaque: the dark theme's --surface-1 is white at 5%, which let the chips and help text
   under the open list show through it */
.sa-combobox { --listbox-bg: var(--surface-1); }
[data-theme="dark"] .sa-combobox { --listbox-bg: var(--ru-navy-800); }
.sa-combobox .field { margin-bottom: 0; position: relative; }
/* the matches float over what is below the input instead of pushing the page down, and over the help line under it */
.sa-listbox { position: absolute; inset-inline: 0; z-index: 30; list-style: none; margin: var(--s-1) 0 0; padding: var(--s-1); max-height: 15rem; overflow-y: auto; border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--listbox-bg); box-shadow: var(--shadow-md); }
.sa-listbox [role=option] { justify-content: space-between; gap: var(--s-4); padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.sa-listbox [role=option]:hover, .sa-listbox [aria-selected=true] { background: var(--surface-3); outline: 2px solid var(--ru-gold-500); outline-offset: -2px; }
.sa-option-note { padding: var(--s-2) var(--s-3); color: var(--text-secondary); }
.sa-opt-sub { color: var(--text-secondary); }
.sa-opt-count { flex-shrink: 0; color: var(--text-secondary); font-size: 13px; white-space: nowrap; }
.sa-option-count { position: sticky; bottom: calc(-1 * var(--s-1)); margin-top: var(--s-1); padding: var(--s-2) var(--s-3); border-top: 1px solid var(--border-subtle); background: var(--listbox-bg); color: var(--text-secondary); font-size: 13px; }
/* the OUs this person opened last, under the search; the help is a quiet disclosure under them, not a card above */
.op-recent { margin-top: var(--s-6); }
.op-recent h2 { margin: 0 0 var(--s-2); color: var(--text-secondary); font-size: 15px; font-weight: 600; line-height: 24px; }
/* the type scale of DESIGN.md on these pages: the lead is Body Large (19/32), the title of the list is a Heading 4 (24/32),
   not a 13px caption; a phone gets a step smaller of each so the lead does not take half the screen */
.op-lead { margin: 0; max-width: 68ch; color: var(--text-secondary); font-size: 19px; line-height: 32px; text-wrap: pretty; }
.op-section-title { margin: 0 0 var(--s-4); color: var(--text-primary); font-size: 24px; font-weight: 700; line-height: 32px; }
@media (max-width: 639px) {
    .op-lead { font-size: 16px; line-height: 26px; }
    .op-section-title { font-size: 20px; line-height: 28px; }
}
.op-recent-list { display: flex; flex-wrap: wrap; gap: var(--s-2); list-style: none; margin: 0; padding: 0; }
.op-chip { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s-4); border: 1px solid var(--border-strong); border-radius: var(--r-pill); color: var(--text-primary); text-decoration: none; background: var(--surface-1); transition: border-color var(--dur-base), background var(--dur-base); }
.op-chip:hover { background: var(--surface-3); border-color: var(--ru-navy-300); }
.op-help { margin-top: var(--s-6); color: var(--text-secondary); font-size: 14px; }
.op-help summary { cursor: pointer; padding-block: var(--s-3); } /* a 44px target that keeps the browser's own disclosure marker */
.op-help ul { margin: var(--s-2) 0 0; padding-left: var(--s-6); }

/* ---- barcode pages (wave 12) -------------------------------------------------------------------- */
[x-cloak] { display: none !important; }
.bc-row { display: flex; flex-wrap: wrap; gap: var(--s-4); align-items: flex-end; }
.bc-row .field { flex: 1 1 10rem; margin-bottom: 0; }
.bc-errors .field-error { margin: var(--s-2) 0 0; }
.bc-row [aria-invalid="true"] { border-color: var(--danger-fg); }
.bc-chips { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; padding: var(--s-2); min-height: 3.5rem; border: 1.5px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface-1); }
.bc-chips input { flex: 1 1 10rem; border: 0; outline: 0; background: transparent; color: var(--text-primary); font: inherit; min-height: 44px; }
.bc-chips:focus-within { border-color: var(--ru-gold-500); box-shadow: 0 0 0 4px rgba(232, 184, 79, 0.18); }
.bc-chip { display: inline-flex; align-items: center; gap: var(--s-1); }
.bc-chip button { display: inline-grid; place-items: center; border: 0; background: transparent; color: inherit; cursor: pointer; min-width: 24px; min-height: 24px; }
.bc-facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-1) var(--s-4); margin: 0; }
.bc-facts dt { color: var(--text-secondary); font-size: 13px; }
.bc-facts dd { margin: 0; font-weight: 600; }
.bc-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.bc-note { color: var(--text-secondary); font-size: 13px; margin: 0; }
.bc-warn td { background: var(--warning-bg); }
.bc-stat { display: grid; gap: var(--s-2); }
.bc-stat-value { font-size: 28px; line-height: 36px; font-weight: 700; margin: 0; }
.bc-stat-bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bc-stat-bar > span { display: block; height: 100%; background: var(--grad-gold); }
.bc-stat details { color: var(--text-secondary); font-size: 14px; }
.bc-stat summary { cursor: pointer; min-height: 24px; }
.bc-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: var(--s-4); }

/* A page with the language switch, the theme switch and a sign-out button (student and portal pages) must still fit 360px */
@media (max-width: 400px) {
    .app-topbar { padding: 0 var(--s-2); }
    .app-brand { gap: 0; }
    .app-logo { margin: 4px; }
    .app-topbar-actions { gap: var(--s-1); }
    .app-topbar-actions .btn-sm { padding-inline: 10px; }
    .lang-toggle button { padding-inline: 10px; }
    .theme-toggle button { padding-inline: 12px; }
}

/* label/value pairs of a detail page (supplier inquiry): two columns from tablet up, stacked on a phone */
.sa-dl { display: grid; grid-template-columns: 1fr; gap: var(--s-1) var(--s-4); margin: 0; }
.sa-dl dt { color: var(--text-secondary); font-size: 14px; }
.sa-dl dd { margin: 0 0 var(--s-3); overflow-wrap: anywhere; }
@media (min-width: 640px) {
  .sa-dl { grid-template-columns: minmax(180px, 1fr) 3fr; }
  .sa-dl dd { margin: 0; }
}

/* invoice + receipt applications (ar-invoice-receipt): a heavier rule above each invoice, its receipts quieter below */
.ari-invoice-row td { border-top: 2px solid var(--border-strong); }
.ari-receipt-row td { color: var(--text-secondary); font-size: 14px; }
.ari-overdue { color: var(--danger-fg); font-weight: 700; font-size: 13px; }

/* permission profiles (staff_admin): enforcement panel, profile list beside the menus, level buttons */
.pm-enforce { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-4); justify-content: space-between; }
.pm-enforce-on { border-color: var(--danger-border); }
.pm-layout { display: grid; grid-template-columns: 1fr; gap: var(--s-5); }
@media (min-width: 900px) { .pm-layout { grid-template-columns: minmax(220px, 1fr) 3fr; } }
.pm-profiles { list-style: none; margin: 0 0 var(--s-4); padding: 0; display: grid; gap: var(--s-2); }
.pm-profile { display: block; padding: var(--s-3) var(--s-4); border: 1px solid var(--border-subtle); border-radius: var(--r-md); text-decoration: none; color: var(--text-primary); min-height: 44px; }
.pm-profile.active { background: var(--grad-royal); color: #fff; border-color: transparent; }
.pm-sub { display: block; font-size: 13px; opacity: 0.85; }
.pm-bulk { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.pm-menus { list-style: none; margin: 0; padding: 0; }
.pm-menu { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); padding: var(--s-3) 0; border-top: 1px solid var(--border-subtle); }
.pm-menu:first-child { border-top: 0; }
.pm-new { background: var(--warning-bg); }
.pm-levels { margin-left: auto; display: inline-flex; flex-wrap: wrap; gap: var(--s-1); }
.pm-level { min-height: 44px; padding: 0 var(--s-3); border: 1px solid var(--border-strong); border-radius: var(--r-md); background: transparent; color: var(--text-primary); cursor: pointer; font: inherit; }
.pm-level.on { color: #fff; border-color: transparent; }
.pm-level-none.on { background: var(--text-primary); }
.pm-level-view.on, .pm-key.pm-level-view { background: #0369a1; color: #fff; }
.pm-level-edit.on, .pm-key.pm-level-edit { background: #15803d; color: #fff; }
.pm-level-full.on, .pm-key.pm-level-full { background: #6d28d9; color: #fff; }
.pm-key { display: inline-block; padding: 2px var(--s-3); border-radius: var(--r-pill); font-size: 13px; }

/* raw ETL step output (staff_admin etl_run_view) */
.sa-log { max-height: 300px; overflow: auto; margin: var(--s-2) 0 0; padding: var(--s-2); background: var(--surface-3); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* announcements (feed, manage, form) */
.sa-two { display: grid; grid-template-columns: 1fr; gap: 0 var(--s-4); }
@media (min-width: 720px) { .sa-two { grid-template-columns: 1fr 1fr; } }
.ann-feed { max-width: 720px; display: grid; gap: var(--s-4); }
.ann-card { display: block; }
.ann-cover { width: 100%; max-height: 320px; object-fit: cover; border-radius: var(--r-md, 8px); margin-bottom: var(--s-3); }
.ann-gallery { list-style: none; margin: 0 0 var(--s-3); padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.ann-gallery img { width: 90px; height: 90px; object-fit: cover; border-radius: var(--r-sm, 6px); display: block; }
.ann-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-3); flex-wrap: wrap; }
.ann-title { margin: 0; font-size: 20px; }
.ann-admin, .ann-row-actions { display: flex; gap: var(--s-2); align-items: center; }
.ann-admin form, .ann-row-actions form { margin: 0; }
.ann-meta { margin: var(--s-1) 0 var(--s-3); font-size: 14px; }
.ann-body { overflow-wrap: anywhere; margin-bottom: var(--s-3); }
.ann-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); border-top: 1px solid var(--border-subtle); padding-top: var(--s-3); }
.ann-comments { flex-basis: 100%; }
.ann-comments ul { list-style: none; margin: 0; padding: 0; }
.ann-comments li { display: flex; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--border-subtle); }
.ann-comments li p { margin: 0; overflow-wrap: anywhere; }
.ann-comment-form { display: flex; gap: var(--s-2); margin-top: var(--s-3); }
.ann-comment-form .field-input { flex: 1; }
.ann-empty { text-align: center; padding: var(--s-6, 48px) 0; }
.ann-counts { margin: 0; }

/* revenue analytics (analytics/index.html) */
.ra-two { display: grid; grid-template-columns: 1fr; gap: var(--s-4); }
@media (min-width: 900px) { .ra-two { grid-template-columns: 1fr 1fr; } }
.ra-breakdown { margin: var(--s-4) 0; }
.ra-section { border: 1px solid var(--border-subtle); border-radius: var(--r-md, 8px); padding: var(--s-3); margin: var(--s-3) 0; }
.ra-section[hidden] { display: none; }
.ra-label { margin: 0 0 var(--s-2); font-weight: 600; }
.ra-checks { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); }
.ra-filter { display: grid; grid-template-columns: 1fr; gap: var(--s-2); align-items: end; margin-bottom: var(--s-2); }
@media (min-width: 900px) { .ra-filter { grid-template-columns: 3fr 3fr 4fr auto; } }
.ra-progress { width: 120px; height: 12px; vertical-align: middle; }
.ra-templates { list-style: none; margin: 0; padding: var(--s-3); }
.ra-templates li { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); padding: var(--s-2) 0; }
.ra-templates form { margin: 0; }
.ra-template { max-width: 480px; }

/* home page (home/index.html) */
.home-welcome { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); }
.home-entry { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-4); }
.home-cards { display: grid; grid-template-columns: 1fr; gap: var(--s-4); }
@media (min-width: 720px) { .home-cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .home-cards { grid-template-columns: repeat(3, 1fr); } }
.home-card { display: flex; flex-direction: column; }
.home-card h3 { margin: var(--s-2) 0 var(--s-1); font-size: 18px; }
/* the badge of a service card: the group's colour (design tokens), on a pale disc; never gold (it is earned) */
.home-icon { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: 50%; background: var(--ru-navy-50); color: var(--ru-navy-600); }
.home-icon .icon { width: 24px; height: 24px; }
.home-icon--staff { color: var(--ru-navy-600); }
.home-icon--student { color: var(--info-500); }
.home-icon--external { color: var(--text-secondary); }
[data-theme="dark"] .home-icon { background: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .home-icon--staff { color: var(--ru-navy-200); }
[data-theme="dark"] .home-icon--student { color: var(--info-fg); }
[data-theme="dark"] .home-icon--external { color: var(--text-secondary); }
.home-desc { flex: 1; font-size: 14px; }
.home-card-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--s-3); border-top: 1px solid var(--border-subtle); padding-top: var(--s-3); margin-top: var(--s-3); }
.home-card-foot > span { margin-right: auto; font-size: 14px; }
.home-jobs, .home-services { list-style: none; margin: 0; padding: var(--s-2) var(--s-3); }
.home-jobs li a { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); padding: var(--s-2) 0; }
.home-job-name { flex: 1; min-width: 0; }
.home-job-name .field-error { display: block; font-size: 13px; }
.home-services li { padding: var(--s-2) 0; }
.home-services a { display: flex; align-items: center; gap: var(--s-3); }
.home-services .icon { color: var(--text-secondary); }
.home-overview { display: grid; gap: var(--s-4); margin-top: var(--s-3); }
@media (min-width: 1100px) { .home-overview { grid-template-columns: 7fr 5fr; } .home-overview > :last-child { grid-column: 1 / -1; } }
.home-engage { margin-bottom: var(--s-3); }
.home-engage-head { display: flex; justify-content: space-between; gap: var(--s-3); font-size: 14px; }
.home-engage progress { width: 100%; height: 8px; }
.login-card { max-width: 420px; margin: var(--s-6, 48px) auto 0; }
.login-pinned { max-width: 420px; margin: 0 auto var(--s-3); }
.login-tabs { display: flex; gap: var(--s-2); margin-bottom: var(--s-3); }
.login-tabs a { flex: 1; text-align: center; padding: var(--s-2) var(--s-3); border-bottom: 3px solid transparent; font-weight: 600; }
.login-tabs a[aria-current="page"] { border-bottom-color: var(--border-gold); }
.login-addon { display: flex; align-items: center; gap: var(--s-2); }
.login-addon .field-input { flex: 1; }
.login-today { max-width: 420px; margin: var(--s-4) auto 0; text-align: center; }
.login-avatars { display: flex; justify-content: center; margin-bottom: var(--s-2); }
.login-avatar { position: relative; display: inline-flex; width: 36px; height: 36px; margin-left: -8px; border-radius: 50%; align-items: center; justify-content: center; background: var(--surface-3); border: 2px solid var(--surface-1, #fff); font-size: 13px; font-weight: 700; overflow: hidden; }
.login-avatar:first-child { margin-left: 0; }
.login-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* the `hidden` attribute must win over a component's own display (.btn is inline-flex): found by the browser pass, where
   the "remove filter" button stayed visible on the last row */
[hidden] { display: none !important; }
