/* Kairos dashboard. Hand-written, no framework - see ADR-009 (revised).
   Palette matches the architecture overview: cool slate ground, signal amber for
   anything that needs a human, teal for automatic, rust for blocked. */

:root {
  --ground: #eef0f4;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --line: #d5dae3;
  --line-soft: #e3e7ee;
  --ink: #161b24;
  --ink-2: #3d4655;
  --muted: #6b7688;
  --accent: #a75d0f;
  --accent-soft: #fbf0e1;
  --accent-line: #e8cda6;
  --ok: #2c6f63;
  --ok-soft: #e6f1ee;
  --bad: #a63d2e;
  --bad-soft: #f8e9e6;

  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 3px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0e1218;
    --surface: #161b24;
    --surface-2: #1c222d;
    --line: #2c3441;
    --line-soft: #232a35;
    --ink: #e2e7ef;
    --ink-2: #b3bdcc;
    --muted: #838ea0;
    --accent: #e5a34a;
    --accent-soft: #2a2115;
    --accent-line: #58421f;
    --ok: #4fb3a2;
    --ok-soft: #142522;
    --bad: #e07a6a;
    --bad-soft: #2a1815;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; hyphens: none; }
h1 { font-size: 1.6rem; letter-spacing: -0.015em; }
h2 { font-size: 1.1rem; letter-spacing: -0.01em; }
p { margin: 0 0 0.8rem; }
p:last-child { margin-bottom: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- layout */

.shell { max-width: 1000px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }

.centered {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.05rem;
}
.nav { display: flex; gap: 1rem; flex: 1; }
.nav a {
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.2rem 0;
  border-bottom: 2px solid transparent;
}
.nav a:hover { color: var(--ink); border-bottom-color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 0.9rem; }
.org { font-size: 0.85rem; color: var(--muted); }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.9rem;
}
.grid-2 {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.auth-card { width: min(400px, 100%); }
.auth-card h1 { margin-bottom: 0.3rem; }
.auth-card .lede { color: var(--muted); font-size: 0.92rem; margin-bottom: 1.4rem; }

/* ---------------------------------------------------------------- forms */

form .field { margin-bottom: 1rem; }
label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 0.35rem;
}
input[type="text"], input[type="email"], input[type="password"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
input:focus { border-color: var(--accent); }

.code-input {
  font-family: var(--mono);
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  text-align: center;
}

.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
@media (prefers-color-scheme: dark) { .btn { color: #1a1206; } }
.btn:hover { filter: brightness(1.06); }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--line);
  font-weight: 500;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--accent); filter: none; }

.errorlist {
  list-style: none;
  margin: 0 0 0.8rem;
  padding: 0.55rem 0.75rem;
  background: var(--bad-soft);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  color: var(--bad);
  font-size: 0.87rem;
}
.field .errorlist { margin: 0.4rem 0 0; }
.helptext { font-size: 0.82rem; color: var(--muted); margin-top: 0.3rem; }

/* ---------------------------------------------------------------- messages */

.messages { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; gap: 0.5rem; }
.msg {
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  border: 1px solid var(--line);
  background: var(--surface);
}
.msg-success { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.msg-warning { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.msg-error { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

/* ---------------------------------------------------------------- data */

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.45rem 1rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 0.85rem; }

table { border-collapse: collapse; width: 100%; font-size: 0.87rem; }
.tablewrap { overflow-x: auto; }
th, td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
th {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}
td.mono { font-family: var(--mono); font-size: 0.8rem; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }

.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  padding: 0.18rem 0.45rem;
  border-radius: 2px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
}
.pill-ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.pill-warn { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.pill-bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

/* ---------------------------------------------------------------- phases */

.phases { display: grid; }
.phase {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 0.8rem;
  align-items: baseline;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line-soft);
}
.phase:last-child { border-bottom: none; }
.phase .n { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.phase .t { font-weight: 600; font-size: 0.9rem; }
.phase .d { display: block; font-weight: 400; color: var(--muted); font-size: 0.83rem; }

.empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.pager { display: flex; gap: 0.6rem; align-items: center; margin-top: 1rem; font-size: 0.85rem; }

.secret-block {
  font-family: var(--mono);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  word-break: break-all;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

.qr {
  display: block;
  margin: 0 auto 1rem;
  width: 190px;
  height: 190px;
  image-rendering: pixelated;
  background: #fff;
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

/* ================================================================ studio (v0.2) */

.badge {
  display: inline-block; min-width: 1.25rem; padding: 0 0.35rem; margin-left: 0.2rem;
  border-radius: 99px; background: var(--accent); color: #fff;
  font-size: 0.7rem; font-weight: 700; line-height: 1.25rem; text-align: center;
}
@media (prefers-color-scheme: dark) { .badge { color: #1a1206; } }
.badge-bad { background: var(--bad); color: #fff; }

.nav { align-items: center; }
.nav-more { position: relative; }
.nav-more summary {
  list-style: none; cursor: pointer; color: var(--ink-2); font-size: 0.9rem; padding: 0.2rem 0;
}
.nav-more summary::-webkit-details-marker { display: none; }
.nav-more summary::after { content: " \25BE"; font-size: 0.7rem; }
.nav-menu {
  position: absolute; top: 1.9rem; left: -0.6rem; z-index: 20; min-width: 190px;
  display: grid; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.35); padding: 0.35rem;
}
.nav-menu a { padding: 0.45rem 0.6rem; border: 0; border-radius: 2px; }
.nav-menu a:hover { background: var(--surface-2); }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head .sub { color: var(--muted); font-size: 0.9rem; margin-top: 0.3rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.stack { display: grid; gap: 1rem; }
.split { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

.btn-secondary { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--accent); filter: none; }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.82rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }
a.btn { display: inline-block; text-decoration: none; }

select, textarea, input[type="url"], input[type="number"], input[type="datetime-local"], input[type="file"] {
  width: 100%; padding: 0.5rem 0.65rem; font: inherit; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
}
textarea { line-height: 1.5; resize: vertical; }
input[type="color"] { width: 3rem; height: 2.2rem; padding: 0.1rem; border: 1px solid var(--line); background: var(--surface-2); }
input[type="checkbox"] { width: 1rem; height: 1rem; accent-color: var(--accent); }
.check { display: flex; gap: 0.5rem; align-items: center; font-weight: 500; }
.radios ul, .radios > div { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.radios label { display: flex; gap: 0.5rem; align-items: center; font-weight: 500; font-size: 0.92rem; color: var(--ink); }

.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
/* min-width: 0 - fieldsets default to min-content and otherwise overflow narrow cards. */
fieldset { border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 1rem 1rem 0.2rem; margin: 0 0 1rem; min-width: 0; }
legend { font-weight: 700; font-size: 0.85rem; padding: 0 0.4rem; color: var(--ink-2); }

.eyebrow { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

/* setup checklist */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; }
.checklist li { display: grid; grid-template-columns: 1.6rem 1fr auto; gap: 0.6rem; align-items: baseline; padding: 0.6rem 0; border-bottom: 1px solid var(--line-soft); }
.checklist li:last-child { border-bottom: 0; }
.tick { font-family: var(--mono); color: var(--muted); }
.tick.ok { color: var(--ok); }
.checklist .d { display: block; color: var(--muted); font-size: 0.84rem; }

/* stat tiles */
.tiles { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; }
.tile .v { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 0.8rem; }
.meter { height: 6px; background: var(--line-soft); border-radius: 99px; overflow: hidden; margin-top: 0.5rem; }
.meter > span { display: block; height: 100%; background: var(--accent); }

/* board */
.board { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); align-items: start; }
.column { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 0.75rem; }
.column h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.6rem; }
.pcard { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.8rem; text-decoration: none; color: var(--ink); margin-bottom: 0.5rem; }
.pcard:hover { border-color: var(--accent); }
.pcard .t { font-weight: 600; font-size: 0.92rem; line-height: 1.35; }
.pcard .m { color: var(--muted); font-size: 0.78rem; margin-top: 0.3rem; display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }

/* stepper */
.stepper { display: flex; gap: 0.25rem; flex-wrap: wrap; margin: 0 0 1.2rem; padding: 0; list-style: none; }
.stepper li { font-size: 0.74rem; padding: 0.28rem 0.55rem; border-radius: 2px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line-soft); }
.stepper li.done { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.stepper li.now { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); font-weight: 700; }
.stepper li.gate::before { content: "\25C6  "; }

/* gate, busy and failure panels */
.gate-panel { border: 1px solid var(--accent-line); border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.gate-panel h2 { color: var(--accent); margin-bottom: 0.35rem; }
.busy-panel { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; display: flex; gap: 0.8rem; align-items: center; }
.spinner { width: 1rem; height: 1rem; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.fail-panel { border: 1px solid var(--bad); border-left: 3px solid var(--bad); background: var(--bad-soft); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.fail-panel pre { white-space: pre-wrap; font-size: 0.8rem; color: var(--ink-2); margin: 0.6rem 0; max-height: 14rem; overflow: auto; }

/* scenes */
.scenes { display: grid; gap: 0.7rem; }
.scene { display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: 0.8rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem; }
.scene .n { font-family: var(--mono); color: var(--muted); font-size: 0.85rem; }
.scene.hero { border-color: var(--accent-line); }
.scene .narr { font-size: 0.95rem; }
.scene .meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.35rem; display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.scene textarea { font-size: 0.93rem; }
.thumbs { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.thumbs video, .thumbs img { width: 72px; height: 128px; object-fit: cover; border-radius: 2px; border: 1px solid var(--line); background: #000; }
.thumbs.wide video, .thumbs.wide img { width: 128px; height: 72px; }

.player { width: 100%; max-height: 72vh; background: #000; border-radius: var(--radius); border: 1px solid var(--line); display: block; }
.player.vertical { max-width: 380px; margin: 0 auto; aspect-ratio: 9 / 16; }
.thumb-img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); }

.prompt { font-family: var(--mono); font-size: 0.8rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.55rem 0.65rem; white-space: pre-wrap; }
.hash { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); word-break: break-all; }
.finding { display: grid; grid-template-columns: auto 1fr; gap: 0.6rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line-soft); font-size: 0.9rem; }
.finding:last-child { border-bottom: 0; }
.kv-list { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; font-size: 0.9rem; margin: 0; }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; word-break: break-word; }
.small { font-size: 0.82rem; }
.muted { color: var(--muted); }
.sources { margin: 0; padding-left: 1.1rem; font-size: 0.85rem; }
.sources li { margin-bottom: 0.25rem; word-break: break-word; }

.idea { display: grid; gap: 0.35rem; padding: 0.9rem 0; border-bottom: 1px solid var(--line-soft); }
.idea:last-child { border-bottom: 0; }
.idea .t { font-weight: 650; }
.idea .why { color: var(--muted); font-size: 0.86rem; }
.spark { width: 100%; height: 48px; display: block; }
.spark .area { fill: var(--accent-soft); }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark circle { fill: var(--accent); }

/* ---------------- responsive top bar */
.topbar-inner { flex-wrap: wrap; row-gap: 0.4rem; }
.nav { flex-wrap: wrap; row-gap: 0.25rem; min-width: 0; }
.nav a, .nav-more summary { white-space: nowrap; }
@media (max-width: 640px) {
  .topbar-inner { gap: 0.5rem 1rem; }
  .nav { order: 3; flex-basis: 100%; gap: 0.9rem; }
  .org { display: none; }
  .shell { padding: 1.25rem 1rem 3rem; }
  .nav-menu { left: auto; right: -0.5rem; }
}

/* ================================================================ growth analysis */

.stack > .card + .card, .grid-2 > .card + .card { margin-top: 0; }
.tools { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; margin-bottom: 1.25rem; }
.tools .card + .card { margin-top: 0; }
.tool h2 { margin: 0.15rem 0 0.35rem; }
.tool .d { color: var(--muted); font-size: 0.86rem; margin-bottom: 0.9rem; }
.tool-focus { border-color: var(--accent-line); box-shadow: inset 3px 0 0 var(--accent); }
.options { margin: -0.3rem 0 1rem; font-size: 0.88rem; }
.options summary { cursor: pointer; color: var(--ink-2); }
.options[open] summary { margin-bottom: 0.6rem; }

.channel-head, .video-head { display: flex; gap: 1rem; align-items: center; }
.avatar { width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--line); object-fit: cover; flex: none; background: var(--surface-2); }
.vthumb { width: 168px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); flex: none; background: var(--surface-2); }
@media (max-width: 560px) { .video-head { flex-direction: column; align-items: flex-start; } .vthumb { width: 100%; } }

.score-head { display: flex; gap: 1.1rem; align-items: center; margin-bottom: 1.1rem; }
.score-big { font-size: 2.8rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; min-width: 3.2rem; }
.score-big.score-ok { color: var(--ok); }
.score-big.score-warn { color: var(--accent); }
.score-big.score-bad { color: var(--bad); }
.scores { display: grid; gap: 1rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.score-row .row { display: flex; justify-content: space-between; gap: 0.6rem; font-size: 0.88rem; font-weight: 600; }
.score-row .row .mono { font-family: var(--mono); font-size: 0.78rem; font-weight: 500; white-space: nowrap; }
.score-row .why { font-size: 0.82rem; color: var(--muted); margin-top: 0.35rem; line-height: 1.45; }
.meter > span.ok { background: var(--ok); }
.meter > span.warn { background: var(--accent); }
.meter > span.bad { background: var(--bad); }

.bul { margin: 0.6rem 0 0; padding-left: 1.1rem; display: grid; gap: 0.45rem; font-size: 0.92rem; }
.bul li::marker { color: var(--accent); }
.bul.ok li::marker { color: var(--ok); }
.steps { margin: 0.4rem 0 0.6rem; padding-left: 1.2rem; display: grid; gap: 0.3rem; }

.actions-list { list-style: none; counter-reset: act; margin: 0; padding: 0; display: grid; gap: 0.7rem; }
.actions-list > li { display: grid; grid-template-columns: 1.8rem minmax(0, 1fr); gap: 0.6rem; border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 0.8rem 0.9rem; }
.actions-list > li::before { counter-increment: act; content: counter(act); font-family: var(--mono); font-weight: 700; color: var(--accent); }
.actions-list .t { font-weight: 650; margin-bottom: 0.35rem; }
.actions-list .m { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.actions-list p { margin-bottom: 0.4rem; }

.copyrow { display: flex; justify-content: space-between; align-items: center; gap: 0.7rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line-soft); font-size: 0.92rem; }
.copyrow:last-child { border-bottom: 0; }
.copyrow .btn { flex: none; }
