:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1d2327;
  --muted: #5f6b73;
  --line: #dcd9d2;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e5eef5;
  --good: #2e7d4f;
  --good-soft: #e3f2e8;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191c; --surface: #1d2226; --ink: #e8eaeb; --muted: #9aa5ac; --line: #343b40;
    --accent: #6aa9d6; --accent-ink: #0d1214; --accent-soft: #1f3343;
    --good: #7cc79a; --good-soft: #1d3326; --warn: #e2b45a; --warn-soft: #3a2f17;
    --bad: #f08a80; --bad-soft: #3d1f1d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; }
.topbar nav a:hover { color: var(--ink); background: var(--bg); }
.topbar nav a.active { color: var(--accent); background: var(--accent-soft); }
.who { margin-left: auto; color: var(--muted); font-size: 13px; }

.banner { background: var(--warn-soft); color: var(--warn); padding: 8px 24px; font-size: 13px; border-bottom: 1px solid var(--line); }
main { max-width: 1180px; margin: 0 auto; padding: 24px; outline: none; }

.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.sub { color: var(--muted); font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }

button, .btn {
  font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; display: inline-block;
}
button:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 84px; resize: vertical; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label .req { color: var(--bad); }
.field { min-width: 0; }
.grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 24px 10px; text-align: center; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.Open { background: var(--good-soft); color: var(--good); }
.badge.Closed { background: var(--line); color: var(--muted); }
.badge.Rejected { background: var(--bad-soft); color: var(--bad); }
.badge.Complete { background: var(--good-soft); color: var(--good); }
.badge.Incomplete { background: var(--warn-soft); color: var(--warn); }
.badge.inactive { background: var(--line); color: var(--muted); }

.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input { max-width: 360px; }
.filters select { width: auto; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 13px; }
.pager select { width: auto; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 9px 14px; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 20px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

.ssn { display: flex; gap: 8px; align-items: center; }
.ssn code { font-family: var(--mono); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline .meta { color: var(--muted); font-size: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 6px; font-weight: 500; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.toast.error { background: var(--bad); color: #fff; }
.error-box { background: var(--bad-soft); color: var(--bad); border-radius: 6px; padding: 9px 12px; margin-top: 12px; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 20px; width: min(520px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }

/* Sign-in screens */
body.signed-out .topbar nav, body.signed-out .who { visibility: hidden; }
.auth-card { max-width: 420px; margin: 48px auto; padding: 28px; }
.brand-lg { font-weight: 700; font-size: 20px; margin-bottom: 18px; letter-spacing: -.01em; }
.notice { background: var(--accent-soft); color: var(--ink); border-radius: 6px; padding: 9px 12px; }
.qr { background: #fff; padding: 12px; width: fit-content; border-radius: 6px; margin: 12px 0; }
.auth-card code { font-family: var(--mono); word-break: break-all; }

/* Stage 2 */
.overdue { color: var(--bad); font-weight: 600; }
.due-today { color: var(--warn); font-weight: 600; }
.next-task { margin-top: 4px; font-size: 13px; }
.chips { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 5px 12px; display: inline-flex; gap: 8px; align-items: center; }
.chip .count { background: var(--bg); border-radius: 999px; padding: 0 7px; font-size: 12px; font-variant-numeric: tabular-nums; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.active .count { background: rgba(255,255,255,.25); color: inherit; }
.chip.warn:not(.active) .count { background: var(--bad-soft); color: var(--bad); }
.warn-card { background: var(--warn-soft); border-color: transparent; color: var(--ink); }
td.clip { max-width: 340px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions button { margin-left: 6px; padding: 4px 10px; }
.prio { font-size: 12px; font-weight: 600; color: var(--muted); }
.prio-high { color: var(--warn); } .prio-urgent { color: var(--bad); } .prio-low { color: var(--muted); font-weight: 400; }
.activity { padding: 12px 0; border-bottom: 1px solid var(--line); }
.activity:last-child { border-bottom: none; }
.activity.system .activity-desc { color: var(--muted); }
.activity-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.activity-head .spacer { flex: 1; }
.activity .meta, .revisions .meta { color: var(--muted); font-size: 12px; }
.atype { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--accent); }
.activity.system .atype { color: var(--muted); }
.activity-desc { margin-top: 3px; font-weight: 500; }
.activity-notes { margin-top: 4px; white-space: pre-wrap; color: var(--ink); font-size: 13px; }
.activity-foot { display: flex; gap: 14px; margin-top: 4px; font-size: 12px; }
.revisions { margin-top: 6px; padding: 8px 10px; background: var(--bg); border-radius: 6px; font-size: 13px; }
.revisions del { color: var(--bad); } .revisions ins { color: var(--good); text-decoration: none; }
.party.removed { opacity: .7; }
tr.muted td { color: var(--muted); }
.inline-check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); font-weight: 500; margin: 0; }
.inline-check input { width: auto; }
dialog { width: min(720px, 94vw); }
