/* Components. Written entirely against the tokens in theme.css — no raw colors here, so a
   theme swap is a token swap and nothing structural moves. */

* { box-sizing: border-box; }

/*
 * The background is set on `html`, not only on `body`. Body-to-canvas propagation covers the
 * viewport only while `html` itself has no background — inside an app shell or webview that
 * sets one, propagation stops and every pixel below a short `body` falls back to the shell's
 * colour, which is the two-tone page it produces. Painting `html` removes the dependency.
 */
html { background: var(--bg); color-scheme: light dark; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- chrome */

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 54px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  letter-spacing: var(--display-spacing);
  white-space: nowrap;
  color: inherit;
  text-decoration: none;
}
.logo { width: 22px; height: 22px; flex: none; color: var(--muted); }
.logo-accent { fill: var(--accent); }

nav { display: flex; gap: 2px; }

nav button {
  background: none;
  border: 0;
  padding: 6px 12px;
  border-radius: calc(var(--radius) * .7);
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
nav button:hover { background: var(--bg); color: var(--ink); }
nav button.active { background: var(--bg); color: var(--ink); font-weight: 600; }

.status {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: calc(28px * var(--density)) 20px 80px;
}

.loading { color: var(--faint); padding: 40px 0; }

/* ---------------------------------------------------------------- type */

h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: var(--display-weight);
  letter-spacing: var(--display-spacing);
  margin: 0 0 4px;
}
h2 {
  font-size: 12.5px;
  margin: calc(34px * var(--density)) 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
h3 { font-size: 15px; margin: 0 0 6px; font-weight: 600; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }
code { font-family: var(--font-mono); font-size: 0.92em; }

/* ---------------------------------------------------------------- empty states */

.empty-state {
  text-align: center;
  padding: calc(30px * var(--density)) 20px;
  color: var(--muted);
}
.illus {
  width: 120px;
  height: 80px;
  color: var(--faint);
  margin-bottom: 10px;
}
.empty-title { font-weight: 600; color: var(--ink); font-size: 15px; }
.empty-body { font-size: 13.5px; margin-top: 4px; max-width: 42ch; margin-inline: auto; }
.empty-action { margin-top: 12px; font-size: 13px; }
.empty-action code {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 7px;
}

/* ---------------------------------------------------------------- banner */

.banner {
  padding: 11px 14px;
  border-radius: var(--radius);
  border: var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  margin-bottom: 16px;
  border-left: 3px solid var(--warn);
}
.banner.bad { border-left-color: var(--bad); }

/* ---------------------------------------------------------------- now card

   The one thing the page has to answer before you read anything else. Big enough to be
   legible from arm's length, and carrying only decision-changing numbers. */

.now {
  background: var(--panel);
  border: var(--panel-border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 14px;
  margin-bottom: 18px;
}
.now.focus  { border-left-color: var(--accent); }
.now.meeting{ border-left-color: var(--muted); }
.now.gap,
.now.clear  { border-left-color: var(--good); }

.now-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
}
.now-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: var(--display-weight);
  letter-spacing: var(--display-spacing);
  line-height: 1.25;
  margin: 5px 0 3px;
}
.now-sub { color: var(--muted); font-size: 13.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 20px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chip.bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 42%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 42%, transparent); }

/* ---------------------------------------------------------------- buckets */

.bucket { margin-bottom: 18px; }
.bucket-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2px;
}
.bucket-name {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.bucket-count {
  font: 11.5px var(--font-mono);
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.bucket.overdue .bucket-name { color: var(--bad); }
.bucket.today   .bucket-name { color: var(--ink); }

/* ---------------------------------------------------------------- plan */

.block {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 14px;
  padding: calc(11px * var(--density)) 0;
  border-bottom: 1px solid var(--line);
}
.block time {
  font: 12.5px var(--font-mono);
  color: var(--muted);
  padding-top: 2px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.block .title { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.block .why { color: var(--muted); font-size: 13px; margin-top: 2px; }
.block .kind {
  width: 6px; height: 6px; border-radius: 2px;
  background: var(--faint); flex: none;
}
.block.meeting .kind { background: var(--muted); }
.block.focus .kind { background: var(--accent); border-radius: 50%; }
.block.focus {
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 7%, transparent), transparent 55%);
}

/* ---------------------------------------------------------------- tasks */

.task {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: calc(12px * var(--density)) 0;
  border-bottom: 1px solid var(--line);
}
.task .score {
  font: 12px var(--font-mono);
  color: var(--muted);
  min-width: 46px;
  text-align: right;
  padding-top: 3px;
  font-variant-numeric: tabular-nums;
}
.task .body { flex: 1; min-width: 0; }

/* One-click completion: the most frequent action gets the largest, closest target. */
.tick {
  width: 18px; height: 18px;
  margin-top: 2px;
  flex: none;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  position: relative;
}
.tick:hover { border-color: var(--good); }
.tick:hover::after {
  content: "";
  position: absolute; inset: 3px;
  border-radius: 50%;
  background: var(--good);
}
.task.b-overdue .tick { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }

.task .title {
  font-weight: 600;
  border-radius: 4px;
  cursor: text;
  margin: -1px -4px;
  padding: 1px 4px;
}
.task .title:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.task .title:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

.meta-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.due-chip {
  font-size: 11.5px;
  padding: 1px 8px;
  border-radius: 20px;
  border: 1px dashed var(--line);
  color: var(--muted);
  cursor: pointer;
}
.due-chip:hover { border-style: solid; color: var(--ink); border-color: var(--muted); }
.due-chip:focus-visible { outline: 2px solid var(--accent); }
.task.b-overdue .due-chip { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 42%, transparent); }
.task.b-today   .due-chip { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 42%, transparent); }
.est { font: 11.5px var(--font-mono); color: var(--faint); }

