:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efefec;
  --border: #dddcd7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --pending: #b5b4ae;
  --running: #2a78d6;
  --code-bg: #f0efeb;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
    --pending: #5a5955; --running: #3987e5; --code-bg: #0e0e0d;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
  --pending: #5a5955; --running: #3987e5; --code-bg: #0e0e0d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
button { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid var(--border); background: var(--accent); color: #fff; padding: 6px 12px; }
button.ghost { background: transparent; color: var(--text-2); }
button:focus-visible, a:focus-visible, .step:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
pre, code { font-family: var(--mono); font-size: 12px; }
pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; overflow: auto; max-height: 420px; white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; }
.muted { color: var(--muted); }
.error { color: var(--critical); min-height: 1.2em; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: min(360px, 100%); display: grid; gap: 12px; }
.login-card label { display: grid; gap: 4px; color: var(--text-2); }
.login-card input { font: inherit; padding: 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; padding: 0 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); }
.nav nav { display: grid; gap: 2px; }
.nav nav a { color: var(--text-2); padding: 7px 10px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.nav nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-sep { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 12px 10px 4px; }
.pill { background: var(--critical); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
.live { margin-top: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; padding: 0 8px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pending); }
.live.on .live-dot { background: var(--good); }
.view { padding: 24px; min-width: 0; outline: none; }

/* cards */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.section { margin-top: 24px; }

/* status badge: icon + label, never colour alone */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px 2px 6px; border-radius: 12px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge svg { width: 14px; height: 14px; flex: none; }
.s-passed, .s-up { color: var(--good); }
.s-failed, .s-down { color: var(--critical); }
.s-warning, .s-degraded { color: var(--warning); }
.s-running { color: var(--running); }
.s-pending, .s-skipped, .s-unknown { color: var(--muted); }
.env { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); color: var(--text-2); }
.env.production { border-color: var(--serious); color: var(--serious); }

