/* Layout: fixed sidebar + scrolling main on desktop, top bar on phones.
   Palette: pure mono (black, white, greys). The only colour is in the data:
   green = good, amber = close, red = behind. */
:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --panel-2: #f7f7f7;
  --line: #e6e6e6;
  --fg: #0a0a0a;
  --muted: #6b6b6b;
  --accent: #0a0a0a;
  --accent-ink: #ffffff;
  --accent-soft: #f1f1f1;
  --signal: #fafafa;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --good: #15803d;
  --good-soft: #dcfce7;
  --side: #0a0a0a;
  --side-fg: #fafafa;
  --side-muted: #8a8a8a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .05);
  --radius: 10px;
  --font: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a; --panel: #111111; --panel-2: #161616; --line: #262626;
    --fg: #fafafa; --muted: #a1a1a1; --accent: #fafafa; --accent-ink: #0a0a0a;
    --accent-soft: #1f1f1f; --signal: #fafafa; --warn: #f59e0b; --warn-soft: #2d2006; --bad: #f87171;
    --bad-soft: #2c1010; --good: #4ade80; --good-soft: #0f2a19; --side: #000000; --side-fg: #fafafa; --side-muted: #7a7a7a;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font);
  font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Auth & onboarding ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.brand { font-weight: 600; letter-spacing: -.045em; text-transform: lowercase; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 24px; height: 24px; flex: none; display: block; color: inherit; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.auth-card h1 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.auth-card p { margin: 0; color: var(--muted); }
.switch-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; }
.choice-grid { display: grid; gap: 12px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .01em; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  outline: none; min-width: 0;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600; white-space: nowrap;
}
a.btn { color: inherit; text-decoration: none; }
.ig-links { display: flex; gap: 6px; margin-top: 4px; }
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .nav a:focus-visible, .switch-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.error-text { color: var(--bad); font-size: 13px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; background: linear-gradient(to right, var(--side) 236px, transparent 236px); }
.side { background: var(--side); color: var(--side-fg); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { color: var(--side-fg); font-size: 18px; padding: 0 6px; }
.ws-switch { display: flex; flex-direction: column; gap: 6px; padding: 0 6px; }
.ws-switch label { font-size: 11px; color: var(--side-muted); text-transform: uppercase; letter-spacing: .06em; }
.ws-switch select { background: #1a1a1a; color: var(--side-fg); border: 1px solid #2a2a2a; border-radius: 8px; padding: 7px 9px; }
.role-chip { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--side-muted); padding: 0 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: var(--side-fg); text-decoration: none; padding: 9px 10px; border-radius: 8px; font-weight: 600; opacity: .82; }
.nav a:hover { background: #171717; opacity: 1; }
.nav a[aria-current="page"] { background: #1f1f1f; opacity: 1; box-shadow: inset 3px 0 0 var(--signal); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding: 0 6px; font-size: 12px; color: var(--side-muted); }
.side-foot .btn { background: transparent; color: var(--side-fg); border-color: #2a2a2a; }
.main { padding: 28px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); min-width: 0; }
.main-inner { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .input { width: auto; min-width: 140px; }
.toolbar .search { flex: 1 1 220px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; background: none; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left)); }
  .nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
  .nav a { white-space: nowrap; }
  .side-foot { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; }
  .side-foot { display: none; }
  .ws-switch { flex: 1 1 160px; }
  .ws-switch label, .role-chip { display: none; }
  .main { padding-top: 18px; }
}

/* ---------- Cards, KPIs, tables ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card h2 { margin: 0; font-size: 15px; font-weight: 700; }
.card .sub { margin: -6px 0 0; color: var(--muted); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); }
.kpi.accent { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--panel)); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 700; background: var(--panel-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td .stack { display: flex; flex-direction: column; }
td .stack small { color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.stage-select { padding: 4px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); font-size: 12px; font-weight: 700; }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.list-item:last-child { border-bottom: 0; }
.rank { font-family: var(--mono); color: var(--muted); width: 2ch; display: inline-block; }
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.tabs button { border: 0; background: transparent; padding: 7px 12px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button[aria-pressed="true"] { background: var(--accent-soft); color: var(--fg); }
.code-box { font-family: var(--mono); font-size: 12px; background: var(--panel-2); border: 1px dashed var(--line); border-radius: 8px; padding: 10px; word-break: break-all; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 12px 14px; font-weight: 600; }

/* ---------- Modal & toasts ---------- */
dialog#modal { border: 0; padding: 0; border-radius: 14px; width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--fg); box-shadow: 0 24px 64px rgba(0,0,0,.35); }
dialog#modal::backdrop { background: rgba(0, 0, 0, .5); }
#modal-form { padding: 22px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 48px); overflow-y: auto; }
#modal-form h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#toasts { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); right: max(16px, env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--bad); color: #fff; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .2s ease-out; }
  @keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* Tags */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--fg); font-size: 11px; font-weight: 600; }

/* Pipeline board: scrolls sideways inside itself, never the page */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; max-width: 100%; }
.board-col { flex: 0 0 250px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.board-col.drop { border-color: var(--accent); background: var(--accent-soft); }
.board-head { display: flex; flex-direction: column; gap: 2px; padding: 2px 2px 8px; border-bottom: 3px solid var(--line); }
.board-col.kind-booked .board-head { border-bottom-color: var(--warn); }
.board-col.kind-won .board-head { border-bottom-color: var(--good); }
.board-col.kind-lost .board-head { border-bottom-color: var(--bad); }
.board-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; cursor: grab; box-shadow: var(--shadow); }
.board-card .stage-select { align-self: flex-start; max-width: 100%; }
.board-name { all: unset; display: block; font-weight: 700; cursor: pointer; overflow-wrap: anywhere; }
.board-name:hover { text-decoration: underline; }
.board-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.board-foot { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.board-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 0; border: 1px dashed var(--line); border-radius: 8px; }

