/* DSR Manager design system: tokens first, then layout, components, pages. */
:root {
  --bg: #f5f6f8; --surface: #fff; --surface-2: #f9fafb; --sunken: #f1f3f6;
  --border: #e3e6eb; --border-strong: #cfd4dc;
  --text: #101828; --text-2: #344054; --muted: #5a6273;
  --accent: #0f766e; --accent-hover: #115e59; --accent-ink: #fff; --accent-soft: #f0fdfa; --accent-line: #99f6e4;
  --danger: #b42318; --danger-hover: #912018; --danger-soft: #fef3f2; --danger-line: #fecdca;
  --ok: #067647; --ok-soft: #ecfdf3; --ok-line: #abefc6;
  --warn: #93370d; --warn-soft: #fffaeb; --warn-line: #fedf89;
  --closing: #fff4e0; --closing-ink: #93370d;
  --ro: #f2f4f7; --ro-ink: #475467; --zebra: #fbfcfd; --hover: #f0fdfa;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px -6px rgba(16, 24, 40, .18), 0 4px 8px -4px rgba(16, 24, 40, .08);
  --ring: 0 0 0 3px rgba(15, 118, 110, .3);
  --r-sm: 6px; --r: 8px; --r-lg: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --topbar-h: 56px; --rownum-w: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --surface: #151b23; --surface-2: #19202a; --sunken: #10151c;
    --border: #2a323d; --border-strong: #3a4452;
    --text: #e8ebf0; --text-2: #c9d0da; --muted: #9aa4b2;
    --accent: #2dd4bf; --accent-hover: #5eead4; --accent-ink: #042f2e; --accent-soft: #042f2e; --accent-line: #134e4a;
    --danger: #f97066; --danger-hover: #fda29b; --danger-soft: #2a1514; --danger-line: #5c2622;
    --ok: #47cd89; --ok-soft: #0f2419; --ok-line: #1f5537;
    --warn: #fdb022; --warn-soft: #2a2010; --warn-line: #5c4512;
    --closing: #2d2212; --closing-ink: #fdb022;
    --ro: #121820; --ro-ink: #a9b2bf; --zebra: #171d26; --hover: #0f2a28;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 1px 3px rgba(0, 0, 0, .5);
    --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .7);
    --ring: 0 0 0 3px rgba(45, 212, 191, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #151b23; --surface-2: #19202a; --sunken: #10151c;
  --border: #2a323d; --border-strong: #3a4452;
  --text: #e8ebf0; --text-2: #c9d0da; --muted: #9aa4b2;
  --accent: #2dd4bf; --accent-hover: #5eead4; --accent-ink: #042f2e; --accent-soft: #042f2e; --accent-line: #134e4a;
  --danger: #f97066; --danger-hover: #fda29b; --danger-soft: #2a1514; --danger-line: #5c2622;
  --ok: #47cd89; --ok-soft: #0f2419; --ok-line: #1f5537;
  --warn: #fdb022; --warn-soft: #2a2010; --warn-line: #5c4512;
  --closing: #2d2212; --closing-ink: #fdb022;
  --ro: #121820; --ro-ink: #a9b2bf; --zebra: #171d26; --hover: #0f2a28;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .7);
  --ring: 0 0 0 3px rgba(45, 212, 191, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); background: var(--bg); color: var(--text); min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; color: var(--text); }
code { font-family: var(--mono); font-size: .92em; background: var(--sunken); border: 1px solid var(--border); padding: 0 5px; border-radius: 4px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: var(--r-sm); }
.skip:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }

