:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5b6577;
  --border: #dfe3ea;
  --accent: #2563eb;
  --ok: #157f3b;      --ok-bg: #e3f5e9;
  --bad: #b42318;     --bad-bg: #fde8e7;
  --busy: #8a5a00;    --busy-bg: #fff2cc;
  --plain: #4b5565;   --plain-bg: #eef1f5;
  --info: #1d4ed8;    --info-bg: #e3ecff;
  --gold: #7a4d00;    --gold-bg: #fdecc8;
  --scroll-thumb: #c4cad4;
  color-scheme: light;
}
/* Dark colors: when the device prefers dark (theme Auto), or when Dark is chosen in the header. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151c;
    --surface: #1a2029;
    --text: #e6e9ef;
    --muted: #9aa4b5;
    --border: #2c3442;
    --accent: #7aa7ff;
    --ok: #6fd897;      --ok-bg: #173523;
    --bad: #ff8f86;     --bad-bg: #3d1a18;
    --busy: #f2c75c;    --busy-bg: #3a2f12;
    --plain: #b8c0cc;   --plain-bg: #262d38;
    --info: #9dbcff;    --info-bg: #1c2a47;
    --gold: #f5c66b;    --gold-bg: #3b2c10;
    --scroll-thumb: #3a4352;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11151c;
  --surface: #1a2029;
  --text: #e6e9ef;
  --muted: #9aa4b5;
  --border: #2c3442;
  --accent: #7aa7ff;
  --ok: #6fd897;      --ok-bg: #173523;
  --bad: #ff8f86;     --bad-bg: #3d1a18;
  --busy: #f2c75c;    --busy-bg: #3a2f12;
  --plain: #b8c0cc;   --plain-bg: #262d38;
  --info: #9dbcff;    --info-bg: #1c2a47;
  --gold: #f5c66b;    --gold-bg: #3b2c10;
  --scroll-thumb: #3a4352;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Scrollbars in the page's colors (native controls follow color-scheme; the thumb uses the tokens). */
* { scrollbar-color: var(--scroll-thumb) transparent; }
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }

.top { flex: none; background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; height: 52px; }
.brand { font-weight: 650; color: var(--text); font-size: 15px; }
nav { display: flex; gap: 4px; }
nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
nav a:hover { text-decoration: none; background: var(--plain-bg); }
nav a.active { color: var(--text); background: var(--plain-bg); font-weight: 600; }
.theme { margin-left: auto; font: inherit; font-size: 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; cursor: pointer; }
.user { margin-left: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sign-out { margin-left: 16px; }

/* The header and footer stay put; only main scrolls. Side padding centers the content in up to 1280px. */
main { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 20px max(16px, calc((100% - 1248px) / 2)) 24px; }
/* A page whose table scrolls inside its panel (add class "fill" to main), with headings and pager in view. */
main.fill { display: flex; flex-direction: column; overflow: hidden; }
main.fill > .panel { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; }
main.fill .table-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; }
main.fill thead th { position: sticky; top: 0; z-index: 1; box-shadow: inset 0 -1px 0 var(--border); }

.foot { flex: none; background: var(--surface); border-top: 1px solid var(--border); }
.foot-inner { max-width: 1280px; margin: 0 auto; padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 12px 48px; font-size: 13px; }
.foot-inner:empty { display: none; }
.foot-item .subtle { font-size: 12px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.message { padding: 32px; text-align: center; color: var(--muted); }
.subtle { color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.filters select, .filters input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; min-width: 150px;
}
.filters input { min-width: 220px; }
button {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover:not(:disabled) { background: var(--plain-bg); }
button:disabled { opacity: .45; cursor: default; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; background: var(--surface); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--plain-bg) 55%, transparent); }
tbody tr.highlight td { background: color-mix(in srgb, var(--accent) 16%, transparent); }
td.nowrap, th.nowrap { white-space: nowrap; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pager div { display: flex; gap: 8px; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.pill.busy { color: var(--busy); background: var(--busy-bg); }
.pill.plain { color: var(--plain); background: var(--plain-bg); }
.pill.info { color: var(--info); background: var(--info-bg); }
.pill.gold { color: var(--gold); background: var(--gold-bg); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.links { display: flex; gap: 10px; white-space: nowrap; }

.card { padding: 16px 18px; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }



@media (max-width: 640px) {
  .top-inner { gap: 12px; }
  .user { display: none; }
  .filters input, .filters select { min-width: 0; width: 100%; }
  .filters label { flex: 1 1 140px; }
}

/* ---------- Shell (header tabs) and Home */
.brand { display: flex; align-items: center; gap: 8px; }
.brand svg { width: 20px; height: 20px; flex: none; }
nav { overflow-x: auto; scrollbar-width: none; }
nav a { white-space: nowrap; }

.stack { display: grid; gap: 16px; max-width: 860px; }
.checks { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.checks li { display: flex; gap: 8px; align-items: baseline; }
.checks .mark { width: 18px; text-align: center; font-weight: 700; flex: none; }
.checks .yes { color: var(--ok); }
.checks .no { color: var(--bad); }
details.more { margin-top: 12px; color: var(--muted); }
details.more summary { cursor: pointer; }
details.more code { overflow-wrap: anywhere; }
.message h2 { color: var(--text); }
button.link { border: 0; padding: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }

/* ---------- Forms and Admin */
.stack.wide { max-width: none; }
.subnav { display: flex; gap: 4px; overflow: visible; }
.subnav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.subnav a.active { color: var(--text); background: var(--surface); border: 1px solid var(--border); font-weight: 600; }
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); max-width: 420px; }
.field input, .filters input[type="month"] {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
fieldset.roles { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 0; display: grid; gap: 6px; }
fieldset.roles legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.role-option { display: flex; gap: 8px; align-items: baseline; cursor: pointer; }
.role-option input { flex: none; }
.role-option input:disabled + span { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, black); }
:root[data-theme="dark"] button.primary { color: #0b1220; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) button.primary { color: #0b1220; } }
.form-status { font-size: 13px; color: var(--muted); }
.form-status.bad { color: var(--bad); }
button.link.danger { color: var(--bad); }
button.link.small { font-size: 12px; margin-left: 6px; }
.plain-list { margin: 0; padding-left: 18px; }
dl.roles-list dd { margin-bottom: 6px; }
.bad-text { color: var(--bad); }