/* pipeline — one circle per step, label always under it, like GitHub Actions */
.pipeline { display: flex; align-items: flex-start; overflow-x: auto; padding: 6px 2px 4px; }
.step { flex: 1 0 64px; display: grid; justify-items: center; gap: 8px; background: none; border: 0; color: var(--text-2); padding: 0; position: relative; cursor: pointer; }
.step + .step::before { content: ""; position: absolute; top: 15px; right: calc(50% + 18px); width: calc(100% - 36px); height: 2px; border-radius: 1px; background: var(--border); }
.step.done + .step::before { background: var(--good); }
.step .circle { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--pending); color: var(--muted); box-sizing: border-box; }
.step .circle svg { width: 18px; height: 18px; }
.step.s-passed .circle { border-color: var(--good); background: var(--good); color: #fff; }
.step.s-failed .circle { border-color: var(--critical); background: var(--critical); color: #fff; }
.step.s-warning .circle { border-color: var(--warning); background: var(--warning); color: #0b0b0b; }
.step.s-running .circle { border-color: var(--running); color: var(--running); box-shadow: 0 0 0 4px color-mix(in srgb, var(--running) 22%, transparent); animation: pulse 1.6s ease-in-out infinite; }
.step.s-skipped .circle { border-style: dashed; }
.step .label { font-size: 12px; line-height: 1.2; color: var(--text-2); text-align: center; white-space: nowrap; }
.step.s-running .label { color: var(--running); font-weight: 700; }
.step.s-failed .label { color: var(--critical); font-weight: 700; }
.step.s-pending .label, .step.s-skipped .label { color: var(--muted); }
/* failed step of an active run: the runner may still restart it. Wraps inside the step, never truncates */
.step .restart { font-size: 11px; line-height: 1.15; color: var(--text-2); font-weight: 400; text-align: center; margin-top: -5px; max-width: 100%; }
.step.selected .label { color: var(--text); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.step[disabled] { cursor: default; }
.step:not([disabled]):hover .circle { filter: brightness(1.08); }
.pipeline.compact .step { flex-basis: 58px; }
.pipeline.compact .step .circle { width: 28px; height: 28px; }
.pipeline.compact .step .circle svg { width: 16px; height: 16px; }
.pipeline.compact .step + .step::before { top: 13px; right: calc(50% + 16px); width: calc(100% - 32px); }
.pipeline.compact .step .label { font-size: 11.5px; }
.pipeline.compact .step .restart { font-size: 10.5px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--running) 8%, transparent); } }
@media (prefers-reduced-motion: reduce) { .step.s-running .circle { animation: none; } }
.run-now { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.run-now > svg { width: 16px; height: 16px; flex: none; }
.run-now strong { color: var(--text); }
.card.wide { grid-column: 1 / -1; }
.card[data-href] { cursor: pointer; }
.git-icon { display: inline-flex; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td code { word-break: break-all; }
.table-wrap { overflow-x: auto; }
.run-row { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.run-row:last-child { border-bottom: 0; }
.run-meta { display: grid; gap: 2px; min-width: 0; }
.run-meta .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* step detail */
.event { border-top: 1px solid var(--border); padding: 12px 0; }
.event-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.event .msg { white-space: pre-wrap; margin-top: 6px; }

/* drawer */
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(760px, 100vw); background: var(--surface); border-left: 1px solid var(--border); box-shadow: -8px 0 24px rgba(0,0,0,.15); display: flex; flex-direction: column; z-index: 10; }
.drawer header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer header h2 { margin: 0; }
.drawer-body { padding: 16px; overflow: auto; }
.drawer-body pre { max-height: none; }

.banner { background: color-mix(in srgb, var(--critical) 12%, var(--surface)); border: 1px solid var(--critical); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.iframe { width: 100%; height: calc(100vh - 140px); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav nav { display: flex; flex-wrap: wrap; }
  .nav-sep, .live { display: none; }
  .view { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- workspace pages */
:root { --f-fable: #2a78d6; --f-opus: #eb6834; --f-sonnet: #1baf7a; --f-haiku: #eda100; --f-other: #8f8e86; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --f-fable: #3987e5; --f-opus: #d95926; --f-sonnet: #199e70; --f-haiku: #c98500; } }
:root[data-theme="dark"] { --f-fable: #3987e5; --f-opus: #d95926; --f-sonnet: #199e70; --f-haiku: #c98500; }

.page-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
.sync-line button { padding: 2px 8px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.chip.act-active { border-color: var(--good); color: var(--good); }
.chip.act-dormant { color: var(--muted); }
.chip.policy { border-color: var(--accent); color: var(--accent); }
h2.inline { display: inline; }
details > summary { cursor: pointer; list-style-position: inside; }
details[open] > summary { margin-bottom: 10px; }

.strip { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.strip-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; color: var(--text); }
.strip-item:hover { text-decoration: none; border-color: var(--accent); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; gap: 4px; }
.kpi-label { color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter.over span { background: var(--critical); }
.share { display: inline-block; width: 120px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; vertical-align: middle; margin-right: 6px; }
.share span { display: block; height: 100%; background: var(--text-2); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.f-fable { fill: var(--f-fable); background: var(--f-fable); }
.f-opus { fill: var(--f-opus); background: var(--f-opus); }
.f-sonnet { fill: var(--f-sonnet); background: var(--f-sonnet); }
.f-haiku { fill: var(--f-haiku); background: var(--f-haiku); }
.f-other { fill: var(--f-other); background: var(--f-other); }
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .bar.hover { opacity: .8; }
.chart .hit { fill: transparent; cursor: default; }
.tip { position: absolute; width: 180px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.12); pointer-events: none; }
.tip div { display: flex; align-items: center; gap: 2px; }
.tip .num { margin-left: auto; }

.breakdown { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.policy-form { display: grid; gap: 16px; }
.policy-form label { display: grid; gap: 4px; }
.policy-form label > span { font-weight: 600; }
select, input[type="number"], .task-form input { font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.budget-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.budget-form input { width: 110px; margin-left: 4px; }

.task-form { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; margin-bottom: 16px; }
.tasks { list-style: none; margin: 0; padding: 0; }
.task { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.task:first-child { border-top: 0; }
.task-title { font-weight: 600; }
.task-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; font-size: 12px; }
.task-notes { margin-top: 4px; font-size: 12px; }
.task-actions { display: flex; gap: 6px; align-items: start; }
.chip.owner-agent { border-color: var(--accent); color: var(--accent); }
.empty-row { padding: 8px 0; }

@media (max-width: 760px) {
  .task-form { grid-template-columns: 1fr; }
  .task { flex-direction: column; }
  .kpi-value { font-size: 24px; }
}

.follow { padding: 3px 9px; white-space: nowrap; }
.follow.on { color: var(--warning); border-color: var(--warning); }
tr.dim td { opacity: .6; }
.nowrap { white-space: nowrap; }
.page-head .follow { align-self: center; }
