:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #16181d;
  --muted: #646a75;
  --line: #e2e5ea;
  --accent: #0a66d8;
  --accent-ink: #ffffff;
  --danger: #c62828;
  --pending-bg: #fff4d6; --pending-fg: #8a5a00;
  --active-bg: #e3f5e8;  --active-fg: #1d6b34;
  --disabled-bg: #f1f2f4; --disabled-fg: #6b7079;
  --admin-bg: #e8eefc;   --admin-fg: #2846a8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1d2128;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --line: #2a2f38;
    --accent: #4b93f0;
    --danger: #ef6a6a;
    --pending-bg: #3a2f12; --pending-fg: #f3c766;
    --active-bg: #163121;  --active-fg: #7fd69a;
    --disabled-bg: #24282f; --disabled-fg: #9aa1ad;
    --admin-bg: #1c2747;   --admin-fg: #9db4f5;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; margin-bottom: 12px; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Header */
.top {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 800; font-size: 19px;
}
.project { margin: 0; color: var(--muted); font-size: 12px; }
.project.demo { color: var(--pending-fg); }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs button {
  border: 0; background: none; padding: 8px 14px; border-radius: 8px;
  color: var(--muted); font-weight: 600; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }

.banner {
  padding: 10px 14px; border-radius: 10px; margin-bottom: 16px;
  background: var(--pending-bg); color: var(--pending-fg); font-weight: 500;
}
.banner.error { background: #fde8e8; color: var(--danger); }
@media (prefers-color-scheme: dark) { .banner.error { background: #3a1717; } }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow); text-align: left; cursor: pointer;
}
.stat:hover { border-color: var(--accent); }
.stat .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }
.stat.attention .n { color: var(--pending-fg); }

/* Toolbar */
.toolbar, .bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.spacer { flex: 1; }
input[type="search"], input[type="text"], input[type="email"], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-height: 36px;
}
input[type="search"] { min-width: 240px; flex: 0 1 320px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.bulk { background: var(--admin-bg); color: var(--admin-fg); border-radius: 10px; padding: 8px 12px; font-weight: 600; }

button.primary, button.ghost {
  border-radius: 8px; padding: 0 14px; min-height: 36px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
button.primary { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
button.ghost { background: var(--surface); border: 1px solid var(--line); }
button.ghost:hover { border-color: var(--muted); }
button.danger.primary { background: var(--danger); border-color: var(--danger); }
button.danger.ghost { color: var(--danger); }
button.link { border: 0; background: none; color: inherit; text-decoration: underline; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: ""; margin-left: 4px; }
th.sorted-asc::after { content: "▲"; font-size: 9px; }
th.sorted-desc::after { content: "▼"; font-size: 9px; }
th.check, td.check { width: 36px; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.selected { background: var(--admin-bg); }
.who strong { display: block; }
.who small, .when small { color: var(--muted); }
.when { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { min-height: 30px; padding: 0 10px; font-size: 13px; }
.empty { padding: 30px; text-align: center; color: var(--muted); margin: 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.pending { background: var(--pending-bg); color: var(--pending-fg); }
.badge.active { background: var(--active-bg); color: var(--active-fg); }
.badge.disabled { background: var(--disabled-bg); color: var(--disabled-fg); }
.badge.admin { background: var(--admin-bg); color: var(--admin-fg); }
.badge.user { background: transparent; color: var(--muted); padding-left: 0; }
.tag { font-size: 11px; color: var(--muted); margin-left: 6px; }

/* Settings */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); max-width: 760px; }
.card.muted { background: var(--surface-2); }
.switch-row { display: flex; gap: 20px; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.switch-row:first-of-type { border-top: 0; }
.switch-row small { display: block; color: var(--muted); margin-top: 2px; }
.switch { appearance: none; width: 44px; height: 26px; border-radius: 999px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s; }
.switch:checked { background: #2e9d52; }
.switch:checked::after { left: 21px; }
.legend { display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; margin: 0; }
.legend dd { margin: 0; color: var(--muted); }

/* Audit */
table.audit td { font-size: 13px; }
.details { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* Dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 14, 22, .45); }
dialog form { padding: 22px; display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
dialog label input, dialog label select, dialog label textarea { font-weight: 400; width: 100%; }
dialog .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; margin: 0; }
legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
label.radio { display: flex; gap: 8px; align-items: center; font-weight: 400; padding: 3px 0; }
label.radio input { width: auto; }
.with-button { display: flex; gap: 8px; }
.facts { font-size: 12px; color: var(--muted); display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.facts span:nth-child(odd) { font-weight: 600; }
.form-error { color: var(--danger); margin: 0; font-weight: 500; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
#confirm-text { margin: 0; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  .top { padding: 12px 16px; gap: 12px; }
  .tabs { margin-left: 0; width: 100%; }
  main { padding: 16px; }
  input[type="search"] { min-width: 0; flex: 1 1 100%; }
  th:nth-child(5), td:nth-child(5) { display: none; }
  dialog .two { grid-template-columns: 1fr; }
}

/* Activity */
.hint { color: var(--muted); margin: 0 0 12px; max-width: 760px; }
dialog.wide { width: min(820px, calc(100vw - 32px)); }
dialog h3 { margin: 6px 0 0; font-size: 13px; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 210px 1fr 120px; gap: 10px; align-items: center; font-size: 13px; }
.bar .track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.log-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table.log td { padding: 6px 10px; font-size: 12px; }
table.log td.n { text-align: right; font-variant-numeric: tabular-nums; }
th[data-asort] { cursor: pointer; }
@media (max-width: 720px) { .bar { grid-template-columns: 1fr 80px; } .bar .track { grid-column: 1 / -1; } }

/* Flights */
table.matrix th.user { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; text-align: left; height: 150px; vertical-align: bottom; padding: 8px 6px; }
table.matrix td.tick { text-align: center; width: 34px; padding: 6px; }
table.matrix td.tick input { width: 18px; height: 18px; cursor: pointer; }
table.matrix td.pack small { display: block; color: var(--muted); }
table.matrix .demo-tag { font-size: 11px; color: var(--admin-fg); background: var(--admin-bg); border-radius: 999px; padding: 1px 7px; margin-left: 6px; }

/* Activity, in detail. Steps take the first six categorical slots in a fixed
   order; the heat map is one blue ramp, light → dark (dark mode: dark →
   light, so "nothing" recedes into the surface either way). */
:root {
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
  --h0: #cde2fb; --h1: #9ec5f4; --h2: #5598e7; --h3: #256abf; --h4: #104281;
}
@media (prefers-color-scheme: dark) {
  :root {
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
    --h0: #0d366b; --h1: #184f95; --h2: #256abf; --h3: #3987e5; --h4: #86b6ef;
  }
}
.s1 { --c: var(--s1); } .s2 { --c: var(--s2); } .s3 { --c: var(--s3); }
.s4 { --c: var(--s4); } .s5 { --c: var(--s5); } .s6 { --c: var(--s6); }
.c1 { --c: var(--s1); } .c2 { --c: var(--s2); } .c3 { --c: var(--s3); }
.c4 { --c: var(--s4); } .c5 { --c: var(--s5); } .c6 { --c: var(--s6); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 0; }
.muted { color: var(--muted); }

.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.stat.static { cursor: default; }
.stat.static:hover { border-color: var(--line); }
.stats.compact { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 0; }
.stats.compact .stat { padding: 9px 11px; box-shadow: none; background: var(--surface-2); }
.stats.compact .n { font-size: 16px; }

.card.wide-card { max-width: none; padding: 16px 18px; }
.card-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.table-wrap.flat { border: 0; box-shadow: none; border-radius: 0; margin: 0 -18px -16px; }
.legend-row { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.scale { display: inline-flex; gap: 3px; align-items: center; font-size: 12px; color: var(--muted); }
.scale .cell { display: inline-block; width: 14px; height: 14px; }

/* Heat map */
.heat-wrap { overflow-x: auto; padding-bottom: 4px; }
.heat { display: grid; gap: 3px; align-items: center; width: max-content; }
.heat .hd { font-size: 10px; color: var(--muted); white-space: nowrap; height: 14px; overflow: visible; }
.heat .hd.we, .days .tick.we { color: var(--text); opacity: .55; }
.heat button.who { border: 0; background: none; text-align: left; padding: 2px 10px 2px 0; cursor: pointer; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.heat button.who:hover { color: var(--accent); }
.cell { width: 18px; height: 18px; border-radius: 4px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.cell.l0 { background: var(--h0); box-shadow: none; } .cell.l1 { background: var(--h1); box-shadow: none; }
.cell.l2 { background: var(--h2); box-shadow: none; } .cell.l3 { background: var(--h3); box-shadow: none; }
.cell.l4 { background: var(--h4); box-shadow: none; }

/* Table */
tr.dim td { color: var(--muted); }
tr.dim td.who strong { font-weight: 500; }
table.activity tbody tr { cursor: pointer; }
.meter { display: inline-block; width: 54px; height: 6px; border-radius: 999px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line);
  vertical-align: middle; margin-right: 6px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.steps-cell { min-width: 160px; }
.stack { display: flex; gap: 2px; height: 10px; width: 100%; min-width: 140px; }
.stack .seg { background: var(--c); border-radius: 2px; min-width: 3px; }
.stack .seg:first-child { border-radius: 4px 2px 2px 4px; }
.stack .seg:last-child { border-radius: 2px 4px 4px 2px; }

/* The detail */
dialog.xl { width: min(1080px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
dialog.xl form { max-height: calc(100vh - 42px); overflow: auto; gap: 10px; }
.dialog-head { display: flex; gap: 8px; align-items: flex-start; position: sticky; top: -22px; background: var(--surface);
  margin: -22px -22px 0; padding: 18px 22px 10px; z-index: 2; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
dialog.xl h3 { margin-top: 14px; }
dialog.xl h3 small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.note { margin: 0; padding: 9px 12px; border-radius: 8px; background: var(--pending-bg); color: var(--pending-fg); font-size: 13px; }

.days { display: grid; gap: 3px; height: 130px; align-items: end; }
.day { display: grid; grid-template-rows: 1fr 16px; height: 100%; min-width: 0; }
.day .col { display: flex; align-items: flex-end; height: 100%; border-bottom: 1px solid var(--line); }
.bar-v { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; position: relative; }
.bar-v span { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--text); white-space: nowrap; padding-bottom: 2px; }
.day .tick { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: visible; padding-top: 2px; }
.day:hover .col { background: var(--surface-2); }

.cover { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.cover .group { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.cover h4 { margin: 0 0 6px; font-size: 12px; }
.cover ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.cover li { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.cover li small { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cover li.never span { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.cover li.never small { color: var(--pending-fg); }

.bar .fill.s1, .bar .fill.s2, .bar .fill.s3, .bar .fill.s4, .bar .fill.s5, .bar .fill.s6 { background: var(--c); }

.sessions { display: grid; gap: 6px; }
.sessions details { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.sessions summary { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 8px 12px; cursor: pointer; font-size: 13px; }
.sessions summary span { color: var(--muted); font-variant-numeric: tabular-nums; }
.sessions summary small { color: var(--muted); margin-left: auto; }
.steps-mini .dot { margin-right: 3px; }
.path { display: flex; flex-wrap: wrap; gap: 5px; padding: 2px 12px 12px; }
.chip { font-size: 12px; padding: 2px 8px 2px 7px; border-radius: 6px; background: var(--surface-2); border-left: 3px solid var(--c); white-space: nowrap; }
.chip b { font-weight: 500; color: var(--muted); margin-left: 3px; font-variant-numeric: tabular-nums; }
.chip.idle { background: var(--pending-bg); }
.sessions .more { justify-self: start; }

.tip { position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px;
  padding: 5px 9px; border-radius: 7px; max-width: 320px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }

@media (max-width: 720px) {
  .dialog-head { flex-wrap: wrap; }
  .sessions summary small { margin-left: 0; }
}

/* The web's gate */
body.locked > header .tabs, body.locked > main, body.locked #signout { display: none !important; }
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); z-index: 20; overflow: auto; }
.gate-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); }
.gate-card .brand { margin-bottom: 16px; }
.gate-card form { display: grid; gap: 12px; }
.gate-card label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
.gate-card input { width: 100%; font-weight: 400; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; }
.gate-card input[name="code"] { font-size: 20px; letter-spacing: .2em; text-align: center; font-variant-numeric: tabular-nums; }
.gate-card .form-error { margin-bottom: 12px; }
.hint.small { font-size: 12px; margin: 0; }
.qr { width: 180px; height: 180px; justify-self: center; background: #fff; border-radius: 8px; padding: 8px; }
#enrol-secret { word-break: break-all; font-size: 12px; }
#signout { margin-left: 8px; }
