:root {
  color-scheme: light;
  --bg: #EDF0F2; --surface: #FFFFFF; --sunken: #E3E8EB; --ink: #18252F; --muted: #5A6873; --line: #CDD5DB;
  --signal: #9A6A00; --signal-bg: #FFF3D1; --run: #13756F; --run-bg: #DDF2EF; --stop: #B83A27; --stop-bg: #FBE6E2;
  --done: #3D6B2E; --done-bg: #E4F0DD; --primary: #2F45C6; --on-primary: #FFFFFF;
  --head: "Barlow Semi Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141B21; --surface: #1C252D; --sunken: #111820; --ink: #E6ECF0; --muted: #95A3AE; --line: #2E3A44;
    --signal: #F0B429; --signal-bg: #3A2F10; --run: #3CC0B8; --run-bg: #12302E; --stop: #F07560; --stop-bg: #3B1C17;
    --done: #8CCB72; --done-bg: #1D2E17; --primary: #8394FF; --on-primary: #10163A;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 1rem/1.5 var(--body); }
a { color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--head); letter-spacing: -0.005em; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100%; }
.side { position: sticky; top: 0; align-self: start; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 22px 16px; border-right: 1px solid var(--line); background: var(--surface); }
.brand { font: 700 1.35rem/1.1 var(--head); color: var(--ink); text-decoration: none; padding: 0 8px; }
.server { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px; background: var(--sunken); color: var(--ink); text-decoration: none; font-size: .92rem; line-height: 1.25; }
.nav { display: grid; gap: 2px; }
.nav a { padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; }
.nav a:hover { color: var(--ink); background: var(--sunken); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--sunken); box-shadow: inset 3px 0 0 var(--primary); }
.side-foot { margin-top: auto; display: grid; gap: 6px; }
.main { padding: 28px clamp(16px, 3vw, 40px) 64px; max-width: 1240px; width: 100%; outline: none; }

.lamp { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 20%, transparent); }
.lamp[data-state="ok"] { background: var(--run); box-shadow: 0 0 0 4px color-mix(in srgb, var(--run) 25%, transparent); }
.lamp[data-state="stale"] { background: var(--stop); box-shadow: 0 0 0 4px color-mix(in srgb, var(--stop) 25%, transparent); }
.lamp.big { width: 20px; height: 20px; box-shadow: 0 0 0 7px color-mix(in srgb, var(--muted) 18%, transparent); }
.lamp.big[data-state="ok"] { box-shadow: 0 0 0 7px color-mix(in srgb, var(--run) 22%, transparent); }
.lamp.big[data-state="stale"] { box-shadow: 0 0 0 7px color-mix(in srgb, var(--stop) 22%, transparent); }

/* ---------- page furniture ---------- */
.page-head { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: clamp(1.7rem, 3.4vw, 2.3rem); line-height: 1.05; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-weight: 600; }
.back:hover { color: var(--ink); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.panel h2 { margin: 0 0 12px; font-size: 1.25rem; }
.panel + .panel, .stack > * + * { margin-top: 16px; }
.grid2 { margin: 16px 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 > .panel + .panel { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 15px; border-radius: 8px; cursor: pointer; font: 600 .95rem/1.2 var(--body); text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.danger { color: var(--stop); border-color: color-mix(in srgb, var(--stop) 50%, var(--line)); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- dashboard ---------- */
.hero { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin-bottom: 22px; }
.hero > div { flex: 1 1 260px; }
.hero h1 { margin: 0; font-size: clamp(1.9rem, 4vw, 2.7rem); line-height: 1.02; }
.hero p { margin: 4px 0 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 16px; }
.stat { background: var(--surface); padding: 14px 16px; color: var(--ink); text-decoration: none; }
.stat:hover { background: var(--sunken); }
.stat b { display: block; font: 600 2rem/1 var(--head); }
.stat span { color: var(--muted); font-size: .92rem; }
.stat.attention b { color: var(--signal); }
.stat.failed b { color: var(--stop); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 11px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; padding-top: 2px; }
.row { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.row .grow { flex: 1 1 240px; min-width: 0; }
.row .title { font-weight: 600; color: var(--ink); text-decoration: none; }
.row a.title:hover { text-decoration: underline; }
.meta { color: var(--muted); font-size: .88rem; }
.id { color: var(--muted); font-weight: 600; font-size: .9rem; margin-right: 4px; }
.empty { padding: 18px 0 6px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 2px; }

.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .82rem; font-weight: 600; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.chip.waiting { background: var(--sunken); color: var(--ink); }
.chip.active { background: var(--run-bg); color: var(--run); }
.chip.attention { background: var(--signal-bg); color: var(--signal); }
.chip.done { background: var(--done-bg); color: var(--done); }
.chip.failed { background: var(--stop-bg); color: var(--stop); }

.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 14px 4px; }
.timeline li::before { content: ""; position: absolute; left: -24px; top: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--muted); }
.timeline time { display: block; color: var(--muted); font-size: .85rem; }

/* ---------- filters & forms ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.filters select, .filters input { width: auto; min-width: 140px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; }
textarea { resize: vertical; min-height: 110px; line-height: 1.45; }
textarea.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9rem; }
.form { display: grid; gap: 16px; max-width: 760px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; }
.field small, .hint { color: var(--muted); font-size: .88rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: fit-content; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label { padding: 8px 18px; cursor: pointer; background: var(--surface); }
.seg input:checked + label { background: var(--ink); color: var(--surface); }
.seg input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: -2px; }
.form-error { color: var(--stop); margin: 0; min-height: 1.2em; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { appearance: none; width: 42px; height: 24px; padding: 0; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; border: 0; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.switch input:checked { background: var(--run); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:disabled { opacity: .5; cursor: not-allowed; }

.banner { padding: 14px 16px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--signal) 45%, transparent); background: var(--signal-bg); margin-bottom: 16px; }
.banner.error { border-color: color-mix(in srgb, var(--stop) 45%, transparent); background: var(--stop-bg); color: var(--stop); }
.banner b { display: block; margin-bottom: 2px; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 10; max-width: calc(100vw - 32px); }
.loading { color: var(--muted); padding: 24px 0; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(360px, 100%); display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 2.2rem; line-height: 1; }
.login p { margin: 0; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; z-index: 5; height: auto; display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 12px 14px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
  .side { top: env(safe-area-inset-top, 0px); }
  .brand { padding: 0; align-self: center; }
  .server { padding: 6px 10px; font-size: .85rem; }
  .nav { grid-column: 1 / -1; display: flex; overflow-x: auto; gap: 4px; margin: 0 -14px; padding: 0 14px 10px; scrollbar-width: none; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--primary); }
  .side-foot { display: none; }
  .main { padding-top: 20px; }
  .grid2, .two { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .hero h1 { font-size: 1.8rem; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
