:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #16202c;
  --muted: #5b6878;
  --border: #dbe1e8;
  --accent: #0e7490;
  --accent-contrast: #ffffff;
  --good: #15803d;
  --good-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --muted-bg: #e8ecf1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1620;
    --surface: #17212d;
    --surface-2: #1d2937;
    --text: #e6edf5;
    --muted: #9aa8b8;
    --border: #2a3a4b;
    --accent: #22b8d6;
    --accent-contrast: #06242c;
    --good: #4ade80;
    --good-bg: #12351f;
    --warn: #fbbf24;
    --warn-bg: #3a2e0c;
    --bad: #f87171;
    --bad-bg: #3d1717;
    --info: #7aa7ff;
    --info-bg: #14284d;
    --muted-bg: #243242;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 12px; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 6px; }
.skip:focus { left: 8px; z-index: 20; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a {
  text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar nav a[aria-current="page"] { background: var(--accent); color: var(--accent-contrast); }
a.btn { text-decoration: none; display: inline-block; }
.env { color: var(--muted); font-size: 0.85rem; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
main:focus { outline: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* cards and panels */
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 16px; }
.card, .panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.panel { margin-bottom: 16px; }
.card .label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
.card .value { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.card .sub { color: var(--muted); font-size: 0.85rem; }
.two-col { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.panel.error { border-color: var(--bad); }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* health grid and AI operation list */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.item-head h3 { margin: 0; font-size: 1rem; }
.meta { color: var(--muted); font-size: 0.85rem; }
.meta + .meta { margin-top: 2px; }
.stack > * + * { margin-top: 12px; }
.mt { margin-top: 12px; }
.mt-s { margin-top: 8px; }
.err-text { color: var(--bad); font-size: 0.85rem; word-break: break-word; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.nowrap { white-space: nowrap; }
.sub-line { color: var(--muted); font-size: 0.8rem; }

/* badges */
.badge {
  display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  white-space: nowrap; background: var(--muted-bg); color: var(--muted);
}
.b-good { background: var(--good-bg); color: var(--good); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: var(--info-bg); color: var(--info); }

/* forms and buttons */
form.inline-form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
label, .label-text { font-size: 0.85rem; font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 7px 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 10px; font-size: 0.85rem; }
details.panel summary { cursor: pointer; font-weight: 600; }
details.panel[open] summary { margin-bottom: 12px; }
.pager { display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 12px; color: var(--muted); }
.filters { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; align-items: end; }
.filters .field { min-width: 160px; }

/* toast */
#toast {
  position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px));
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px;
  opacity: 0; transform: translateY(8px); transition: opacity 0.15s, transform 0.15s; pointer-events: none; z-index: 30;
}
#toast.show { opacity: 1; transform: none; }
#toast.error { background: var(--bad); color: #fff; }

[aria-busy="true"] { opacity: 0.6; }

@media (max-width: 700px) {
  .brand { order: 1; }
  .user { order: 2; margin-left: auto; }
  .topbar nav { order: 3; flex-basis: 100%; }
}

@media (max-width: 600px) {
  .topbar { gap: 8px; }
  .card .value { font-size: 1.6rem; }
}

/* ---- sign-in screens ---- */
.signed-out .topbar { display: none; }
.auth { display: flex; justify-content: center; padding: 8vh 0 0; }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
.auth-card form { display: grid; gap: 14px; margin-top: 16px; }
.brand.big { font-size: 1.3rem; margin-bottom: 12px; }
.btn.block { width: 100%; padding: 10px 14px; }

/* ---- top bar user area ---- */
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.who { text-decoration: none; color: var(--text); font-weight: 600; }

/* ---- layout helpers ---- */
.two-col { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.offscreen { position: fixed; left: -9999px; top: 0; }
.hint { color: var(--muted); font-size: 0.8rem; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; }
.check input { width: auto; }
.card.alert { border-color: var(--bad); }
.card .value.small { font-size: 1.2rem; word-break: break-word; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 6px; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 0.9em; }
.block-text { display: block; }

/* ---- banners ---- */
.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.banner.bad { border-color: var(--bad); background: var(--bad-bg); }
.banner.good { border-color: var(--good); background: var(--good-bg); }
.token-box .code { margin-top: 8px; }

/* ---- tabs ---- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- code blocks ---- */
.code { position: relative; }
.code pre {
  margin: 0; padding: 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  overflow-x: auto; font: 0.85rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all;
}
.code .copy { position: absolute; top: 8px; right: 8px; }

/* ---- charts ---- */
.spark, .strip { display: block; width: 100%; }
.spark { height: 48px; margin-top: 6px; }
.strip { height: 14px; margin-top: 8px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark-area { fill: var(--accent); opacity: 0.12; }
.st-healthy { fill: var(--good); }
.st-degraded { fill: var(--warn); }
.st-down { fill: var(--bad); }
.st-unknown { fill: var(--muted); }
.health-charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.health-charts .spark { height: 64px; }

/* ---- Release Command Center ---- */
.pill { display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em; border: 1px solid transparent; }
.pill-good { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.pill-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.pill-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }

.candidates { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; }
.cand {
  display: flex; align-items: center; gap: 10px; flex: 0 0 auto; max-width: 340px; cursor: pointer; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 8px 6px 14px;
}
.cand:hover { background: var(--surface-2); }
.cand.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.cand-id { font-weight: 800; }
.cand-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; color: var(--muted); }

.story {
  display: grid; gap: 24px; align-items: center; grid-template-columns: 170px minmax(260px, 1fr) minmax(300px, 1.1fr);
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  border-left: 6px solid var(--border);
}
.story.s-go { border-left-color: var(--good); }
.story.s-review { border-left-color: var(--warn); }
.story.s-block { border-left-color: var(--bad); }
.story-gauge { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.72rem; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.story h2 { font-size: 1.7rem; margin: 0 0 4px; }
.story-title { font-weight: 600; margin: 0 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { font-size: 0.78rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; }
a.chip:hover { border-color: var(--accent); }
.chip-good { border-color: var(--good); color: var(--good); }
.chip-warn { border-color: var(--warn); color: var(--warn); }

.gauge { width: 150px; height: 150px; }
.gauge-track { stroke: var(--border); }
.gauge-fill { stroke: var(--accent); transition: stroke-dasharray 0.6s ease; }
.gauge.d-go .gauge-fill { stroke: var(--good); }
.gauge.d-review .gauge-fill { stroke: var(--warn); }
.gauge.d-block .gauge-fill { stroke: var(--bad); }
.gauge-num { font-size: 38px; font-weight: 800; fill: var(--text); }
.gauge-cap { font-size: 10px; letter-spacing: 0.2em; fill: var(--muted); font-weight: 700; }

.story-checks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.check-card { padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--border); min-width: 0; }
.cc-name { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.cc-value { font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.check-card.cc-pass { border-top-color: var(--good); }
.check-card.cc-warn { border-top-color: var(--warn); }
.check-card.cc-fail { border-top-color: var(--bad); }
.check-card.cc-fail .cc-value { color: var(--bad); }

.reasons, .timeline { list-style: none; margin: 0; padding: 0; }
.reason { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.reason:last-child { border-bottom: none; }
.r-icon { flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 0.75rem; font-weight: 800; background: var(--muted-bg); color: var(--muted); }
.r-good .r-icon { background: var(--good-bg); color: var(--good); }
.r-warn .r-icon { background: var(--warn-bg); color: var(--warn); }
.r-block .r-icon { background: var(--bad-bg); color: var(--bad); }
.r-text { flex: 1; overflow-wrap: anywhere; }
.r-points { color: var(--muted); font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: none; }
.tl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-text { color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }

.flow { display: grid; grid-template-columns: repeat(9, auto); align-items: stretch; gap: 8px; }
.flow-step { grid-column: span 1; min-width: 0; padding: 12px; border-radius: 10px; border: 1px dashed var(--border); opacity: 0.6; background: var(--surface); }
.flow-step.done { opacity: 1; border-style: solid; border-color: var(--accent); }
.flow-stage { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 700; }
.flow-agent { font-weight: 800; margin: 2px 0 6px; }
.flow-note { font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.flow-time { font-size: 0.72rem; color: var(--muted); margin-top: 6px; }
.flow-arrow { align-self: center; color: var(--muted); font-weight: 800; }

@media (max-width: 1000px) {
  .story { grid-template-columns: 1fr; }
  .story-gauge { flex-direction: row; justify-content: flex-start; }
  .flow { grid-template-columns: 1fr; }
  .flow-arrow { transform: rotate(90deg); justify-self: center; }
}
