:root {
  --bg: #f5f5f3;
  --panel: #ffffff;
  --sub: #f9f9f7;
  --line: #e5e4df;
  --line-strong: #cfcec7;
  --text: #1d1d1b;
  --muted: #6a6963;
  --faint: #9a9891;
  --accent: #2563eb;
  --accent-weak: #e8eefc;
  --on-accent: #ffffff;
  --ok: #18794e;
  --ok-weak: #e3f3ea;
  --warn: #9a5b00;
  --warn-weak: #fbefd9;
  --bad: #c0362c;
  --bad-weak: #fbe8e6;
  --radius: 8px;
  --radius-lg: 12px;
  --side: 232px;
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --panel: #1b1b1a;
    --sub: #212120;
    --line: #2d2d2b;
    --line-strong: #3d3d3a;
    --text: #ecebe6;
    --muted: #a3a29b;
    --faint: #75746e;
    --accent: #6c9bff;
    --accent-weak: #1b2741;
    --on-accent: #0b1220;
    --ok: #4fc487;
    --ok-weak: #13301f;
    --warn: #e5a640;
    --warn-weak: #33260e;
    --bad: #ff7d72;
    --bad-weak: #3a1916;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
h3 { font-size: 14px; font-weight: 600; margin: 20px 0 4px; }
a { color: var(--accent); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; padding: 4px 10px 14px; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius);
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--sub); color: var(--text); }
.nav a.on { background: var(--accent-weak); color: var(--accent); }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-left: auto; }
.nav-dot.bad { background: var(--bad); }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.led { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.led.ok { background: var(--ok); }
.led.bad { background: var(--bad); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.topbar { display: none; }
.scrim { display: none; }

/* ---------- banner ---------- */
.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 16px 24px 0; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid transparent; font-weight: 500;
}
.banner.bad { background: var(--bad-weak); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.banner.warn { background: var(--warn-weak); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner .btn { margin-left: auto; }

/* ---------- common ---------- */
.view { flex: 1; min-height: 0; }
.page { padding: 24px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.box { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--sub); }
.label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: none; letter-spacing: 0.01em; }
.small { font-size: 12.5px; }
.muted { color: var(--muted); }
.link { text-decoration: none; }
.link:hover { text-decoration: underline; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.empty { color: var(--muted); padding: 16px; margin: 0; text-align: center; }
.note { padding: 10px 14px; border-radius: var(--radius); background: var(--sub); border: 1px solid var(--line); margin-bottom: 16px; }
.note-bad { background: var(--bad-weak); color: var(--bad); border-color: transparent; }
.note-ok { background: var(--ok-weak); color: var(--ok); border-color: transparent; }
.note-warn { background: var(--warn-weak); color: var(--warn); border-color: transparent; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--sub); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-danger { color: var(--bad); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 0; background: none; color: var(--text); border-radius: var(--radius); cursor: pointer; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--sub); color: var(--muted); border: 1px solid var(--line);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-lg { height: 28px; font-size: 13px; padding: 0 12px; }
.pill.armed { background: var(--ok-weak); color: var(--ok); border-color: transparent; }
.pill.paused { background: var(--warn-weak); color: var(--warn); border-color: transparent; }
.pill.signed-out { background: var(--bad-weak); color: var(--bad); border-color: transparent; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tiles-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 12px; }
.tile { background: var(--sub); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

.seg { display: inline-flex; max-width: 100%; overflow-x: auto; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--panel); }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 500; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-weak); color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }

/* ---------- overview console ---------- */
.console { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 0; min-height: 0; }
.rail {
  display: flex; flex-direction: column; gap: 12px; padding: 20px;
  border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto;
}
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.why { margin: -4px 0 0; color: var(--muted); font-size: 12.5px; min-height: 1em; }
#ov-rehearsal { margin: 6px 0 0; color: var(--muted); }
#ov-rehearsal.ok { color: var(--ok); }
#ov-rehearsal.bad { color: var(--bad); }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-list .when { color: var(--faint); font-size: 11.5px; display: block; }
.res { white-space: nowrap; font-weight: 500; text-align: right; }
.res.ok { color: var(--ok); }
.res.bad { color: var(--bad); }
.res.skip { color: var(--muted); font-weight: 400; }
.stage { display: flex; flex-direction: column; gap: 10px; padding: 16px 20px 20px; min-height: 0; }
.stage-head { display: flex; align-items: center; justify-content: space-between; }
#ov-vnc { flex: 1; width: 100%; min-height: 420px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: #000; }

/* ---------- offers ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--sub); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.res { text-align: left; }
.table .reason { display: block; color: var(--faint); font-weight: 400; font-size: 12px; white-space: normal; }

/* ---------- settings ---------- */
.settings { padding-bottom: 0; display: flex; flex-direction: column; }
.settings-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 24px; align-items: start; max-width: 980px; flex: 1; }
.subnav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 16px; }
.subnav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-radius: var(--radius); color: var(--muted); text-decoration: none; font-weight: 500; }
.subnav a:hover { background: var(--panel); color: var(--text); }
.subnav a.on { background: var(--panel); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.sec-dot { width: 7px; height: 7px; border-radius: 50%; }
.sec-dot.bad { background: var(--bad); }
.sec-dot.warn { background: var(--warn); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px 22px 8px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.field { margin-bottom: 18px; }
.field-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.opt { font-weight: 400; color: var(--faint); font-size: 12px; margin-left: 4px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.field-msg { margin: 6px 0 0; font-size: 12.5px; font-weight: 500; }
.field-msg:empty { display: none; }
.field.has-error .field-msg { color: var(--bad); }
.field.has-warning .field-msg { color: var(--warn); }
.field.has-error input, .field.has-error select, .field.has-error .chips { border-color: var(--bad); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline.grow input { flex: 1; min-width: 200px; }

input[type=text], input[type=number], input[type=time], input[type=password], input:not([type]), select {
  height: 36px; padding: 0 10px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--text); font: inherit; width: 100%; max-width: 100%;
}
.inline input, .inline select { width: auto; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }

.chips {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 38px; padding: 4px 6px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--panel); cursor: text;
}
.chips:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.chips input { border: 0; box-shadow: none; height: 28px; flex: 1; min-width: 140px; padding: 0 4px; background: none; }
.chips input:focus { box-shadow: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 10px; border-radius: 999px; background: var(--accent-weak); color: var(--accent); font-size: 12.5px; font-weight: 500; }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; width: 20px; height: 20px; border-radius: 50%; font-size: 15px; line-height: 1; }
.chip button:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.suggest .small { color: var(--muted); }
.suggest button { height: 26px; padding: 0 10px; border-radius: 999px; border: 1px dashed var(--line-strong); background: none; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; }
.suggest button:hover { border-style: solid; color: var(--text); }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button { width: 48px; height: 34px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--panel); color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; }
.days button.on { background: var(--accent-weak); color: var(--accent); border-color: transparent; }

