:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1a1d23;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #2f6fed;
  --pos: #0f9d58;
  --neg: #d93025;
  --warn: #b26a00;
  --warn-bg: #fff4e0;
  --err-bg: #fdecea;
  --ok-bg: #e7f6ee;
  --chip: #eef2fb;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a21; --panel-2: #1e222b; --text: #e6e8ec; --muted: #9aa3b2;
    --border: #2a2f3a; --accent: #6b9bff; --pos: #3ccf84; --neg: #ff6b5e; --warn: #f0b44c;
    --warn-bg: #2d2412; --err-bg: #331a18; --ok-bg: #12291d; --chip: #222a3a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1e222b; --text: #e6e8ec; --muted: #9aa3b2;
  --border: #2a2f3a; --accent: #6b9bff; --pos: #3ccf84; --neg: #ff6b5e; --warn: #f0b44c;
  --warn-bg: #2d2412; --err-bg: #331a18; --ok-bg: #12291d; --chip: #222a3a; color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
header.top .brand { font-weight: 700; letter-spacing: .2px; }
header.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
header.top nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); }
header.top nav a.active, header.top nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
header.top .nav-sec { display: contents; }  /* desktop: one inline row, as before */
header.top .here, header.top .navtoggle, header.top .navbtn { display: none; }

