/* ==========================================================================
   iPAY staff portal — design tokens + components
   EdUHK green identity (leaves) + orange highlight (sun), warm paper
   neutrals, WCAG-AA contrast, 16px+ type, generous targets. Fonts: Public
   Sans (Latin) + Noto Sans TC (zh-Hant) + JetBrains Mono (codes/IDs).
   Style ONLY with the classes below — no new colours, no inline styles
   beyond widths.
   ========================================================================== */

:root {
  /* brand — identity and action are the same green (design language v2) */
  --brand: #146B3A;           /* EdUHK green: approximation until the guideline value lands */
  --brand-deep: #0E4F2A;
  --brand-tint: #E6F2EA;
  --brand-tint-2: #CDE5D4;
  --action: #146B3A;
  --action-hover: #0E4F2A;
  --action-tint: #E6F2EA;
  /* accent — the logo orange. Borders, tints and rings only; the dark form
     (--accent-text, 6.0:1 on white) is the only orange that carries text. */
  --accent: #F28C1E;
  --accent-tint: #FDEBD5;
  --accent-line: #F5B36B;
  --accent-text: #9A4E00;
  /* neutrals (warm paper) */
  --paper: #FAF7F2;
  --surface: #FFFFFF;
  --surface-2: #F3EFE8;
  --surface-3: #EAE4DA;
  --line: #E2DBD0;
  --line-strong: #C9C0B3;
  --ink: #1F1B17;             /* 15.6:1 on paper */
  --ink-2: #4A433C;           /* 8.4:1 */
  --ink-3: #6B635A;           /* 5.3:1 on white — muted but AA */
  --ink-inverse: #FFFFFF;
  /* status tones (text on tint ≥ 7:1) */
  --ok: #1E6B3A;      --ok-tint: #E3F2E8;     --ok-line: #A9D6B8;
  --warn: #6E5A1E;    --warn-tint: #F6F0DC;   --warn-line: #DCCD9A;
  --danger: #A32020;  --danger-tint: #FBE6E6; --danger-line: #EFB3B3;
  --info: #1F4E7A;    --info-tint: #E3EEF8;   --info-line: #B3CDE8;
  --neutral: #4A433C; --neutral-tint: #EDE8E0; --neutral-line: #D3CBBF;
  --dark: #FFFFFF;    --dark-tint: #4A433C;   --dark-line: #4A433C;
  --focus: #F5A623;
  /* shape + motion */
  --radius: 12px; --radius-sm: 8px; --radius-lg: 18px; --radius-pill: 999px;
  --shadow: 0 1px 2px rgba(31, 27, 23, .06), 0 4px 16px rgba(31, 27, 23, .06);
  --shadow-lg: 0 2px 6px rgba(31, 27, 23, .08), 0 12px 32px rgba(31, 27, 23, .10);
  --ease: 160ms ease;
  /* type */
  --font-sans: "Public Sans", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "微軟正黑體", "Heiti TC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Noto Sans TC", monospace;
  --fs-base: 16px; --lh-base: 1.55;
  /* layout */
  --topbar-h: 62px; --sidebar-w: 248px; --content-max: 1240px;
}

/* --------------------------------------------------------------------------
   Reset + base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: var(--fs-base); -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font-sans); font-size: 1rem; line-height: var(--lh-base); color: var(--ink); background: var(--paper); min-height: 100vh; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0 0 .75rem; }
p:last-child { margin-bottom: 0; }
a { color: var(--action); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--action-hover); }
img, svg { max-width: 100%; vertical-align: middle; }
button, input, select, textarea { font: inherit; color: inherit; }
ul, ol { margin: 0; padding-left: 1.25rem; }
.inline-form { display: inline; margin: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: .5rem .75rem; border-radius: var(--radius-sm); z-index: 100; }
.skip-link:focus { left: 8px; }
.muted { color: var(--ink-3); }
.small { font-size: .9rem; }
.strong { font-weight: 600; }
.mono, .code { font-family: var(--font-mono); }
.h2 { font-size: 1.3rem; }
.h3 { font-size: 1.1rem; }
.icon { flex: none; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; } .mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.stack > * + * { margin-top: 1rem; }
.stack--sm > * + * { margin-top: .5rem; }
.cluster { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; }
.cluster--between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.25rem; align-items: start; }
.grid-sidebar { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .grid-sidebar { grid-template-columns: 1fr; } }

/* --------------------------------------------------------------------------
   Demo badge (persistent in every shell)
   -------------------------------------------------------------------------- */
