:root {
  color-scheme: light dark;
  --bg: #f3f4f7;
  --col-bg: #e9ebf0;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --border: #dde1e8;
  --border-strong: #c6ccd6;
  --text: #1b2130;
  --muted: #677085;
  --accent: #3657d6;
  --accent-text: #ffffff;
  --todo: #64748b;
  --working: #2563eb;
  --hitl: #c2610c;
  --done: #16883f;
  --danger: #c62828;
  --question: #7c3aed;
  --review: #0e7490;
  --failure: #c62828;
  --code-bg: #f1f3f6;
  --add-bg: #e6f6ea;
  --add-fg: #135c2a;
  --del-bg: #fdecec;
  --del-fg: #8f1d1d;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: -8px 0 30px rgba(16, 24, 40, 0.16);
  --radius: 10px;
  --mono: ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --col-bg: #151a22;
    --panel: #1b212b;
    --panel-2: #202733;
    --border: #2b3340;
    --border-strong: #3a4454;
    --text: #e4e8ef;
    --muted: #8f99ab;
    --accent: #6d8cff;
    --accent-text: #0e1117;
    --todo: #94a3b8;
    --working: #60a5fa;
    --hitl: #f59e0b;
    --done: #4ade80;
    --danger: #f87171;
    --question: #a78bfa;
    --review: #22d3ee;
    --failure: #f87171;
    --code-bg: #141920;
    --add-bg: #12301d;
    --add-fg: #9fe5b4;
    --del-bg: #3a1618;
    --del-fg: #f6b1b1;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: -8px 0 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

/* Author display rules (flex, grid) must never un-hide elements. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  border-radius: 7px;
  padding: 6px 12px;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; border-color: var(--border); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
button.ghost { background: transparent; }
button.small { padding: 3px 9px; font-size: 12.5px; }
button.icon { border: none; background: transparent; font-size: 16px; padding: 4px 8px; color: var(--muted); }
button.icon:hover { color: var(--text); }

input, select, textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 6px 9px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input:disabled, select:disabled { opacity: 0.6; }
textarea { resize: vertical; }
.mono, code, pre { font-family: var(--mono); font-size: 12.5px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand span { color: var(--muted); font-weight: 500; }
.filters { display: flex; gap: 8px; flex: 1; min-width: 240px; max-width: 560px; }
.filters select { max-width: 180px; }
.status { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.pill-hitl {
  background: color-mix(in srgb, var(--hitl) 16%, transparent);
  color: var(--hitl);
  border: 1px solid color-mix(in srgb, var(--hitl) 40%, transparent);
  border-radius: 999px;
  padding: 3px 11px;
  font-weight: 600;
  font-size: 12.5px;
}
.live { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.live-on { background: var(--done); box-shadow: 0 0 0 3px color-mix(in srgb, var(--done) 25%, transparent); }
.live-off { background: var(--danger); }

/* ---------- board ---------- */

.board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(260px, 1fr));
  gap: 14px;
  padding: 14px 16px 16px;
  overflow-x: auto;
}
.board-empty { display: flex; align-items: flex-start; justify-content: center; }

.col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--col-bg);
  border-radius: var(--radius);
  border-top: 3px solid var(--todo);
}
.col-working { border-top-color: var(--working); }
.col-hitl { border-top-color: var(--hitl); }
.col-done { border-top-color: var(--done); }
.col.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }

.col-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px; }
.col-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.count { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel); border-radius: 999px; padding: 1px 8px; }
.col-hitl .count { color: var(--hitl); }