/* ---------- top bar ---------- */
.top { position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s4); background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 30px; width: auto; flex: none; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.logo svg { width: 18px; height: 18px; }
.top nav { display: flex; align-items: stretch; height: 100%; gap: var(--s1); margin-left: var(--s3); }
.top nav a { display: inline-flex; align-items: center; gap: 6px; padding: 0 var(--s3); color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.top nav a:hover { color: var(--text); text-decoration: none; }
.top nav a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.top .spacer { flex: 1; }

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: var(--s2); padding: 4px 8px 4px 4px;
  border-radius: 999px; border: 1px solid transparent; user-select: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover, .menu[open] > summary { background: var(--sunken); border-color: var(--border); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12px;
  display: grid; place-items: center; border: 1px solid var(--accent-line); text-transform: uppercase; }
.who-name { font-weight: 500; color: var(--text-2); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 6px; z-index: 40; }
.menu-pop .menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-pop .menu-head b { display: block; color: var(--text); }
.menu-pop a, .menu-pop button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--text-2); background: none; border: 0; font: inherit; text-align: left; cursor: pointer; min-height: 36px; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--sunken); text-decoration: none; color: var(--text); }
.menu-pop form { margin: 0; }
.menu-pop hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---------- layout ---------- */
main { width: 100%; max-width: 1120px; margin: 0 auto; padding: var(--s5) var(--s4) var(--s6); flex: 1; }
main.wide { max-width: none; padding: var(--s3) var(--s4) var(--s3); display: flex; flex-direction: column; min-height: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s5); }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumb { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s5); margin-bottom: var(--s5); box-shadow: var(--shadow-sm); }
.card > h2 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card > h2 svg { color: var(--muted); }
.card.danger-zone > h2 svg { color: var(--danger); }
.table-wrap.open { overflow: visible; }
.check.field { display: flex; min-height: 38px; margin: 0; }
.pop > summary.btn { gap: 4px; }
.pop[open] > summary.btn { background: var(--sunken); }
.ms-list label span { flex: 1; }
.card > h2 + p, .card .lead { margin: 0 0 var(--s4); color: var(--muted); }
.card h3 { font-size: 14px; margin: var(--s5) 0 var(--s3); }
.card.danger-zone { border-color: var(--danger-line); }
.card.danger-zone > h2 { color: var(--danger); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s4); }
.card-head h2 { margin: 0 0 4px; font-size: 16px; }
.card-head p { margin: 0; color: var(--muted); max-width: 70ch; }
.divider { border: 0; border-top: 1px solid var(--border); margin: var(--s5) 0; }

/* ---------- forms ---------- */
label { display: block; }
.field { display: block; margin-bottom: var(--s4); }
.field > span, .field > label > span { display: block; font-weight: 500; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field .help { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: 8px 10px; min-height: 38px; transition: border-color .15s, box-shadow .15s; max-width: 100%; }
input::placeholder { color: var(--muted); opacity: .85; }
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[disabled] { background: var(--sunken); color: var(--muted); cursor: not-allowed; }
.field input, .field select { width: 100%; }
input[type=checkbox], input[type=radio] { min-height: 0; width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex: none; }
input[type=file] { padding: 6px; background: var(--surface-2); border-style: dashed; cursor: pointer; }
input[type=file]::file-selector-button { font: inherit; font-weight: 500; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: var(--r-sm); padding: 4px 10px; margin-right: 10px; cursor: pointer; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 32px; }
.choice-group { display: flex; flex-wrap: wrap; gap: var(--s2); }
.choice { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r); cursor: pointer;
  flex: 1 1 220px; background: var(--surface); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 2px; }
.choice b { display: block; font-weight: 600; }
.choice small { color: var(--muted); }

button, .btn { font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px;
  padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer;
  white-space: nowrap; transition: background .15s, border-color .15s, color .15s, box-shadow .15s; text-decoration: none; }
button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
button:disabled { opacity: .6; cursor: progress; }
.ghost, button.ghost, .btn.ghost { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.ghost:hover, button.ghost:hover, .btn.ghost:hover { background: var(--sunken); color: var(--text); border-color: var(--border-strong); }
button.danger, .btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger-line); }
button.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
button.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
button.danger.solid:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
button.quiet { background: none; border-color: transparent; color: var(--muted); box-shadow: none; }
button.quiet:hover { background: var(--sunken); color: var(--text); border-color: transparent; }
/* theme toggle: show the icon of the theme you'd switch to */
.theme-btn .i-moon { display: none; }
.theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .i-sun { display: none; }
  :root:not([data-theme="light"]) .theme-btn .i-moon { display: block; }
}
.auth-theme { position: fixed; top: 12px; right: 12px; z-index: 50; }
button.small, .btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
button.icon { width: 38px; padding: 0; }
button.icon.small { width: 30px; }
.row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.row + .row { margin-top: var(--s3); }
.actions-bar { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-top: var(--s4); }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--s3) var(--s4); align-items: end; }
.form-grid .field { margin: 0; }