.demo-badge { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .8rem; background: var(--warn-tint); color: var(--warn); border: 1.5px solid var(--warn-line); border-radius: var(--radius-pill); font-size: .85rem; font-weight: 600; box-shadow: var(--shadow); pointer-events: none; }

/* --------------------------------------------------------------------------
   Top bar + layout
   -------------------------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 50; height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0 1.25rem; background: linear-gradient(90deg, var(--brand-deep), var(--brand)); color: var(--ink-inverse); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.brand { display: inline-flex; align-items: baseline; gap: .6rem; color: inherit; text-decoration: none; }
.brand-mark { font-weight: 800; font-size: 1.45rem; letter-spacing: .02em; }
.brand-mark--lg { font-size: 2.4rem; color: var(--brand); }
.brand-sub { font-size: .9rem; opacity: .9; }
.topbar-right { display: flex; align-items: center; gap: .9rem; }
.user-chip { display: inline-flex; align-items: center; gap: .5rem; }
.user-name { font-weight: 600; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; background: var(--surface); color: var(--brand); font-weight: 700; font-size: .9rem; border: 2px solid rgba(255,255,255,.7); flex: none; }
.avatar--lg { width: 52px; height: 52px; font-size: 1.1rem; }
.avatar--sm { width: 28px; height: 28px; font-size: .75rem; }
.main .avatar { background: var(--brand-tint); border-color: var(--brand-tint-2); }

.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h)); }
.sidebar { position: sticky; top: var(--topbar-h); align-self: start; height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 1.25rem .9rem; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sidebar-heading { margin: .75rem .6rem .4rem; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.nav-list { list-style: none; padding: 0; margin: 0 0 .5rem; }
.nav-link { display: flex; align-items: center; gap: .7rem; min-height: 46px; padding: .55rem .75rem; margin: 2px 0; border-radius: var(--radius-sm); color: var(--ink-2); text-decoration: none; font-weight: 500; border-left: 3px solid transparent; transition: background var(--ease), color var(--ease); }
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.is-active { background: var(--brand-tint); color: var(--brand); border-left-color: var(--brand); font-weight: 600; }
.nav-link--admin.is-active { background: var(--action-tint); color: var(--action); border-left-color: var(--action); }
.nav-link--sub { font-size: .92rem; color: var(--ink-3); }
.nav-link--button { width: 100%; background: transparent; border: 0; border-left: 3px solid transparent; cursor: pointer; text-align: left; font: inherit; font-size: .92rem; }
.nav-link--button:hover { background: var(--surface-2); color: var(--ink); }
.nav-badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 .4rem; border-radius: var(--radius-pill); background: var(--brand); color: #fff; font-size: .75rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.sidebar-note { display: flex; gap: .5rem; margin: .5rem .4rem; padding: .7rem .8rem; font-size: .85rem; color: var(--ink-3); background: var(--surface-2); border-radius: var(--radius-sm); line-height: 1.4; }
.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line); }
.main { padding: 1.75rem 2rem 4rem; max-width: var(--content-max); width: 100%; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; gap: .25rem; padding: .6rem .75rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-heading, .sidebar-note, .sidebar-foot { display: none; }
  .nav-list { display: flex; flex-wrap: wrap; gap: .25rem; margin: 0; }
  .nav-link { min-height: 42px; padding: .4rem .7rem; border-left: 0; border-bottom: 3px solid transparent; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
  .nav-link.is-active { border-bottom-color: var(--brand); }
  .main { padding: 1.25rem 1rem 4rem; }
  .brand-sub { display: none; }
  .user-name { display: none; }
}

/* --------------------------------------------------------------------------
   Page header
   -------------------------------------------------------------------------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-kicker { margin: 0 0 .25rem; font-size: .85rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); }
.page-title { font-size: 1.8rem; }
.page-title .study-title-zh { font-size: inherit; font-weight: inherit; line-height: 1.25; }
.page-title .study-title-en { font-size: 1.05rem; font-weight: 500; margin-top: .15rem; }
.page-lede { margin: .35rem 0 0; color: var(--ink-3); max-width: 70ch; }
.page-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 0 .9rem; }
.section-title h2 { font-size: 1.2rem; }

/* --------------------------------------------------------------------------
   Cards, stats, notices
   -------------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; box-shadow: var(--shadow); }
.card--flush { padding: 0; overflow: hidden; }
.card--tint { background: var(--surface-2); box-shadow: none; }
.card--brand { border-color: var(--brand-tint-2); background: linear-gradient(180deg, #fff, var(--brand-tint)); }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.4rem; border-bottom: 1px solid var(--line); }
.card-header h2, .card-header h3 { font-size: 1.1rem; }
.card-body { padding: 1.25rem 1.4rem; }
.card-foot { padding: .9rem 1.4rem; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .2rem; min-height: 96px; text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--line-strong); }
.stat-label { font-size: .85rem; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.1; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-value--brand { color: var(--brand); }
.stat-value--warn { color: var(--warn); }
.stat-value--ok { color: var(--ok); }
.stat-hint { font-size: .85rem; color: var(--ink-3); }
.notice { display: flex; gap: .7rem; padding: .9rem 1.1rem; border-radius: var(--radius-sm); border: 1px solid var(--info-line); background: var(--info-tint); color: var(--info); line-height: 1.45; }
.notice--warn { border-color: var(--warn-line); background: var(--warn-tint); color: var(--warn); }
.notice--ok { border-color: var(--ok-line); background: var(--ok-tint); color: var(--ok); }
.notice--danger { border-color: var(--danger-line); background: var(--danger-tint); color: var(--danger); }
.notice--brand { border-color: var(--brand-tint-2); background: var(--brand-tint); color: var(--brand-deep); }
.notice .icon { flex: none; margin-top: 2px; }
.notice a { color: inherit; font-weight: 600; }
.callout-title { font-weight: 700; margin-bottom: .2rem; }

/* --------------------------------------------------------------------------
   Flash messages
   -------------------------------------------------------------------------- */