/* phones and narrow tablets: one compact bar; the menu opens under it, grouped, two columns */
@media (max-width: 900px) {
  header.top { gap: 10px; flex-wrap: nowrap; padding: 8px 14px; }
  header.top .brand { font-size: 15px; white-space: nowrap; }
  header.top .here {
    display: block; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--muted); font-size: 14px;
  }
  header.top .navbtn {
    display: inline-flex; align-items: center; padding: 7px 12px; border: 1px solid var(--border);
    border-radius: 8px; background: var(--panel-2); cursor: pointer; white-space: nowrap; user-select: none;
  }
  header.top form.inline button { padding: 7px 10px; }
  header.top nav {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    background: var(--panel); border-bottom: 1px solid var(--border); box-shadow: 0 8px 18px rgba(0, 0, 0, .08);
    padding: 6px 14px 12px; max-height: calc(100vh - 56px); overflow-y: auto;
  }
  header.top .navtoggle:checked ~ nav { display: block; }
  header.top .navtoggle:checked + .navbtn { background: var(--panel); border-color: var(--accent); color: var(--accent); }
  header.top .nav-sec {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 8px 0; border-bottom: 1px solid var(--border);
  }
  header.top .nav-sec:last-child { border-bottom: 0; }
  header.top .nav-group { grid-column: 1 / -1; border-left: 0; margin: 0; padding: 2px 0 2px; font-size: 12px; }
  header.top nav a { padding: 9px 10px; background: var(--panel-2); color: var(--text); }
  header.top nav a.active { background: var(--accent); color: #fff; }
}
main { padding: 20px; max-width: 1500px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
td.muted { white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; background: var(--panel); position: sticky; top: 0; }
tr:hover td { background: var(--panel-2); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--chip); font-size: 12px; margin: 1px 2px 1px 0; white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--pos); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.err { background: var(--err-bg); color: var(--neg); }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--border); }
.banner.err { background: var(--err-bg); color: var(--neg); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.ok { background: var(--ok-bg); color: var(--pos); }
form.inline { display: inline; }
input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px;
}
button { cursor: pointer; background: var(--panel-2); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { background: var(--neg); color: #fff; border-color: var(--neg); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chart { width: 100%; height: 300px; }
.params { display: grid; grid-template-columns: minmax(160px, max-content) 1fr; gap: 6px 12px; align-items: center; }
.params input { width: 100%; max-width: 420px; }
.reason { max-width: 520px; }
.trunc { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details summary { cursor: pointer; color: var(--muted); }
pre { white-space: pre-wrap; word-break: break-word; background: var(--panel-2); padding: 8px; border-radius: 6px; margin: 6px 0; }
.login { max-width: 360px; margin: 12vh auto; }
.login input { width: 100%; margin: 10px 0; }
.login button { width: 100%; }
@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .cols-2, .cols-3 { grid-template-columns: 1fr; }
  header.top { padding: 8px 16px; }
}

/* ---- pipeline */
.flow { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; counter-reset: step; }
.step { position: relative; display: flex; flex-direction: column; gap: 6px; color: var(--text); }
.step:hover { border-color: var(--accent); text-decoration: none; }
.step .no { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; margin-right: 6px; }
.step h3 { margin: 0; font-size: 15px; display: flex; align-items: center; }
.step h3 .go { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 12px; }
.step .big { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.step .kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 13px; }
.step .kv span:nth-child(odd) { color: var(--muted); }
.step .kv span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.step .sub-h { font-size: 12px; color: var(--muted); margin-top: 4px; border-top: 1px dashed var(--border); padding-top: 6px; }
.step::after { content: "→"; position: absolute; right: -13px; top: 50%; color: var(--muted); font-size: 14px; }
.step:last-child::after { content: none; }
@media (max-width: 640px) { .step::after { content: "↓"; right: 50%; top: auto; bottom: -15px; } }
.ok-dot, .bad-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.ok-dot { background: var(--pos); } .bad-dot { background: var(--neg); }

/* ---- 18 stages: status lights and the end-to-end funnel */
.step.st-ok { border-left: 4px solid var(--pos); }
.step.st-degraded { border-left: 4px solid var(--warn); }
.step.st-failed { border-left: 4px solid var(--neg); background: var(--err-bg); }
.step.st-bottleneck { border: 2px solid var(--warn); border-left-width: 6px; box-shadow: 0 0 0 3px var(--warn-bg); }
.step.st-unimplemented { border-style: dashed; opacity: .85; }
.step.st-idle { opacity: .6; }
.light { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; flex: none; background: var(--muted); }
.light.ok { background: var(--pos); } .light.degraded, .light.bottleneck { background: var(--warn); }
.light.failed { background: var(--neg); } .light.unimplemented, .light.idle { background: transparent; border: 2px dashed var(--muted); width: 6px; height: 6px; }
.step .owners { display: flex; flex-wrap: wrap; gap: 2px; font-size: 12px; }
.step .why { font-size: 12px; color: var(--warn); }
.step.st-failed .why { color: var(--neg); }
.step .err-line { font-size: 12px; color: var(--neg); overflow-wrap: anywhere; }
.e2e { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; }
.e2e .cell { background: var(--panel-2); border-radius: 8px; padding: 8px; border: 1px solid var(--border); min-width: 0; }
.e2e .cell .lbl { font-size: 12px; color: var(--muted); }
.e2e .cell .n { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.e2e .cell .d { font-size: 12px; }
.e2e .cell .bar { height: 5px; background: var(--chip); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.e2e .cell .bar i { display: block; height: 100%; background: var(--accent); }
.e2e .cell.hot { border: 2px solid var(--warn); background: var(--warn-bg); }
.e2e .cell.fixed .d { color: var(--muted); }

/* ---- tabs / pagination */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.pager { display: flex; gap: 6px; align-items: center; margin: 12px 0; color: var(--muted); }
.pager a { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; }

/* ---- funnel */
.funnel { display: grid; gap: 6px; }
.funnel .row { display: grid; grid-template-columns: minmax(220px, 300px) 1fr 140px; gap: 12px; align-items: center; }
.funnel .bar { height: 18px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.funnel .bar i { display: block; height: 100%; background: var(--accent); }
.funnel .row.final .bar i { background: var(--pos); }
@media (max-width: 640px) { .funnel .row { grid-template-columns: 1fr; } }

/* ---- progress & timeline */
.prog { width: 110px; height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; }
.prog i { display: block; height: 100%; background: var(--pos); }
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 16px 14px; }
.timeline li::before { content: ""; position: absolute; left: -25px; top: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--accent); }
.timeline li.k-fill::before, .timeline li.k-closed::before { border-color: var(--pos); background: var(--pos); }
.timeline li.k-exit\.triggered::before { border-color: var(--warn); }
.timeline .t-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.timeline .t-step { font-size: 12px; color: var(--accent); font-weight: 600; }

/* ---- real vs paper */
:root { --real: #c0392b; --real-bg: #fdecea; --paper: #2f6fed; --paper-bg: #eaf1fe; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --real-bg: #3a1c19; --paper-bg: #17233d; } }
:root[data-theme="dark"] { --real-bg: #3a1c19; --paper-bg: #17233d; }
.nav-group { font-size: 11px; color: var(--muted); padding: 6px 2px 6px 10px; border-left: 1px solid var(--border); margin-left: 4px; }
.nav-group.nav-real { color: var(--real); font-weight: 700; }
.nav-group.nav-paper { color: var(--paper); font-weight: 700; }
.scope { padding: 6px 20px; font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--border); }
.scope-real { background: var(--real-bg); color: var(--real); }
.scope-paper { background: var(--paper-bg); color: var(--paper); }
.scope-shared { background: var(--panel-2); color: var(--muted); }
.chip.real { background: var(--real-bg); color: var(--real); font-weight: 700; }
.chip.paper { background: var(--paper-bg); color: var(--paper); }
.mode-switch { display: inline-flex; margin-right: 12px; border: 1px solid currentColor; border-radius: 6px; overflow: hidden; vertical-align: middle; }
.mode-switch a { padding: 2px 10px; color: inherit; font-weight: 600; }
.mode-switch a.on { background: currentColor; }
.scope-paper .mode-switch a.on { color: #fff; background: var(--paper); }
.scope-real .mode-switch a.on { color: #fff; background: var(--real); }
.mode-switch a:hover { text-decoration: none; }