.inline-input {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  width: 100%;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 2px 6px;
  margin: -3px 0;
}
.inline-input[type="date"] { font-size: 13px; font-weight: 400; width: auto; }
.task .why { color: var(--muted); font-size: 13px; margin-top: 2px; }
.task .why a { color: var(--muted); }

.actions { display: flex; gap: 6px; opacity: 0; transition: opacity .12s; }
.task:hover .actions, .task:focus-within .actions { opacity: 1; }
@media (hover: none) { .actions { opacity: 1; } }

button.act {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) * .7);
  padding: 3px 9px;
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
}
button.act:hover { color: var(--ink); border-color: var(--muted); }

.tag {
  display: inline-block;
  font-size: 11.5px;
  padding: 1px 8px;
  border-radius: 20px;
  border: 1px solid var(--line);
  color: var(--muted);
  margin-left: 6px;
  vertical-align: 1px;
  font-weight: 400;
}
.tag.chronic { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.tag.waiting { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.tag.low { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

/* ---------------------------------------------------------------- forms */

form.add { display: flex; gap: 8px; margin: 4px 0 10px; flex-wrap: wrap; }
form.add input, form.add select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) * .8);
  padding: 8px 11px;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}
form.add input:focus-visible, form.add select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
form.add input[name=title] { flex: 1; min-width: 220px; }
form.add button {
  background: var(--ink);
  color: var(--bg);
  border: 0;
  border-radius: calc(var(--radius) * .8);
  padding: 8px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.filters { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.filters button {
  background: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 3px 13px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.filters button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------------------------------------------------------------- stat tiles */

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); gap: 12px; }

.card {
  background: var(--panel);
  border: var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: calc(15px * var(--density)) 16px;
}
.card .label { font-size: 12.5px; color: var(--muted); }
.card .value {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: var(--display-weight);
  letter-spacing: var(--display-spacing);
  margin: 5px 0 3px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.card .note { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.card.unreliable .value { color: var(--faint); }
.card.unreliable::after {
  content: "insufficient sample";
  display: block;
  margin-top: 9px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--warn);
}
.card.alarm { border-left: 3px solid var(--bad); }

/* ---------------------------------------------------------------- charts */

.viz-figure {
  margin: 0 0 22px;
  background: var(--panel);
  border: var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: calc(15px * var(--density)) 16px;
}
.viz-figure figcaption { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.viz-title { font-weight: 600; font-size: 14px; }
.viz-sub { font-size: 12.5px; color: var(--muted); }

.viz { width: 100%; height: auto; overflow: visible; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { fill: var(--muted); font-size: 10.5px; font-family: var(--font-mono); }
.viz-area { fill: var(--viz-fill); }
.viz-line { stroke: var(--viz-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-line-2 { stroke: var(--viz-2); stroke-dasharray: 4 3; }
.viz-dot { fill: var(--viz-1); stroke: var(--panel); stroke-width: 2; }
.viz-hit { cursor: crosshair; }

.viz-legend { display: flex; gap: 16px; margin-bottom: 12px; font-size: 12.5px; color: var(--muted); }
.viz-key { display: inline-flex; align-items: center; gap: 6px; }
.viz-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.viz-swatch.s1 { background: var(--viz-1); }
.viz-swatch.s2 { background: var(--viz-2); }

.viz-bars, .viz-diverging { display: grid; gap: 8px; }
.viz-bar-row {
  display: grid;
  grid-template-columns: minmax(120px, max-content) 1fr 68px;
  gap: 12px;
  align-items: center;
  font-size: 13.5px;
}
/* Labels wrap rather than truncate — a category name you cannot read is a bar you
   cannot interpret, and these names are the finding. */
.viz-bar-label { max-width: 30ch; line-height: 1.3; }
.viz-bar-track { background: var(--viz-track); border-radius: 4px; height: 14px; overflow: hidden; }
/* 4px rounded data-end, anchored flat to the baseline. */
.viz-bar-fill {
  background: var(--viz-1);
  height: 100%;
  border-radius: 0 4px 4px 0;
  min-width: 3px;
}
.viz-bar-fill.muted { background: var(--faint); }
.viz-bar-fill.accent { background: var(--viz-1); }
.viz-bar-value {
  font: 12.5px var(--font-mono);
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.viz-div-track { position: relative; height: 14px; background: var(--viz-track); border-radius: 4px; }
.viz-div-axis {
  position: absolute; left: 50%; top: -3px; bottom: -3px;
  width: 1px; background: var(--muted); opacity: .5;
}
.viz-div-fill { position: absolute; top: 0; bottom: 0; }
.viz-div-fill.pos { background: var(--viz-pos); border-radius: 0 4px 4px 0; }
.viz-div-fill.neg { background: var(--viz-neg); border-radius: 4px 0 0 4px; }

.viz-cal-pair { display: grid; gap: 8px; }
.viz-cal-row { display: grid; grid-template-columns: 88px 1fr 52px; gap: 12px; align-items: center; font-size: 13.5px; }
.viz-cal-verdict { margin-top: 12px; font-size: 13px; color: var(--muted); }
.viz-cal-verdict.bad { color: var(--bad); }
.viz-calibration.unreliable { opacity: .55; }

.viz-meter-track { background: var(--viz-track); border-radius: 4px; height: 8px; overflow: hidden; }
.viz-meter-fill { background: var(--viz-1); height: 100%; border-radius: 0 4px 4px 0; }
.viz-meter-label { font-size: 12px; color: var(--muted); margin-top: 5px; }

.viz-tip {
  position: fixed;
  z-index: 50;
  background: var(--ink);
  color: var(--bg);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  line-height: 1.45;
  pointer-events: none;
  max-width: 260px;
  box-shadow: 0 6px 20px -6px rgba(0, 0, 0, .4);
}
.viz-tip b { font-weight: 600; }

/* ---------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--line);
}
td { padding: 9px 10px 9px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
td.bad { color: var(--bad); }
.table-wrap { overflow-x: auto; }

/* ---------------------------------------------------------------- agents */

.agent {
  background: var(--panel);
  border: var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: calc(16px * var(--density)) 18px;
  margin-bottom: 12px;
}
.agent .head { display: flex; align-items: baseline; gap: 10px; }
.agent .desc { color: var(--muted); font-size: 13.5px; margin: 7px 0 10px; }
.agent .meta { font: 12px var(--font-mono); color: var(--faint); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--good); }
.dot.failed { background: var(--bad); }
.dot.running { background: var(--warn); }
.dot.never { background: var(--faint); }

details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 10px; }
details pre {
  white-space: pre-wrap;
  font: 12.5px/1.55 var(--font-mono);
  background: var(--bg);
  padding: 12px;
  border-radius: calc(var(--radius) * .8);
  border: 1px solid var(--line);
  overflow-x: auto;
  max-height: 340px;
}

/* Neutral surface with a single coloured edge — a tinted panel reads as warm mud against a
   grayscale chrome, and the tint was carrying no information the border does not. */
.demo-note {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
}

@media (max-width: 700px) {
  header { gap: 10px; padding: 0 12px; height: auto; min-height: 54px; flex-wrap: wrap; }
  .brand, .status { display: none; }
  main { padding: 20px 14px 60px; }
  .block { grid-template-columns: 72px 1fr; gap: 10px; }
  .viz-bar-row { grid-template-columns: 96px 1fr 56px; gap: 8px; }
  .viz-cal-row { grid-template-columns: 68px 1fr 44px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

/* ---------------------------------------------------------------- pipeline */

.pipe-flow {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 22px; font-size: 12px; color: var(--faint);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.pipe-stage {
  border: 1px solid var(--line); border-radius: 20px;
  padding: 3px 11px; background: var(--panel);
}
.pipe-arrow { color: var(--faint); }

.pipe-source {
  background: var(--panel);
  border: var(--panel-border);
  border-left: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 16px;
  margin-bottom: 10px;
}
.pipe-source.ok  { border-left-color: var(--good); }
.pipe-source.bad { border-left-color: var(--bad); }
.pipe-source.off { border-left-color: var(--line); opacity: .72; }

.pipe-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pipe-when { margin-left: auto; font: 12px var(--font-mono); color: var(--faint); }
.pipe-detail { font-size: 13px; color: var(--muted); margin-top: 5px; }
.pipe-nums {
  display: flex; gap: 18px; flex-wrap: wrap;
  margin-top: 9px; font-size: 12.5px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pipe-nums b { color: var(--ink); font-weight: 600; }
.pipe-nums .warn-num b { color: var(--warn); }
.pipe-error {
  margin-top: 8px; font: 12px var(--font-mono);
  color: var(--bad); word-break: break-word;
}