.flash-stack { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1.25rem; }
.flash { display: flex; gap: .6rem; align-items: flex-start; padding: .85rem 1.1rem; border-radius: var(--radius-sm); border: 1px solid; font-weight: 500; }
.flash--success { background: var(--ok-tint); border-color: var(--ok-line); color: var(--ok); }
.flash--error { background: var(--danger-tint); border-color: var(--danger-line); color: var(--danger); }
.flash--warning { background: var(--warn-tint); border-color: var(--warn-line); color: var(--warn); }
.flash--info { background: var(--info-tint); border-color: var(--info-line); color: var(--info); }
.error-list { margin: 0; padding-left: 1.2rem; }

/* --------------------------------------------------------------------------
   Chips, tags, match pill, code
   -------------------------------------------------------------------------- */
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .65rem; border-radius: var(--radius-pill); font-size: .82rem; font-weight: 600; line-height: 1.5; white-space: nowrap; border: 1px solid; }
.chip--lg { font-size: .95rem; padding: .3rem .85rem; }
.chip--sm { font-size: .72rem; padding: .05rem .45rem; }
.chip--ok { background: var(--ok-tint); color: var(--ok); border-color: var(--ok-line); }
.chip--warn { background: var(--warn-tint); color: var(--warn); border-color: var(--warn-line); }
.chip--danger { background: var(--danger-tint); color: var(--danger); border-color: var(--danger-line); }
.chip--info { background: var(--info-tint); color: var(--info); border-color: var(--info-line); }
.chip--neutral { background: var(--neutral-tint); color: var(--neutral); border-color: var(--neutral-line); }
.chip--dark { background: var(--dark-tint); color: var(--dark); border-color: var(--dark-line); }
.chip--brand { background: var(--brand-tint); color: var(--brand); border-color: var(--brand-tint-2); }
.chip--inverse { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.35); }
.tag { display: inline-flex; align-items: center; padding: .15rem .6rem; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); font-size: .82rem; font-weight: 500; }
.tag--matched { background: var(--brand-tint); border-color: var(--brand-tint-2); color: var(--brand); font-weight: 600; }
.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.match-pill { display: inline-flex; align-items: baseline; gap: .3rem; padding: .25rem .7rem; border-radius: var(--radius-pill); border: 1px solid; font-size: .9rem; }
.match-pill strong { font-size: 1.05rem; }
.match-pill--ok { background: var(--ok-tint); color: var(--ok); border-color: var(--ok-line); }
.match-pill--warn { background: var(--warn-tint); color: var(--warn); border-color: var(--warn-line); }
.match-pill--neutral { background: var(--neutral-tint); color: var(--neutral); border-color: var(--neutral-line); }
.code { font-family: var(--font-mono); font-size: .92em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: .1rem .4rem; letter-spacing: .02em; white-space: nowrap; }
.code--masked { letter-spacing: .08em; color: var(--ink-2); }
.code--reveal { font-size: 1.25rem; padding: .5rem .9rem; background: var(--ok-tint); border-color: var(--ok-line); color: var(--ok); user-select: all; }
.pseudonym { font-family: var(--font-mono); font-weight: 600; letter-spacing: .03em; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; padding: .55rem 1.1rem; border-radius: var(--radius-sm); border: 1.5px solid transparent; font-weight: 600; font-size: 1rem; line-height: 1.2; text-decoration: none; cursor: pointer; transition: background var(--ease), border-color var(--ease), color var(--ease), transform var(--ease); white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--action); color: #fff; border-color: var(--action); }
.btn--primary:hover { background: var(--action-hover); border-color: var(--action-hover); color: #fff; }
/* The one panel-wide send (Send announcement): dark orange, the only orange with text. */
.btn--brand { background: var(--accent-text); color: #fff; border-color: var(--accent-text); }
.btn--brand:hover { background: #7E3F00; border-color: #7E3F00; color: #fff; }
.btn--secondary { background: var(--surface); color: var(--action); border-color: var(--line-strong); }
.btn--secondary:hover { background: var(--action-tint); border-color: var(--action); color: var(--action); }
.btn--ghost { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn--on-dark { color: #fff; }
.btn--on-dark:hover { background: rgba(255,255,255,.14); color: #fff; }
.btn--danger { background: var(--surface); color: var(--danger); border-color: var(--danger-line); }
.btn--danger:hover { background: var(--danger-tint); border-color: var(--danger); color: var(--danger); }
.btn--success { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn--success:hover { background: #185A30; border-color: #185A30; color: #fff; }
.btn--sm { min-height: 36px; padding: .3rem .75rem; font-size: .9rem; }
.btn--lg { min-height: 52px; padding: .7rem 1.4rem; font-size: 1.05rem; }
.btn--block { width: 100%; }
.btn-group { display: inline-flex; gap: .5rem; flex-wrap: wrap; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.actions--end { justify-content: flex-end; }
.link-btn { background: none; border: 0; padding: 0; color: var(--action); text-decoration: underline; cursor: pointer; font-weight: 500; }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.form-stack { display: flex; flex-direction: column; gap: 1.1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.1rem 1.5rem; }
.form-grid .field--full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.label { font-weight: 600; color: var(--ink); }
.label .req { color: var(--danger); margin-left: .15rem; }
.help { font-size: .88rem; color: var(--ink-3); line-height: 1.4; }
.input, .select, .textarea { width: 100%; min-height: 46px; padding: .55rem .8rem; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); transition: border-color var(--ease), box-shadow var(--ease); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--action); box-shadow: 0 0 0 3px var(--action-tint); outline: none; }
.input--lg { min-height: 52px; font-size: 1.05rem; }
.input--sm, .select--sm { min-height: 38px; padding: .3rem .6rem; font-size: .92rem; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.textarea--mono { font-family: var(--font-mono); font-size: .9rem; }
.select { appearance: none; -webkit-appearance: none; padding-right: 2.2rem; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%234A433C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right .7rem center; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .input-addon { display: inline-flex; align-items: center; padding: 0 .8rem; border: 1.5px solid var(--line-strong); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); color: var(--ink-2); font-weight: 600; }
.input-group .input-addon--start { border-left: 1.5px solid var(--line-strong); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .input-addon--start + .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.break-all { overflow-wrap: anywhere; word-break: break-word; white-space: normal; }
.check { display: flex; align-items: flex-start; gap: .6rem; padding: .35rem 0; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--action); flex: none; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .25rem .75rem; }
.choice-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.choice-chip { position: relative; }
.choice-chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice-chip span { display: inline-flex; align-items: center; gap: .35rem; min-height: 40px; padding: .4rem .9rem; border-radius: var(--radius-pill); border: 1.5px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font-weight: 500; cursor: pointer; transition: all var(--ease); }
.choice-chip input:checked + span { background: var(--brand-tint); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.choice-chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.criteria-rows { display: flex; flex-direction: column; gap: .6rem; }
.criteria-row { display: grid; grid-template-columns: minmax(160px, 1.4fr) minmax(90px, .6fr) minmax(120px, 1fr); gap: .6rem; align-items: center; }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem 1.25rem; margin: 0; }
.fieldset > legend { font-weight: 700; padding: 0 .4rem; color: var(--brand); }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; padding-top: .5rem; border-top: 1px solid var(--line); margin-top: .5rem; }
.form-actions .spacer { flex: 1; }
.filter-bar { display: flex; flex-wrap: wrap; gap: .6rem .8rem; align-items: flex-end; padding: 1rem 1.2rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
.filter-bar .field { min-width: 150px; gap: .2rem; }
.filter-bar .label { font-size: .82rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.file-drop { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 1.5rem; text-align: center; background: var(--surface-2); }
.file-drop input[type=file] { margin-top: .5rem; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: .75rem .9rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.table th { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #FCFAF6; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .row-actions { white-space: nowrap; text-align: right; }
.table--compact th, .table--compact td { padding: .5rem .7rem; }
.table tr.is-muted td { color: var(--ink-3); }
.table tr.is-selected td { background: var(--action-tint); }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem 1rem; font-size: .9rem; color: var(--ink-3); border-top: 1px solid var(--line); background: var(--surface-2); }
.cell-primary { font-weight: 600; color: var(--ink); }
.cell-sub { display: block; font-size: .85rem; color: var(--ink-3); }

/* --------------------------------------------------------------------------
   Lists, key/value, activity, chat
   -------------------------------------------------------------------------- */
.kv { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; }
.kv-row { display: contents; }
.kv dt { color: var(--ink-3); font-weight: 500; }
.kv dd { margin: 0; color: var(--ink); }
.kv--stack { grid-template-columns: 1fr; gap: .2rem; }
.kv--stack dt { font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-divided > * + * { border-top: 1px solid var(--line); }
.list-row { display: flex; align-items: center; gap: 1rem; padding: .85rem 0; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-weight: 600; }
.list-row-sub { font-size: .9rem; color: var(--ink-3); }
.activity { list-style: none; padding: 0; margin: 0; }
.activity li { display: grid; grid-template-columns: 10px 1fr auto; gap: .8rem; align-items: start; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.activity li:last-child { border-bottom: 0; }
.activity-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); margin-top: .5rem; }
.activity-dot--ok { background: var(--ok); } .activity-dot--info { background: var(--info); } .activity-dot--warn { background: var(--warn); } .activity-dot--neutral { background: var(--line-strong); }
.activity-time { font-size: .85rem; color: var(--ink-3); white-space: nowrap; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: .2rem 0 .9rem 1.1rem; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: .55rem; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
.thread-list { list-style: none; padding: 0; margin: 0; }
.thread-item { display: flex; gap: .9rem; align-items: flex-start; padding: .9rem 1rem; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.thread-item:hover { background: #FCFAF6; }
.thread-item.is-unread .thread-title { font-weight: 700; }
.thread-item.is-active { background: var(--brand-tint); }
.thread-body { flex: 1; min-width: 0; }
.thread-title { display: flex; justify-content: space-between; gap: .5rem; font-weight: 600; }
.thread-preview { color: var(--ink-3); font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-meta { font-size: .82rem; color: var(--ink-3); white-space: nowrap; }
.unread-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); flex: none; margin-top: .4rem; }
.chat { display: flex; flex-direction: column; gap: .6rem; padding: 1rem; background: var(--surface-2); border-radius: var(--radius); min-height: 240px; max-height: 60vh; overflow-y: auto; }
.bubble { max-width: 78%; padding: .65rem .95rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); line-height: 1.45; box-shadow: var(--shadow); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble--mine { align-self: flex-end; background: var(--action); color: #fff; border-color: var(--action); border-bottom-right-radius: 4px; }
.bubble--theirs { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble-meta { display: block; margin-top: .25rem; font-size: .78rem; opacity: .75; }
.chat-compose { display: flex; gap: .6rem; align-items: flex-end; margin-top: .75rem; }
.chat-compose .textarea { min-height: 52px; flex: 1; }
.pane { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .pane { grid-template-columns: 1fr; } }

/* --------------------------------------------------------------------------
   Progress, tabs, toolbar, empty state, study cards
   -------------------------------------------------------------------------- */
.progress { height: 10px; background: var(--surface-3); border-radius: var(--radius-pill); overflow: hidden; }
.progress-bar { height: 100%; border-radius: var(--radius-pill); background: var(--brand); transition: width var(--ease); }
.progress-bar--brand { background: var(--brand); } .progress-bar--ok { background: var(--ok); } .progress-bar--info { background: var(--info); } .progress-bar--warn { background: var(--warn); } .progress-bar--action { background: var(--action); }
.progress-label { margin-top: .3rem; font-size: .88rem; color: var(--ink-3); display: flex; justify-content: space-between; gap: .5rem; }
.empty-art { font-size: 2.4rem; line-height: 1; margin-bottom: .5rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1.25rem; overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: .45rem; min-height: 46px; padding: .5rem 1rem; margin-bottom: -2px; border-bottom: 3px solid transparent; color: var(--ink-2); text-decoration: none; font-weight: 600; white-space: nowrap; }
.tab:hover { color: var(--ink); background: var(--surface-2); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.tab .count { font-size: .8rem; background: var(--surface-3); color: var(--ink-2); padding: 0 .45rem; border-radius: var(--radius-pill); }
.tabs--roles { border: 0; gap: .5rem; margin-bottom: 1.5rem; }
.tabs--roles .tab { flex: 1; justify-content: center; min-height: 54px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); margin: 0; font-size: 1.05rem; background: var(--surface); }
.tabs--roles .tab.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.empty { text-align: center; padding: 2.5rem 1.5rem; }
.empty-title { font-size: 1.15rem; font-weight: 600; margin-bottom: .35rem; }
.study-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.25rem; }
.study-card { display: flex; flex-direction: column; gap: .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem; box-shadow: var(--shadow); transition: border-color var(--ease), box-shadow var(--ease); }
.study-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-lg); }
.study-card--draft { border-style: dashed; }
.study-card--closed { opacity: .85; }
.study-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.study-title { display: flex; flex-direction: column; gap: .1rem; }
.study-title-zh { font-size: 1.15rem; font-weight: 700; color: var(--ink); text-decoration: none; line-height: 1.35; }
a.study-title-zh:hover { color: var(--brand); }
.study-title-en { font-size: .92rem; color: var(--ink-3); }
.study-title--sm .study-title-zh { font-size: 1rem; }
.study-title--sm .study-title-en { font-size: .85rem; }
.study-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem .9rem; font-size: .92rem; }
.study-meta dt { color: var(--ink-3); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.study-meta dd { margin: 0; font-weight: 600; }
.study-card-foot { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: auto; padding-top: .5rem; border-top: 1px solid var(--line); }
.reveal-box { display: flex; flex-direction: column; gap: .6rem; padding: 1rem 1.2rem; border: 1.5px solid var(--ok-line); background: var(--ok-tint); border-radius: var(--radius); }
.reveal-box .muted { color: var(--ok); }
.count-pair { display: flex; gap: 1.5rem; }
.count-pair strong { font-size: 1.35rem; }
.count-pair span { display: block; font-size: .8rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.job-window { font-family: var(--font-mono); font-size: .9rem; }
.pii-note { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--ink-3); }

/* --------------------------------------------------------------------------
   Auth (login / register) layout
   -------------------------------------------------------------------------- */
.auth-body { background: radial-gradient(1200px 600px at 50% -10%, var(--brand-tint) 0%, var(--paper) 60%); }
.auth-main { max-width: 560px; margin: 0 auto; padding: 3rem 1.25rem 5rem; }
.auth-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .2rem; margin-bottom: 1.5rem; }
.auth-brand-sub { font-weight: 600; color: var(--ink-2); font-size: 1.05rem; }
.auth-brand-sub2 { color: var(--ink-3); font-size: .92rem; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.75rem 1.75rem 1.5rem; box-shadow: var(--shadow-lg); }
.auth-title { font-size: 1.5rem; margin-bottom: .3rem; display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.auth-title-zh { font-size: 1.05rem; font-weight: 500; color: var(--ink-3); }
.auth-lede { color: var(--ink-3); margin-bottom: 1.25rem; }
.auth-alt { margin-top: 1.1rem; text-align: center; }
.auth-foot { text-align: center; margin-top: 1.25rem; font-size: .9rem; }
.demo-accounts { margin-top: 1.5rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.demo-accounts summary { cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: .4rem; }
.demo-account-list { list-style: none; padding: 0; margin: .75rem 0 0; display: flex; flex-direction: column; gap: .5rem; }
.demo-account-list li { display: grid; grid-template-columns: auto 1fr auto auto; gap: .6rem; align-items: center; font-size: .92rem; }
.demo-account-label { color: var(--ink-2); }
@media (max-width: 600px) { .demo-account-list li { grid-template-columns: 1fr auto; } .demo-account-list .chip { display: none; } .auth-card { padding: 1.25rem; } }

/* ==========================================================================
   Design language v2 — composition vocabulary
   One primary action · four numbers in one strip · prose behind an (i) ·
   tabs before stacking · tables scroll inside a frame · destructive = dialog ·
   sidebar by workflow, collapsible to a 64px rail.
   Everything below is additive: no class above changed name or meaning.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Breadcrumb + page meta (header furniture above / below the title)
   -------------------------------------------------------------------------- */
.crumb { display: flex; align-items: center; gap: .35rem; margin: 0 0 .35rem; font-size: .85rem; color: var(--ink-3); }
.crumb a { font-weight: 600; text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
.page-meta { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .75rem; margin: .55rem 0 0; font-size: .92rem; color: var(--ink-2); }

/* --------------------------------------------------------------------------
   KPI strip — rule 2: four numbers, one card, dividers instead of gaps.
   ``.kpi-value`` sits after ``.stat-value`` in this file on purpose: pages
   carry both classes on the same element while the old tiles retire.
   -------------------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.25rem; overflow: hidden; }
.kpi { display: flex; flex-direction: column; gap: .15rem; padding: .875rem 1.25rem; border-right: 1px solid var(--line); color: inherit; text-decoration: none; }
.kpi:last-child { border-right: 0; }
a.kpi:hover { background: #FCFAF6; color: inherit; }
.kpi-label { font-size: .8rem; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.kpi-row { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.kpi-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi-value--brand { color: var(--brand); }
.kpi-value--warn { color: var(--warn); }
.kpi-value--ok { color: var(--ok); }
.kpi-value--danger { color: var(--danger); }
.kpi-hint { font-size: .84rem; color: var(--ink-3); }
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(2n) { border-right: 0; }
  .kpi:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

/* --------------------------------------------------------------------------
   Detail summary strip (5 cells: one wide + four numbers)
   -------------------------------------------------------------------------- */
.summary { display: grid; grid-template-columns: 2fr repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.25rem; overflow: hidden; }
.sm { display: flex; flex-direction: column; gap: .2rem; padding: .875rem 1.25rem; border-right: 1px solid var(--line); }
.sm:last-child { border-right: 0; }
.sm-l { font-size: .8rem; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.sm-v { font-size: 1.375rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.sm-v small { font-size: .875rem; font-weight: 500; color: var(--ink-3); }
.sm-v--warn { color: var(--warn); }
.sm-v--ok { color: var(--ok); }
@media (max-width: 900px) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm:nth-child(2n) { border-right: 0; }
}

/* --------------------------------------------------------------------------
   Work queue ("Needs attention"): icon · what · one action
   -------------------------------------------------------------------------- */
.queue { display: flex; flex-direction: column; }
.q-group { margin: 0; padding: .7rem 1.25rem .3rem; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.q-row { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: .875rem; align-items: center; padding: .75rem 1.25rem; border-bottom: 1px solid var(--line); }
.q-row:last-child { border-bottom: 0; }
.q-ic { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--ink-2); }
.q-ic--warn { background: var(--warn-tint); color: var(--warn); }
.q-ic--ok { background: var(--ok-tint); color: var(--ok); }
.q-ic--info { background: var(--info-tint); color: var(--info); }
.q-ic--danger { background: var(--danger-tint); color: var(--danger); }
.q-t { margin: 0; font-weight: 600; }
.q-s { margin: 0; font-size: .875rem; color: var(--ink-3); display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .5rem; }
.q-s .study-title-zh { font-size: .875rem; font-weight: 600; }
.q-s .study-title-en { display: none; }
/* The empty state is the queue's last child and only shows when it is also
   the first — so "is this queue empty?" stays a CSS question and the view
   does not have to pre-compute the union of four unrelated row sources. */
.q-empty { display: none; }
.q-empty:first-child { display: block; }

/* --------------------------------------------------------------------------
   Study rows (dashboard list): title · progress · status · number
   -------------------------------------------------------------------------- */
.s-row { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto auto; gap: .5rem 1rem; align-items: center; padding: .75rem 1.25rem; border-bottom: 1px solid var(--line); }
.s-row:last-child { border-bottom: 0; }
.s-num { font-size: .9rem; color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
@media (max-width: 700px) { .s-row { grid-template-columns: minmax(0, 1fr) auto; } }

/* --------------------------------------------------------------------------
   Key/value rows with a proportion bar (facts column)
   -------------------------------------------------------------------------- */
.kv-rows { display: flex; flex-direction: column; gap: .6rem; padding: 1rem 1.25rem; }
.kv-r { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .3rem .75rem; align-items: center; font-size: .95rem; color: inherit; text-decoration: none; }
.kv-r .k { color: var(--ink-2); }
.kv-r .v { font-weight: 700; font-variant-numeric: tabular-nums; }
a.kv-r:hover .k { color: var(--ink); }
.bar { grid-column: 1 / -1; height: 6px; background: var(--surface-3); border-radius: var(--radius-pill); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: var(--radius-pill); background: var(--brand); }
.bar-fill--ok { background: var(--ok); }
.bar-fill--warn { background: var(--warn); }
.bar-fill--neutral { background: var(--line-strong); }

/* --------------------------------------------------------------------------
   Card header count pill (used next to a section title)
   -------------------------------------------------------------------------- */
.count { font-size: .8rem; font-weight: 600; background: var(--surface-3); color: var(--ink-2); padding: 0 .5rem; border-radius: var(--radius-pill); }

/* --------------------------------------------------------------------------
   Overflow menu — <details>, no JS needed to open (JS only closes it)
   -------------------------------------------------------------------------- */
details.menu, details.popover { position: relative; display: inline-block; }
details.menu > summary, details.popover > summary { list-style: none; cursor: pointer; }
details.menu > summary::-webkit-details-marker,
details.popover > summary::-webkit-details-marker { display: none; }
details.menu > summary { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; padding: .55rem 2.2rem .55rem 1.1rem; border-radius: var(--radius-sm); border: 1.5px solid var(--line-strong); background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%234A433C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>") no-repeat right .7rem center; color: var(--action); font-weight: 600; font-size: 1rem; line-height: 1.2; white-space: nowrap; }
details.menu > summary:hover { background-color: var(--action-tint); border-color: var(--action); }
.menu-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; width: 260px; padding: 6px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.menu-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; border-radius: 6px; color: var(--ink); text-decoration: none; font-weight: 500; font-size: .95rem; background: none; border: 0; width: 100%; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); color: var(--ink); }
.menu-item .hint { margin-left: auto; font-size: .78rem; font-weight: 400; color: var(--ink-3); }
.menu-item--danger, .menu-item--danger:hover { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 8px; }

/* --------------------------------------------------------------------------
   Popover — rule 3: ledes and notices live behind the (i) button
   -------------------------------------------------------------------------- */
.popover-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; width: 340px; max-width: 80vw; padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: .92rem; line-height: 1.5; color: var(--ink-2); text-align: left; white-space: normal; font-weight: 400; }
.popover--filters .popover-panel { width: 520px; }

/* --------------------------------------------------------------------------
   Confirm dialog — rule 6: destructive actions ask first, natively
   -------------------------------------------------------------------------- */
dialog.modal { width: calc(100% - 2rem); max-width: 460px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog.modal::backdrop { background: rgba(31, 27, 23, .45); }
dialog.modal form { margin: 0; padding: 1.25rem 1.4rem; display: flex; flex-direction: column; gap: .6rem; }
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-body { margin: 0; color: var(--ink-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .35rem; }

/* --------------------------------------------------------------------------
   Side drawer — rule 5: the row's detail without leaving the list
   -------------------------------------------------------------------------- */
.drawer { width: 380px; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); }
.drawer-head { display: flex; align-items: flex-start; gap: .75rem; padding: 1.1rem 1.25rem .875rem; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 1.1rem; }
.drawer-foot { padding: .875rem 1.25rem; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; flex-direction: column; gap: .5rem; }
@media (max-width: 900px) { .drawer { width: 100%; border-left: 0; border-top: 1px solid var(--line); } }

/* --------------------------------------------------------------------------
   Table scroll region — rule 5: the body scrolls inside the frame, the
   header (already sticky, see .table th) stays.
   -------------------------------------------------------------------------- */
.table-scroll { max-height: 60vh; overflow: auto; }

/* --------------------------------------------------------------------------
   Rail sidebar (64px). Ignored below 900px, where the sidebar is already a
   horizontal strip; the class lives on <html> so the inline head script can
   set it before first paint and the rail never flashes.
   -------------------------------------------------------------------------- */
@media (min-width: 901px) {
  html.sidebar-collapsed .layout { grid-template-columns: 64px minmax(0, 1fr); }
  html.sidebar-collapsed .sidebar { padding: 1rem .6rem; align-items: center; }
  html.sidebar-collapsed .nav-list { display: flex; flex-direction: column; align-items: center; width: 100%; }
  html.sidebar-collapsed .sidebar-heading,
  html.sidebar-collapsed .sidebar-note,
  html.sidebar-collapsed .nav-link > span:not(.nav-badge) { display: none; }
  html.sidebar-collapsed .nav-link { position: relative; width: 44px; min-width: 44px; height: 44px; min-height: 44px; padding: 0; margin: 2px 0; justify-content: center; border-left: 0; }
  html.sidebar-collapsed .nav-link.is-active { border-left: 0; }
  html.sidebar-collapsed .nav-badge { position: absolute; top: 4px; right: 4px; width: 9px; min-width: 9px; height: 9px; padding: 0; margin: 0; font-size: 0; line-height: 0; border-radius: 50%; }
  html.sidebar-collapsed .sidebar-foot { width: 100%; display: flex; flex-direction: column; align-items: center; }
  html.sidebar-collapsed .sidebar-foot .inline-form { display: flex; justify-content: center; }
  html.sidebar-collapsed [data-sidebar-toggle] .icon { transform: scaleX(-1); }
}
.sidebar-foot .nav-link--button { display: flex; align-items: center; gap: .7rem; min-height: 42px; padding: .45rem .75rem; border-radius: var(--radius-sm); color: var(--ink-3); }

@media print { .topbar, .sidebar, .demo-badge, .page-actions, .btn { display: none !important; } .layout { grid-template-columns: 1fr; } }
