:root {
  --bg: #fbfbfa;
  --panel: #ffffff;
  --sunken: #f3f3f1;
  --line: #e4e4e0;
  --text: #1f2328;
  --muted: #6b7076;
  --accent: #1f6feb;
  --accent-soft: #dbe7ff;
  --ok: #1a7f37;
  --warn: #b35900;
  --bad: #cf222e;
  --review: #8250df;
  --admin: #cf222e;
  --lane0: #1f6feb; --lane1: #1a7f37; --lane2: #b35900; --lane3: #8250df;
  --lane4: #0a7c86; --lane5: #bf3989; --lane6: #6e7781; --lane7: #9a6700;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 6px;
  --shadow: 0 6px 24px rgb(0 0 0 / 0.12), 0 1px 3px rgb(0 0 0 / 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #161a20; --sunken: #1c2129; --line: #2a303a; --text: #d7dae0; --muted: #8b929c;
    --accent: #4c8dff; --accent-soft: #1d2d4d; --ok: #3fb950; --warn: #d29922; --bad: #f85149; --review: #a371f7; --admin: #f85149;
    --lane0: #4c8dff; --lane1: #3fb950; --lane2: #d29922; --lane3: #a371f7; --lane4: #39c5cf; --lane5: #db61a2; --lane6: #8b949e; --lane7: #e3b341;
    --shadow: 0 6px 24px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #161a20; --sunken: #1c2129; --line: #2a303a; --text: #d7dae0; --muted: #8b929c;
  --accent: #4c8dff; --accent-soft: #1d2d4d; --ok: #3fb950; --warn: #d29922; --bad: #f85149; --review: #a371f7; --admin: #f85149;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--sans); overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.row.end { justify-content: flex-end; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 4px 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--sunken); }
.btn.small { padding: 1px 7px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }
.link { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.link:hover { text-decoration: underline; }
.input { width: 100%; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: var(--radius); padding: 6px 8px; font: inherit; }
.input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 0; border-color: var(--accent); }
select { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }

/* header */
header.top { height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -0.01em; white-space: nowrap; }
header.top > * { flex: none; }
.tab, .usage, .user { white-space: nowrap; }
nav.repos { display: flex; flex-direction: column; gap: 2px; }
.tab { width: 100%; border: 0; background: none; padding: 4px 9px; border-radius: var(--radius); cursor: pointer; display: flex; gap: 6px; align-items: center; justify-content: space-between; color: var(--muted); text-align: left; }
.tab .name { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tab .badges { flex: none; }
.tab:hover { background: var(--sunken); }
.tab.current { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.tab .badges { font-size: 11px; color: var(--muted); }
.tab.busy .badges { color: var(--ok); }
.tab.asks .badges { color: var(--warn); }
.repo-pick { display: none; }
.usage { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--sunken); border-radius: 99px; padding: 3px 10px; cursor: pointer; font-size: 12px; }
.usage .state { font-weight: 600; }
.usage[data-state="under"] .state { color: var(--ok); }
.usage[data-state="wastage"] .state { color: var(--review); }
.usage[data-state="over"] .state, .usage[data-state="held"] .state { color: var(--warn); }
.usage[data-state="atLimit"] .state { color: var(--bad); }
.usage[data-state="unknown"] .state { color: var(--muted); }
.meter { position: relative; width: 54px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.meter .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); }
.meter .pace { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: 0.6; }
.num { color: var(--muted); font-variant-numeric: tabular-nums; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.conn.on { background: var(--ok); }
.user { border: 0; background: none; cursor: pointer; color: var(--muted); }

/* layout */
main.app { display: grid; grid-template-columns: 180px 1fr; height: calc(100% - 44px); }
aside.side { border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 6px; min-height: 0; }
.work { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
section.queue { border-bottom: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; flex: 0 1 auto; max-height: 45%; min-height: 0; }
section.graph { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; min-height: 0; }
section.sessions { border-bottom: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; flex: 0 1 auto; max-height: 25%; min-height: 0; }
section.sessions[hidden] { display: none; }
.slist { overflow: auto; padding: 2px 0; }
.srow { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 8px 0 12px; white-space: nowrap; overflow: hidden; }
.srow:hover { background: var(--sunken); }
.srow .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--muted); }
.srow.working .dot { background: var(--ok); border-color: var(--ok); }
.srow.waiting .dot { border-color: var(--warn); }
.srow.idle .dot { border-color: var(--ok); }
.srow.dead .dot { border-color: var(--bad); border-style: dashed; }
.srow .name { font-family: var(--mono); font-size: 12px; flex: none; }
.srow .where { color: var(--muted); font-size: 12px; flex: none; }
.srow .task { font-weight: 500; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.srow .doing { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 0; }
.srow.working .doing { color: var(--ok); }
.srow .age { color: var(--muted); font-size: 11px; flex: none; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-height: 41px; }
.pane-head h2 { font-size: 14px; margin: 0; }
.pane-head .count { color: var(--muted); }
.pane-head .checkout { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.pane-head .fetch-error { color: var(--bad); font-size: 12px; }
.pane-head .tools { display: flex; gap: 4px; align-items: center; }
.toggle { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 4px; margin-right: 6px; }
.empty { color: var(--muted); padding: 24px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mobile-tabs { display: none; }

/* commits */
.rows { overflow: auto; flex: 1; padding-bottom: 120px; }
.commit { display: flex; align-items: center; height: 26px; padding-right: 12px; white-space: nowrap; cursor: default; content-visibility: auto; contain-intrinsic-size: auto 26px; }
.commit:hover { background: var(--sunken); }
.commit.selected { background: var(--accent-soft); }
.commit .lanes { flex: none; padding-left: 6px; height: 26px; }
.commit .lanes svg { display: block; }
.commit .lanes path { fill: none; stroke-width: 2; }
.commit .pills { display: flex; gap: 4px; flex: none; margin: 0 6px 0 4px; }
.commit .subject { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 80px; }
.commit.undeployed .subject { font-weight: 500; }
.commit .author { color: var(--muted); margin-left: 12px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.commit .age { color: var(--muted); margin-left: 10px; width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.l0 { stroke: var(--lane0); } .l1 { stroke: var(--lane1); } .l2 { stroke: var(--lane2); } .l3 { stroke: var(--lane3); }
.l4 { stroke: var(--lane4); } .l5 { stroke: var(--lane5); } .l6 { stroke: var(--lane6); } .l7 { stroke: var(--lane7); }
.d0 { fill: var(--lane0); } .d1 { fill: var(--lane1); } .d2 { fill: var(--lane2); } .d3 { fill: var(--lane3); }
.d4 { fill: var(--lane4); } .d5 { fill: var(--lane5); } .d6 { fill: var(--lane6); } .d7 { fill: var(--lane7); }

.pill { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 0 8px; height: 20px; font-size: 12px; cursor: pointer; font-family: var(--mono); }
.pill:hover { border-color: var(--muted); }
.pill .dot { display: none; width: 8px; height: 8px; border-radius: 50%; }
.pill .meta { color: var(--muted); }
.pill .meta:empty { display: none; }
.pill.worktree .dot { display: inline-block; border: 1.5px solid var(--muted); }
.pill .dot[data-state="idle"] { background: var(--muted); border-color: var(--muted); }
.pill .dot[data-state="working"] { background: var(--ok); border-color: var(--ok); animation: pulse 1.2s ease-in-out infinite; }
.pill .dot[data-state="waiting"] { background: var(--warn); border-color: var(--warn); }
.pill.trunk { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pill.staging { border-color: var(--lane4); color: var(--lane4); font-weight: 600; }
.pill.deployed { background: var(--ok); border-color: var(--ok); color: #fff; }
.pill.remote, .pill.tag { color: var(--muted); border-style: dashed; }
.pill.head { border-color: var(--warn); color: var(--warn); }
.pill.task-review { border-color: var(--review); box-shadow: inset 0 0 0 1px var(--review); }
.pill.task-doing { border-color: var(--accent); }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .pill .dot[data-state="working"] { animation: none; } }

.devserver { font-size: 12px; padding: 2px 8px; border-radius: 99px; color: var(--muted); }
.devserver:empty { display: none; }
.devserver.up { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.devserver.crashed, .devserver.error { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.devserver.starting, .devserver.installing { color: var(--warn); }

/* queue */
.new { display: flex; gap: 6px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.new .new-task { flex: 1; min-width: 0; }
.new .plan { flex: none; }
.qlist { overflow: auto; flex: 1; padding: 4px 0; }
.qrow { display: flex; align-items: center; height: 40px; padding-right: 8px; gap: 6px; overflow: hidden; }
.qrow:hover { background: var(--sunken); }
.qrow .deps { flex: none; padding-left: 6px; height: 40px; }
.qrow .deps svg { display: block; }
.qrow .deps path { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.qrow .deps circle { fill: var(--panel); stroke: var(--muted); stroke-width: 2; }
.qrow .deps circle.next { fill: var(--accent); stroke: var(--accent); }
.qrow .deps circle.manual { stroke: var(--accent); }
.qrow .deps circle.working { fill: var(--ok); stroke: var(--ok); }
.qrow .deps circle.doing { stroke: var(--ok); }
.qrow .deps circle.waiting { stroke: var(--warn); }
.qrow .deps circle.review { fill: var(--review); stroke: var(--review); }
.qrow .deps circle.admin { fill: var(--admin); stroke: var(--admin); }
.qrow .deps circle.blocked { stroke: var(--bad); stroke-dasharray: 2 2; }
.qrow .body { flex: 1; min-width: 0; }
.qrow .line1 { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.qrow .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; min-width: 0; }
.qrow .status { font-size: 11px; color: var(--muted); white-space: nowrap; flex: none; }
.qrow.admin .title, .qrow.admin .status { color: var(--admin); }
.qrow.review .status { color: var(--review); }
.qrow .line2 { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qrow .line2 .doing { margin-left: 6px; color: var(--ok); }
.qrow .controls { display: flex; gap: 3px; align-items: center; flex: none; }
.qrow .controls select { font-size: 11px; }
.qrow .mode { width: 76px; }
.qrow .urgency { width: 44px; }
.qrow .send { width: 56px; }

/* drawer */
.drawer-wrap { position: fixed; top: 44px; right: 0; bottom: 0; pointer-events: none; z-index: 5; }
.drawer { pointer-events: auto; width: min(460px, 100vw); height: 100%; overflow: auto; background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow); padding: 12px 14px 40px; display: flex; flex-direction: column; gap: 10px; }
.drawer .title { font-size: 15px; font-weight: 600; }
.drawer .meta { color: var(--muted); font-size: 12px; }
.drawer .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.drawer h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 8px 0 0; }
.drawer .checks { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.drawer .notes { font-family: var(--mono); font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.deps-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.deps-list li { display: flex; gap: 8px; align-items: center; }
.deps-list .status { color: var(--muted); font-size: 11px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.timeline li { border-left: 2px solid var(--line); padding-left: 8px; }
.timeline .who { font-weight: 600; margin-right: 6px; }
.timeline .when { color: var(--muted); font-size: 11px; }
.timeline .body { white-space: pre-wrap; word-break: break-word; }
.timeline .ev-comment { border-color: var(--accent); }
.timeline .ev-claude { border-color: var(--ok); }
.timeline .ev-status .body, .timeline .ev-field .body, .timeline .ev-created .body { color: var(--muted); font-size: 12px; }

/* runs */
.runs-wrap { position: fixed; right: 14px; bottom: 14px; z-index: 6; width: min(440px, calc(100vw - 28px)); pointer-events: none; }
.runs { display: flex; flex-direction: column; gap: 6px; }
.run { pointer-events: auto; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px 8px; }
.run.ok { border-left-color: var(--ok); }
.run.failed { border-left-color: var(--bad); }
.run.conflict { border-left-color: var(--warn); }
.run .label { font-weight: 600; }
.run .where { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.run .tail { margin: 4px 0 0; font: 11px/1.35 var(--mono); color: var(--muted); max-height: 9em; overflow: hidden; white-space: pre-wrap; word-break: break-all; }
.run .tail:empty { display: none; }
.run.running .state { animation: pulse 1s infinite; }

/* terminals */
.terminals { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
.term-window { position: absolute; pointer-events: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; resize: both; overflow: hidden; min-width: 320px; min-height: 160px; }
.term-window.min { height: 32px !important; min-height: 0; resize: none; }
.term-window.min .term-body { display: none; }
.term-window.gone .term-title { text-decoration: line-through; color: var(--muted); }
.term-bar { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-bottom: 1px solid var(--line); cursor: move; user-select: none; touch-action: none; }
.term-title { font-family: var(--mono); font-weight: 600; font-size: 12px; }
.term-status { color: var(--warn); font-size: 12px; }
.term-body { flex: 1; min-height: 0; padding: 4px; background: var(--bg); }

/* menus and dialogs */
.menu { position: fixed; z-index: 50; min-width: 220px; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; }
.menu .item { display: flex; width: 100%; justify-content: space-between; gap: 12px; border: 0; background: none; padding: 6px 10px; border-radius: 4px; cursor: pointer; text-align: left; }
.menu .item:hover:not(:disabled), .menu .item:focus { background: var(--accent-soft); outline: none; }
.menu .item.danger { color: var(--bad); }
.menu .item:disabled { opacity: 0.45; cursor: default; }
.menu .hint { color: var(--muted); font-size: 12px; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 2px; }
.menu .heading { padding: 4px 10px 2px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 0.35); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; overflow: auto; }
.dialog { background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); padding: 16px; width: min(560px, 100%); display: flex; flex-direction: column; gap: 10px; }
.dialog.small { width: min(400px, 100%); }
.dialog.wide { width: min(1100px, 100%); max-height: 84vh; }
.dialog h2 { font-size: 15px; margin: 0; flex: 1; }
.dialog fieldset { border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; gap: 8px; }
.dialog legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.dialog .check { display: flex; gap: 6px; align-items: baseline; }
.dialog .check small { color: var(--muted); margin-left: 4px; }
.dialog small { color: var(--muted); }
pre.text { margin: 0; overflow: auto; font: 12px/1.45 var(--mono); background: var(--sunken); border-radius: var(--radius); padding: 10px; flex: 1; min-height: 0; }
pre.text .add { color: var(--ok); }
pre.text .del { color: var(--bad); }
pre.text .hunk { color: var(--lane4); }
pre.text .file { font-weight: 700; }

.toasts { position: fixed; top: 52px; right: 14px; z-index: 60; display: flex; flex-direction: column; gap: 6px; width: min(380px, calc(100vw - 28px)); }
.toast { display: flex; gap: 8px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 10px; }
.toast span { flex: 1; }
.toast.error { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
.toast .x { border: 0; background: none; cursor: pointer; color: var(--muted); }

/* login */
.login-page { height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: min(320px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login h1 { font-size: 20px; margin: 0 0 8px; }
.login .error { color: var(--bad); min-height: 1.4em; margin: 0; }

/* narrow screens: one column at a time */
@media (max-width: 760px) {
  header.top { gap: 6px; padding: 0 8px; }
  aside.side { display: none; }
  .repo-pick { display: block; max-width: 40vw; }
  .usage .meter, .usage .num, .brand, .user { display: none; }
  .repo-pick { flex: 1 1 auto; min-width: 0; }
  .mobile-tabs { display: flex; height: 36px; border-bottom: 1px solid var(--line); background: var(--panel); }
  .mobile-tabs button { flex: 1; border: 0; background: none; color: var(--muted); }
  .mobile-tabs button.current { color: var(--text); font-weight: 600; box-shadow: inset 0 -2px var(--accent); }
  main.app { grid-template-columns: 1fr; height: calc(100% - 80px); }
  main.app[data-tab="graph"] section.queue, main.app[data-tab="graph"] section.sessions, main.app[data-tab="queue"] section.graph { display: none; }
  section.queue { max-height: none; flex: 1 1 0; border-bottom: 0; }
  .commit .author { display: none; }
  .pane-head .toggle { display: none; }
  .drawer-wrap { top: 0; left: 0; }
}