/* Notes history */
.note-list { display: flex; flex-direction: column; gap: 10px; max-height: 260px; overflow-y: auto; }
.note { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; }
.note p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Pipeline stage editor */
.stage-rows { display: flex; flex-direction: column; gap: 8px; }
.stage-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; gap: 8px; align-items: center; }
@media (max-width: 560px) {
  .stage-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .stage-row .row-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* EOD question editor */
.eod-row { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto auto; gap: 8px; align-items: center; }
.role-checks { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
@media (max-width: 760px) {
  .eod-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .eod-row .role-checks, .eod-row .row-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* Import */
.import-step { display: flex; flex-direction: column; gap: 12px; }
.import-summary { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); font-weight: 600; }

/* Billing */
.notice.bad { background: var(--bad-soft); color: var(--fg); border-color: transparent; }
.billing-line { margin: 0; font-weight: 600; }

/* Today list */
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.card-head a { font-size: 12px; font-weight: 600; }
.notice.good { background: var(--good-soft); color: var(--fg); }
.today-list { display: flex; flex-direction: column; gap: 10px; }
.today-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.today-item.late { border-left: 4px solid var(--bad); }
.today-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.today-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.today-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.quick-note { padding: 6px 9px; font-size: 13px; }
@media (max-width: 760px) {
  .today-item { grid-template-columns: minmax(0, 1fr); }
  .today-actions { align-items: flex-start; }
  .today-actions .row-actions { justify-content: flex-start; }
}

/* Quick add */
.fab { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1; font-weight: 600; cursor: pointer; box-shadow: var(--shadow); z-index: 20; }
.fab:hover { filter: brightness(1.05); }
.fab:focus-visible { outline: 3px solid var(--fg); outline-offset: 3px; }
.qa-more summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.qa-more .form-grid { margin-top: 10px; }
.qa-hint { font-size: 13px; color: var(--muted); }
#toasts { bottom: 88px; }

/* Daily targets */
.tally-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px; }
.tally { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.tally .row-actions { justify-content: flex-start; }
.tally-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.tally-bar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; border: 1px solid var(--line); }
.tally-bar span { display: block; height: 100%; background: var(--muted); transition: width .2s; }
.tally-bar.half span { background: var(--warn); }
.tally-bar.done span { background: var(--good); }
.eod-row { grid-template-columns: minmax(0, 1fr) 130px 110px auto auto; }
@media (max-width: 760px) { .eod-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* Get set up checklist */
.setup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.setup-list li { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.setup-list li.done { opacity: .65; }
.setup-list li.done strong { text-decoration: line-through; }
.tick { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); font-weight: 800; color: var(--accent-ink); }
.setup-list li.done .tick { background: var(--accent); border-color: var(--accent); }
.row-actions.center { justify-content: center; margin-top: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Closer tools */
.calendar { gap: 12px; }
.cal-day.is-today { border-color: var(--accent); }
.cal-time { font-weight: 800; min-width: 52px; font-variant-numeric: tabular-nums; }
.prep-top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.prep-name { font-size: 18px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 10px; padding: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.fact { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.prep-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.prep-top .stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

/* Management */
.mg { gap: 16px; }
.mg h3 { margin: 4px 0 0; font-size: 14px; }
.mg details summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.mg .kpis { margin: 0; }
.sub-row { align-items: flex-start; }
.list-item .stack, .mg .stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mg .card-head input[type=date] { max-width: 190px; }

/* Management: dense metric rows like a spreadsheet dashboard */
.mg-toolbar { flex-wrap: wrap; align-items: center; gap: 8px; }
.mg-toolbar .input { width: auto; }
.mg-row { display: flex; flex-wrap: wrap; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-top: 12px; }
.mg-cell { flex: 1 1 150px; background: var(--panel); padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mg-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mg-val { font-size: 19px; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mg-sub { font-size: 11px; color: var(--muted); }
.mg-cell.accent .mg-val { color: var(--accent); }
.mg-cell.good .mg-val { color: var(--good); }
.mg-cell.warn .mg-val { color: var(--warn); }
.mg-cell.bad .mg-val { color: var(--bad); }
.mg-cell.total { background: var(--accent-soft); }
.mg-cell.total .mg-val { font-size: 22px; }
.mg-source { margin-top: 12px; }
.mg-source .input { max-width: 190px; }
.mg-pace { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.mg-pace .right { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.mg-pace.small { font-size: 12px; margin-top: 6px; }
.mg-big { font-size: 20px; font-weight: 800; color: var(--accent); }
.mg-bar { height: 10px; margin-top: 10px; }
.mg-bar span { background: var(--accent); }
.accent-text, .good-text { color: var(--good); }
.warn-text { color: var(--warn); }
.bad-text { color: var(--bad); }

.legal-note { font-size: 12.5px; margin: 10px 0 0; }
.legal-note a { color: var(--accent); }

/* Plan picker */
.plan-pick { display: grid; gap: 10px; margin-top: 14px; }
.plan-opt { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.plan-opt.on { border-color: var(--fg); box-shadow: 0 0 0 1px var(--fg); }
.plan-opt.off { opacity: .5; cursor: not-allowed; }
.plan-cost { text-align: right; display: flex; flex-direction: column; }