/* ---------- badges, flashes ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; line-height: 1; padding: 4px 8px; border-radius: 999px;
  background: var(--sunken); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.blue { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.badge.green { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.badge.amber { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.flashes { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.flash { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px 10px 14px; border-radius: var(--r); border: 1px solid var(--accent-line);
  background: var(--accent-soft); color: var(--text); }
.flash .msg { flex: 1; padding-top: 4px; overflow-wrap: anywhere; }
.flash.ok { background: var(--ok-soft); border-color: var(--ok-line); }
.flash.ok > svg { color: var(--ok); }
.flash.error { background: var(--danger-soft); border-color: var(--danger-line); }
.flash.error > svg { color: var(--danger); }
.flash.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.flash.warn > svg { color: var(--warn); }
.flash > svg { margin-top: 6px; color: var(--accent); }
.flash .x { min-height: 28px; width: 28px; padding: 0; background: none; border: 0; color: var(--muted); box-shadow: none; }
.flash .x:hover { background: rgba(0, 0, 0, .06); color: var(--text); }
.flash.out { opacity: 0; transform: translateY(-4px); transition: .2s; }
main.wide .flashes { margin-bottom: var(--s3); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r); }
table.list { border-collapse: collapse; width: 100%; }
table.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover td { background: var(--surface-2); }
.uname { font-weight: 600; color: var(--text); }
.sub { display: block; font-size: 12px; color: var(--muted); }
.cell-actions { text-align: right; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }

/* switch-style toggle (a submit button with aria-pressed) */
.switch { width: 40px; min-height: 22px; height: 22px; padding: 0; border-radius: 999px; background: var(--border-strong); border: 0; position: relative; box-shadow: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: var(--shadow); }
.switch[aria-pressed="true"] { background: var(--ok); }
.switch[aria-pressed="true"]::after { left: 21px; }
.switch:hover { background: var(--muted); }
.switch[aria-pressed="true"]:hover { background: var(--ok); filter: brightness(1.1); }

/* per-row popover (users table) */
.pop { position: relative; display: inline-block; }
.pop > summary { list-style: none; }
.pop > summary::-webkit-details-marker { display: none; }
.pop-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 25; width: 290px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg); padding: var(--s4); text-align: left; white-space: normal; }
.pop-body h4 { margin: 0 0 var(--s3); font-size: 13px; }
.pop-body form { display: block; }
.pop-body .field { margin-bottom: var(--s3); }
.pop-body hr { border: 0; border-top: 1px solid var(--border); margin: var(--s4) 0; }

/* ---------- auth pages ---------- */
body.auth { background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg); }
body.auth main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding-top: var(--s6); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: var(--s6); margin: 0 auto; }
.auth-card .logo { width: 44px; height: 44px; border-radius: 12px; margin-bottom: var(--s4); }
.auth-card .auth-logo { height: 42px; width: auto; margin-bottom: var(--s4); }
.auth-card .logo svg { width: 24px; height: 24px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.01em; }
.auth-card .lead { margin: 0 0 var(--s5); color: var(--muted); }
.auth-card button[type=submit], .auth-card .block { width: 100%; min-height: 42px; margin-top: var(--s2); }
.auth-card .flashes { width: 100%; }
.auth-foot { margin-top: var(--s5); text-align: center; font-size: 12px; color: var(--muted); }
main > .flashes { max-width: 1120px; }
body.auth main > .flashes { width: 100%; max-width: 400px; }
.err-code { font-size: 13px; font-weight: 600; color: var(--accent); letter-spacing: .05em; text-transform: uppercase; margin-bottom: 6px; }