.pp-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.pp-row { display: flex; gap: 8px; align-items: center; }
.pp-row input:first-child { flex: 1; }
.pp-row input[type=number] { width: 110px; }

.issues { list-style: none; padding: 0; margin: 12px 0 0; }
.issues li { color: var(--bad); font-size: 12.5px; margin: 4px 0; }

.savebar {
  position: sticky; bottom: 0; margin: 20px -24px 0; padding: 12px 24px;
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px);
  border-top: 1px solid var(--line);
}
.save-state { margin-right: auto; color: var(--muted); font-size: 13px; }
.save-state.dirty { color: var(--warn); font-weight: 500; }
.save-state.bad { color: var(--bad); font-weight: 500; }
.save-state.ok { color: var(--ok); font-weight: 500; }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; z-index: 30; left: 0; top: 0; width: 260px;
    transform: translateX(-100%); transition: transform 0.18s ease;
  }
  body.nav-open .side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.35); }
  .topbar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 10;
    padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
  }
  .topbar-title { font-weight: 600; margin-right: auto; }
  .banner { margin: 12px 16px 0; }
  .page { padding: 16px; }
  .console { grid-template-columns: minmax(0, 1fr); }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .stage { padding: 16px; }
  #ov-vnc { min-height: 60vh; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .subnav { position: static; flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 2px; }
  .subnav a { white-space: nowrap; gap: 6px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .tiles-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .savebar { margin: 16px -16px 0; padding: 12px 16px; }
  .panel { padding: 16px 16px 4px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: 2px 0; text-align: left !important; }
  .table td[data-label]::before { content: attr(data-label) " "; color: var(--faint); font-size: 12px; }
}

/* ---------- sign-in and account ---------- */
input.w-narrow, select.w-narrow { max-width: 180px; }
.rail-actions { display: flex; gap: 6px; }
.side-foot { flex-direction: column; align-items: stretch; gap: 10px; }
.side-status { display: flex; align-items: center; gap: 8px; }
.me { display: flex; align-items: center; gap: 10px; }
.me-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.me-name { font-weight: 600; color: var(--text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { font-size: 11.5px; color: var(--muted); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--accent-weak); color: var(--accent); font-weight: 600; font-size: 13px; flex: none; }
.avatar-lg { width: 40px; height: 40px; font-size: 16px; }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 28px 28px 24px; }
.login-brand { padding: 0 0 18px; }
.login-card h1 { margin-bottom: 4px; }
.login-card code { font-size: 12.5px; background: var(--sub); padding: 1px 5px; border-radius: 4px; }
.accounts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.account { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--panel); color: var(--text); font: inherit; cursor: pointer; }
.account:hover { background: var(--sub); }
.account.on { border-color: var(--accent); box-shadow: var(--focus); }
.account-text { display: flex; flex-direction: column; }
.account-name { font-weight: 600; }
.account-role { font-size: 12.5px; color: var(--muted); }
.login-error { min-height: 18px; margin: 8px 0 12px; color: var(--bad); font-size: 13px; font-weight: 500; }
.btn-block { width: 100%; height: 38px; }

/* ---------- motor club picker ---------- */
.picker { position: relative; }
.menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 15;
  max-height: 264px; overflow-y: auto; padding: 4px;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
}
.menu-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-item.active { background: var(--accent-weak); color: var(--accent); }
.menu-note { font-size: 12px; color: var(--muted); }
.menu-empty { padding: 10px; color: var(--muted); font-size: 13px; }