.col-body { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 8px; margin: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.12s;
}
.card:hover { border-color: var(--border-strong); }
.card-open { border-color: var(--accent); }
.card-hitl { border-left: 3px solid var(--hitl); }
.card-question { border-left-color: var(--question); }
.card-review { border-left-color: var(--review); }
.card-failure { border-left-color: var(--failure); }
.card.dragging { opacity: 0.45; }
.card h3 { margin: 4px 0 2px; font-size: 14px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.card-top { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.tid { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.when { margin-left: auto; color: var(--muted); }
.need-line, .meta { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; align-items: center; }
.cost { font-size: 12px; color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11.5px;
  font-weight: 500;
  background: color-mix(in srgb, var(--muted) 14%, transparent);
  color: var(--text);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-repo { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); }
.chip-question { background: color-mix(in srgb, var(--question) 15%, transparent); color: var(--question); font-weight: 600; }
.chip-review { background: color-mix(in srgb, var(--review) 15%, transparent); color: var(--review); font-weight: 600; }
.chip-failure { background: color-mix(in srgb, var(--failure) 15%, transparent); color: var(--failure); font-weight: 600; }
.chip-blocked { background: color-mix(in srgb, var(--hitl) 13%, transparent); color: var(--hitl); }
.chip-out-merged, .chip-col-done { background: color-mix(in srgb, var(--done) 15%, transparent); color: var(--done); }
.chip-out-cancelled { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.chip-col-working { background: color-mix(in srgb, var(--working) 15%, transparent); color: var(--working); }
.chip-col-hitl { background: color-mix(in srgb, var(--hitl) 15%, transparent); color: var(--hitl); }
.chip-branch { font-family: var(--mono); font-size: 11px; }
.mode { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; }
.mode-session { color: var(--question); border-color: color-mix(in srgb, var(--question) 40%, transparent); }

.onboard {
  max-width: 560px;
  margin-top: 8vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  box-shadow: var(--shadow);
}
.onboard h2 { margin-top: 0; }
.onboard pre, .md pre, .stat {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  overflow-x: auto;
}

/* ---------- drawer ---------- */

.scrim { position: fixed; inset: 0; background: rgba(10, 14, 22, 0.28); z-index: 10; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(680px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  overflow-y: auto;
}
.drawer-head { position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--border); padding: 12px 16px 10px; z-index: 1; }
.title-row { display: flex; align-items: flex-start; gap: 8px; }
.title-row .tid { padding-top: 3px; }
.title-row h2 { margin: 0; font-size: 17px; flex: 1; line-height: 1.3; overflow-wrap: anywhere; }
.head-actions { display: flex; gap: 6px; margin-top: 8px; }
.drawer-body { padding: 4px 16px 40px; }
.drawer section { padding: 12px 0; border-bottom: 1px solid var(--border); }
.drawer section:last-child { border-bottom: none; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 8px; font-weight: 600; cursor: default; }
summary.section-title { cursor: pointer; margin: 0; }
details[open] > summary.section-title { margin-bottom: 8px; }

.stale { background: color-mix(in srgb, var(--hitl) 12%, transparent); border-radius: 7px; padding: 8px 10px; margin-top: 10px; display: flex; gap: 10px; align-items: center; }

.hitl {
  margin-top: 12px;
  border: 1px solid color-mix(in srgb, var(--hitl) 45%, transparent);
  background: color-mix(in srgb, var(--hitl) 6%, var(--panel));
  border-radius: var(--radius);
  padding: 12px 14px !important;
}
.hitl-question { border-color: color-mix(in srgb, var(--question) 45%, transparent); background: color-mix(in srgb, var(--question) 6%, var(--panel)); }
.hitl-review { border-color: color-mix(in srgb, var(--review) 45%, transparent); background: color-mix(in srgb, var(--review) 6%, var(--panel)); }
.hitl-failure { border-color: color-mix(in srgb, var(--failure) 45%, transparent); background: color-mix(in srgb, var(--failure) 6%, var(--panel)); }
.hitl-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.hitl-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns .danger { margin-left: auto; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.opt { border-radius: 999px; font-size: 12.5px; padding: 3px 11px; }

#task-form { display: flex; flex-direction: column; gap: 10px; }
#task-form label, .field-label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 500; }
.field-label { margin-top: 10px; }
.row { display: flex; gap: 10px; }
.row > label { flex: 1; min-width: 0; }
.row > label.narrow { flex: 0 0 90px; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.small-text { font-size: 12px; }
.muted { color: var(--muted); }
.box { border: 1px solid var(--border); border-radius: 7px; padding: 4px 12px; background: var(--panel-2); }
.deps { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 4px; }
.deps a { color: var(--accent); text-decoration: none; }
.deps a:hover { text-decoration: underline; }

.md { overflow-wrap: anywhere; }
.md p { margin: 0.45em 0; }
.md ul, .md ol { margin: 0.4em 0; padding-left: 1.4em; }
.md h3, .md h4, .md h5, .md h6 { margin: 0.8em 0 0.3em; font-size: 14px; }
.md code { background: var(--code-bg); border-radius: 4px; padding: 0 4px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0.4em 0; padding-left: 10px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.md a { color: var(--accent); }

.diff {
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow-x: auto;
  background: var(--panel-2);
  padding: 4px 0;
  margin: 8px 0 0;
}
.diff span { display: block; white-space: pre; padding: 0 10px; min-height: 1.45em; }
.d-add { background: var(--add-bg); color: var(--add-fg); }
.d-del { background: var(--del-bg); color: var(--del-fg); }
.d-hunk { color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.d-file { font-weight: 700; margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px !important; }
.d-file:first-child { margin-top: 0; border-top: none; padding-top: 2px !important; }
.d-meta { color: var(--muted); }
.warn { background: color-mix(in srgb, var(--hitl) 10%, transparent); border-radius: 7px; padding: 6px 10px; margin: 6px 0; font-size: 12.5px; }
.warn pre { margin: 4px 0 0; }

.past { border-left: 3px solid var(--border-strong); padding: 4px 0 4px 10px; margin: 8px 0; }
.answer { font-size: 13px; margin-top: 4px; }

.runs { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.runs th, .runs td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.runs th { color: var(--muted); font-weight: 600; }

.comment-form { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 10px; }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.ev { border-left: 2px solid var(--border-strong); padding-left: 10px; }
.ev-hitl_open { border-left-color: var(--hitl); }
.ev-hitl_response { border-left-color: var(--accent); }
.ev-comment { border-left-color: var(--question); }
.ev-head { font-size: 12.5px; }
.ev-head time { color: var(--muted); margin-left: 4px; }
.ev .md { font-size: 13px; }
.ev details summary { cursor: pointer; font-size: 13px; color: var(--muted); }

/* ---------- sign-in ---------- */

.login { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; align-items: flex-start; justify-content: center; padding: 14vh 16px 16px; }
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h2 { margin: 0; font-size: 18px; }
.login-card p { margin: 0; }
.login-error { color: var(--danger); font-size: 13px; }

/* ---------- toasts ---------- */

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 30; width: min(460px, calc(100vw - 32px)); }
.toast {
  background: var(--text);
  color: var(--bg);
  border-radius: 9px;
  padding: 9px 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}
.toast-error { background: var(--danger); color: #fff; }
.toast button { color: inherit; border-color: currentColor; }

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  .topbar { gap: 10px; }
  .filters { order: 3; flex-basis: 100%; max-width: none; }
  .board { display: flex; flex-direction: column; overflow-x: hidden; }
  .col { flex: none; }
  .col-body { overflow: visible; }
  .row { flex-wrap: wrap; }
  .row > label { flex-basis: 45%; }
}