/* ---------- sheet ---------- */
.toolbar { display: flex; gap: var(--s2) var(--s3); align-items: center; flex-wrap: wrap; margin-bottom: var(--s3); }
.seg { display: inline-flex; padding: 3px; background: var(--sunken); border: 1px solid var(--border); border-radius: var(--r); gap: 2px; }
.seg button { background: none; border: 0; color: var(--muted); min-height: 32px; padding: 0 12px; border-radius: var(--r-sm); box-shadow: none; }
.seg button:hover { color: var(--text); background: none; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg .count { font-size: 12px; font-weight: 600; min-width: 22px; padding: 1px 6px; border-radius: 999px; background: var(--border); color: var(--text-2); }
.seg button[aria-selected="true"] .count { background: var(--accent-soft); color: var(--accent); }
.search { position: relative; flex: 1 1 240px; max-width: 380px; }
.search > svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { width: 100%; padding-left: 34px; padding-right: 34px; }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.shown { font-size: 13px; color: var(--muted); white-space: nowrap; }
.toolbar .grow { flex: 1; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; padding: 5px 10px; border-radius: 999px;
  background: var(--sunken); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.status .dot { width: 8px; height: 8px; }
.status.ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-line); }
.status.busy { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.status.busy .dot { animation: pulse 1s infinite; }
.status.bad { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-line); }
@keyframes pulse { 50% { opacity: .3; } }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); font-size: 12px; color: var(--muted); margin: 0 0 var(--s2); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border-strong); vertical-align: -2px; margin-right: 4px; }
.sw.edit { background: var(--surface); border-color: var(--accent); }
.sw.ro { background: var(--ro); }
.sw.close { background: var(--closing); border-color: var(--warn-line); }
.legend .tip { margin-left: auto; }
kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }

/* the sheet page is exactly one screen tall, so the grid (not the page) scrolls and its header row stays visible */
body.sheet-page { height: 100vh; height: 100dvh; }
.grid-wrap { position: relative; flex: 1 1 auto; min-height: 260px; overflow: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overscroll-behavior: contain;
  scroll-padding: 72px 0 0 calc(var(--rownum-w) + 150px); /* app.js sets the exact sizes of the sticky header/columns */ }
#grid { border-collapse: separate; border-spacing: 0; font-size: 13px; }
#grid th, #grid td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 0; }
#grid thead th { position: sticky; top: 0; z-index: 3; background: var(--surface-2); padding: 8px 10px 7px; min-width: 140px; max-width: 240px;
  text-align: left; vertical-align: bottom; font-weight: 600; font-size: 12px; color: var(--text); border-bottom: 1px solid var(--border-strong); }
#grid thead th .h { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
#grid thead th .o { display: block; margin-top: 4px; font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#grid thead th.mine { box-shadow: inset 0 3px 0 var(--accent); }
#grid thead th.mine .o { color: var(--accent); }
#grid thead th.ro .h { color: var(--text-2); }
#grid thead th.lastcol { background: var(--closing); }
#grid thead th.lastcol .o::before { content: "Closes job · "; color: var(--closing-ink); }
#grid .rownum { position: sticky; left: 0; z-index: 2; width: var(--rownum-w); min-width: var(--rownum-w); max-width: var(--rownum-w); text-align: center;
  color: var(--muted); background: var(--surface-2); font-size: 12px; font-variant-numeric: tabular-nums; padding: 0 4px; }
#grid thead .rownum { z-index: 5; text-align: center; }
#grid .key { position: sticky; left: var(--rownum-w); z-index: 2; box-shadow: 2px 0 0 var(--border-strong); }
#grid thead th.key { z-index: 4; }
#grid tbody td.key, #grid tbody td.key input { font-weight: 600; }
#grid tbody td { background: var(--surface); height: 36px; }
#grid tbody tr:nth-child(even) td { background: var(--zebra); }
#grid tbody td.ro, #grid tbody tr:nth-child(even) td.ro { background: var(--ro); color: var(--ro-ink); padding: 0 10px; max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#grid tbody tr:nth-child(even) td.rownum, #grid tbody td.rownum { background: var(--surface-2); }
#grid tbody tr:hover td { background: var(--hover); }
#grid td input { display: block; border: 0; border-radius: 0; width: 100%; min-width: 140px; min-height: 36px; padding: 0 10px; background: transparent;
  color: var(--text); font-size: 13px; text-overflow: ellipsis; box-shadow: none; transition: none; }
