:root {
  --bg: #f6f7f9; --card: #fff; --text: #1d2330; --muted: #657085; --border: #dfe3ea;
  --accent: #2f6fde; --green: #128a4a; --red: #c8322f; --amber: #b7791f;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11141a; --card: #1a1f28; --text: #e6e9ef; --muted: #98a2b3; --border: #2b3240;
          --accent: #5b8ff0; --green: #3cc47c; --red: #ef6461; --amber: #e0a43c; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
         padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border); }
header h1 { font-size: 18px; margin: 0; }
nav button { background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; font-size: 14px; border-radius: 6px; }
nav button.active { color: var(--text); background: var(--bg); font-weight: 600; }
#user { color: var(--muted); display: flex; gap: 8px; align-items: center; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; overflow-x: auto; }
.card.narrow { max-width: 460px; margin: 60px auto; text-align: center; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.pos { color: var(--green); } .neg { color: var(--red); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.params { display: contents; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
input, select { font: inherit; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.btn { display: inline-block; font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border);
       background: var(--card); color: var(--text); cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.mode-card { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.badge { padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.badge.paper { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge.live { background: var(--red); color: #fff; }
.badge.halted { background: color-mix(in srgb, var(--amber) 22%, transparent); color: var(--amber); }
.warn { color: var(--amber); } .error { color: var(--red); min-height: 1em; }
.muted { color: var(--muted); }
.events { max-height: 360px; overflow-y: auto; font-size: 13px; }
.events div { padding: 4px 0; border-bottom: 1px dashed var(--border); }
.events .k-error, .events .k-risk { color: var(--red); }
dialog { border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text); max-width: 440px; }
dialog input { width: 100%; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
         padding: 10px 16px; border-radius: 8px; max-width: calc(100% - 32px); }
svg.chart { width: 100%; height: 260px; }
svg.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.5; }
svg.chart .axis { fill: var(--muted); font-size: 11px; }
svg.chart .grid { stroke: var(--border); }
code { word-break: break-all; }