#grid td input:hover { background: var(--accent-soft); }
#grid td input:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface); box-shadow: none; text-overflow: clip; }
#grid td.lastcol input { background: color-mix(in srgb, var(--closing) 60%, transparent); }
#grid tbody td.saving { background: var(--accent-soft) !important; }
#grid tbody td.saved { background: var(--ok-soft) !important; transition: background 1s; }
#grid tbody td.error { background: var(--danger-soft) !important; position: relative; box-shadow: inset 0 0 0 1px var(--danger); }
#grid tbody td.error::after { content: "!"; position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; pointer-events: none; }
#grid tbody td.error input { padding-right: 28px; }
#grid .rowact { position: sticky; right: 0; z-index: 2; padding: 0 6px; white-space: nowrap; min-width: 0; width: 1%; box-shadow: -2px 0 0 var(--border); }
#grid thead th.rowact { z-index: 4; min-width: 0; }
#grid .rowact button { min-height: 28px; height: 28px; }
#grid .rowact .row { flex-wrap: nowrap; gap: 4px; }
#grid tr[hidden] { display: none; }
#grid td.empty-row { padding: 0; }
.empty { text-align: center; padding: 48px 24px; color: var(--muted); max-width: 480px; margin: 0 auto; }
.empty .ill { width: 48px; height: 48px; border-radius: 12px; background: var(--sunken); border: 1px solid var(--border); display: grid; place-items: center;
  margin: 0 auto var(--s3); color: var(--muted); }
.empty .ill svg { width: 22px; height: 22px; }
.empty h2, .empty h3 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.empty p { margin: 0 0 var(--s4); }
.grid-wrap .empty { position: sticky; left: 0; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px; color: var(--muted); }
.loading[hidden] { display: none; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.sm { width: 14px; height: 14px; border-color: color-mix(in srgb, currentColor 35%, transparent); border-top-color: currentColor; }
#grid tbody tr.new td { animation: flash-new 2s ease-out; }
@keyframes flash-new { from { background: var(--accent-soft); } }
#grid tbody td.lastcol.ro { background: color-mix(in srgb, var(--closing) 70%, var(--ro)); }

/* ---------- toasts & dialog ---------- */
.toasts { position: fixed; z-index: 60; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  max-width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px 10px 14px; border-radius: var(--r);
  background: #111827; color: #f9fafb; box-shadow: var(--shadow-lg); font-weight: 500; animation: toast-in .18s ease-out; }
.toast > svg { margin-top: 2px; color: #4ade80; }
.toast span { overflow-wrap: anywhere; user-select: text; }
.toast .x { min-height: 24px; width: 24px; padding: 0; margin: -2px -4px 0 0; background: none; border: 0; color: inherit; opacity: .8; }
.toast .x:hover { background: rgba(127, 127, 127, .25); opacity: 1; }
.toast .x svg { margin: 0; }
.toast.bad { background: #7a1a12; }
.toast.bad > svg { color: #fecaca; }
.toast.out { opacity: 0; transform: translateY(6px); transition: .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast { background: #f3f4f6; color: #111827; } :root:not([data-theme="light"]) .toast > svg { color: #067647; } :root:not([data-theme="light"]) .toast.bad { background: #fee4e2; color: #7a1a12; } :root:not([data-theme="light"]) .toast.bad > svg { color: #b42318; } }
:root[data-theme="dark"] .toast { background: #f3f4f6; color: #111827; } :root[data-theme="dark"] .toast > svg { color: #067647; } :root[data-theme="dark"] .toast.bad { background: #fee4e2; color: #7a1a12; } :root[data-theme="dark"] .toast.bad > svg { color: #b42318; }

dialog.confirm { border: 1px solid var(--border); border-radius: var(--r-lg); padding: 0; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); }
dialog.confirm::backdrop { background: rgba(16, 24, 40, .45); }
dialog.confirm form { margin: 0; padding: var(--s5); }
dialog.confirm .dlg-head { display: flex; gap: var(--s3); align-items: flex-start; }
dialog.confirm .dlg-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); }
dialog.confirm.danger .dlg-icon { background: var(--danger-soft); color: var(--danger); }
dialog.confirm .dlg-icon svg { width: 20px; height: 20px; }
dialog.confirm h2 { margin: 0 0 6px; font-size: 16px; }
dialog.confirm p { margin: 0; color: var(--text-2); overflow-wrap: anywhere; white-space: pre-line; }
dialog.confirm .dlg-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }

/* ---------- admin ---------- */
.subnav { position: sticky; top: var(--topbar-h); z-index: 20; display: flex; gap: 4px; overflow-x: auto; margin: 0 calc(-1 * var(--s4)) var(--s5);
  padding: 8px var(--s4); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); }
.subnav a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.subnav a:hover { background: var(--sunken); color: var(--text); text-decoration: none; }
.subnav a.on { background: var(--accent-soft); color: var(--accent); }
section[id] { scroll-margin-top: calc(var(--topbar-h) + 64px); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); margin-bottom: var(--s5); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow-sm); }
.stat b { display: block; font-size: 22px; font-weight: 700; letter-spacing: -.02em; color: var(--text); font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.warn b { color: var(--warn); }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s5); }
.split > .card { margin-bottom: 0; }
.tile-link { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border: 1px solid var(--border); border-radius: var(--r);
  color: var(--text); background: var(--surface-2); }
.tile-link:hover { border-color: var(--accent-line); background: var(--accent-soft); text-decoration: none; }
.tile-link .sub { margin-top: 2px; }
.tile-link > svg:last-child { margin-left: auto; color: var(--muted); }
.created { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.colgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 2px var(--s3); max-height: 440px; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--r); padding: var(--s2); background: var(--surface-2); }
.colgrid label { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border-radius: var(--r-sm); cursor: pointer; font-size: 13px; }
.colgrid label:hover { background: var(--surface); }
.colgrid label input { margin-top: 2px; }
.colgrid .letter { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 22px; padding-top: 1px; }
.colgrid .sub { font-size: 11px; }
.filter-row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s3); }
.filter-row .search { max-width: 320px; }
.logwrap { max-height: 480px; overflow: auto; border: 1px solid var(--border); border-radius: var(--r); }
.logwrap table.list th { position: sticky; top: 0; z-index: 1; }
.logwrap td { font-size: 13px; }
.logwrap td.when { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.log-detail { overflow-wrap: anywhere; color: var(--text-2); }
.log-detail .old { color: var(--muted); text-decoration: line-through; }
.kv { color: var(--muted); }
.kv b { color: var(--text-2); font-weight: 500; }
.upload-row { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); align-items: center; }
.upload-row input[type=file] { width: 100%; }
.danger-text { color: var(--danger); }

/* columns editor */
.col-table td { padding: 8px 10px; }
.col-table td.letter { font-family: var(--mono); font-weight: 600; color: var(--muted); width: 56px; }
.col-table td.letter .badge { margin-top: 4px; }
.col-table td.head input { width: 100%; min-width: 220px; }
.col-table td.owner { width: 38%; }
.col-table td.del { width: 48px; text-align: right; }
.col-table tr.lastcol td { background: var(--closing); }
.col-table tr.dirty td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.col-table tr.dirty td.letter { color: var(--accent); }
.col-table tr[hidden] { display: none; }
.savebar { position: sticky; bottom: 0; z-index: 15; display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; margin: var(--s4) calc(-1 * var(--s5)) calc(-1 * var(--s5));
  padding: var(--s3) var(--s5); background: var(--surface); border-top: 1px solid var(--border); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.savebar.dirty { background: var(--accent-soft); border-top-color: var(--accent-line); }
.savebar .grow { flex: 1; }
.savebar .dirty-msg { font-weight: 500; color: var(--accent); }

/* owner multi-select */
details.ms { position: relative; min-width: 200px; }
details.ms > summary { list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 38px; padding: 4px 32px 4px 6px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); position: relative; }
details.ms > summary::-webkit-details-marker { display: none; }
details.ms > summary::after { content: ""; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px; border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted); transform: translateY(-70%) rotate(45deg); transition: transform .15s; }
details.ms[open] > summary::after { transform: translateY(-30%) rotate(-135deg); }
details.ms > summary:hover { border-color: var(--muted); }
details.ms[open] > summary, details.ms > summary:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; padding: 3px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); white-space: nowrap; }
.chip.none { background: var(--sunken); color: var(--muted); border-color: var(--border); }
.ms-pop { position: absolute; z-index: 25; left: 0; top: calc(100% + 4px); width: max(100%, 280px); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg); overflow: hidden; }
.ms-search { padding: 8px; border-bottom: 1px solid var(--border); }
.ms-search input { width: 100%; min-height: 34px; }
.ms-list { max-height: 260px; overflow: auto; padding: 4px; }
.ms-list label { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: var(--r-sm); cursor: pointer; }
.ms-list label:hover, .ms-list label:focus-within { background: var(--sunken); }
.ms-list label:has(input:checked) { background: var(--accent-soft); }
.ms-list label small { color: var(--muted); margin-left: auto; }
.ms-list label[hidden] { display: none; }
.ms-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px; border-top: 1px solid var(--border); background: var(--surface-2);
  font-size: 12px; color: var(--muted); }
.ms-empty { padding: 12px; color: var(--muted); text-align: center; font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .who-name, .top .role-badge { display: none; }
  .top { gap: var(--s2); padding: 0 var(--s3); }
  .top nav { margin-left: 0; }
  .top nav a { padding: 0 var(--s2); }
  .brand .brand-text { display: none; }
  main { padding: var(--s4) var(--s3) var(--s5); }
  main.wide { padding: var(--s2) var(--s2) var(--s2); }
  .card { padding: var(--s4); border-radius: var(--r); }
  .savebar { margin: var(--s4) calc(-1 * var(--s4)) calc(-1 * var(--s4)); padding: var(--s3) var(--s4); }
  .subnav { margin: calc(-1 * var(--s4)) calc(-1 * var(--s3)) var(--s4); padding: 8px var(--s3); }
  .search { max-width: none; order: 5; flex-basis: 100%; }
  .toolbar .grow { display: none; }
  .legend .tip { display: none; }
  .auth-card { padding: var(--s5); }
  .upload-row { grid-template-columns: 1fr; }
  /* stacked card tables */
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: auto; }
  table.stack thead { display: none; }
  table.stack tr { border-bottom: 1px solid var(--border); padding: var(--s3); position: relative; }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { border: 0; padding: 4px 0; display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
  table.stack td[data-label]::before { content: attr(data-label); font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
  table.stack td.cell-actions { justify-content: flex-end; padding-top: var(--s2); }
  table.stack td[data-label]::before { white-space: nowrap; flex: none; }
  table.stack td.who { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding-bottom: var(--s2); }
  table.stack td.who .uname { font-size: 15px; }
  table.stack form.inline input { width: 140px; }
  .savebar .dirty-msg { flex-basis: 100%; font-size: 13px; }
  .savebar .grow { display: none; }
  .savebar button[name=save] { flex: 1; }
  #grid { --rownum-w: 40px; }
  table.stack tbody tr:hover td { background: none; }
  .users-table .pop-body { right: 0; width: min(300px, calc(100vw - 48px)); }
  .col-table td { display: block !important; }
  .col-table td.letter { width: auto; display: flex !important; justify-content: flex-start !important; gap: 8px; }
  .col-table td.head input { min-width: 0; }
  .col-table td.owner, .col-table td.del { width: auto; }
  .col-table td.del { position: absolute; top: var(--s2); right: var(--s3); padding: 0; }
  .col-table td[data-label]::before { display: block; margin-bottom: 4px; }
  .col-table tr.lastcol { background: var(--closing); }
  .col-table tr.lastcol td { background: none; }
}
@media (pointer: coarse) {
  input, select, textarea, #grid td input { font-size: 16px; }
  #grid td input, #grid tbody td { min-height: 44px; height: 44px; }
  button.small, .btn.small { min-height: 36px; padding: 0 12px; }
  button.icon.small { width: 36px; }
  #grid .rowact button { min-height: 36px; height: 36px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
:root[data-theme="dark"] .brand-logo, :root[data-theme="dark"] .auth-logo { background: #fff; border-radius: 6px; padding: 2px 6px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-logo, :root:not([data-theme="light"]) .auth-logo { background: #fff; border-radius: 6px; padding: 2px 6px; } }
