:root {
  --bg: #f6f8fb; --surface: #ffffff; --surface-2: #f1f5f9; --border: #e2e8f0;
  --border-strong: #cbd5e1; --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --accent: #0284c7; --accent-soft: rgba(2, 132, 199, 0.10);
  --working: #16a34a; --waiting: #b45309; --idle: #2563eb; --thinking: #7e22ce;
  --error: #dc2626; --ended: #94a3b8; --stalled: #ea580c;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1a; --surface: #0f172a; --surface-2: #16233a; --border: #1e293b;
    --border-strong: #273549; --text: #e2e8f0; --muted: #8595ac; --faint: #64748b;
    --accent: #38bdf8; --accent-soft: rgba(56, 189, 248, 0.12);
    --working: #4ade80; --waiting: #fbbf24; --idle: #60a5fa; --thinking: #c084fc;
    --error: #f87171; --ended: #64748b; --stalled: #fb923c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}
.st-working { --st: var(--working); } .st-thinking { --st: var(--thinking); }
.st-waiting { --st: var(--waiting); } .st-idle { --st: var(--idle); }
.st-error { --st: var(--error); } .st-ended { --st: var(--ended); } .st-stalled { --st: var(--stalled); }

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0; background: radial-gradient(1100px 500px at 78% -10%, var(--accent-soft), transparent 60%), var(--bg);
  color: var(--text); font-family: var(--mono); font-size: 13px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.shell { max-width: 1600px; margin: 0 auto; padding: 18px 22px 26px; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
code { color: var(--muted); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 11px; }
.mark { width: 34px; height: 34px; flex: none; }
.mark.lg { width: 52px; height: 52px; }
.sweep { transform-origin: 50px 50px; animation: spin 6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sweep { animation: none; } }
.wordmark { display: flex; flex-direction: column; line-height: 1.1; }
.wordmark b { font-weight: 600; font-size: 15px; letter-spacing: -0.2px; }
.wordmark b span { color: var(--accent); }
.wordmark small { color: var(--muted); font-size: 10.5px; letter-spacing: 1.4px; text-transform: uppercase; margin-top: 2px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: 11px; white-space: nowrap; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.ro { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.chip.conn.live { color: var(--working); }
.chip.conn.live .dot { animation: ping 2.2s ease-out infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 var(--accent-soft); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .chip.conn.live .dot { animation: none; } }
.chip.conn.down { color: var(--waiting); }
.chip.signout:hover { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, var(--border)); }

/* ---------- tab bar ---------- */
.tabbar { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab { position: relative; background: none; border: none; padding: 9px 16px 10px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color 0.12s ease; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); font-weight: 700; border-bottom-color: var(--accent); }
.tab .badge { margin-left: 7px; font-size: 10px; font-weight: 700; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--waiting) 16%, transparent); color: var(--waiting); vertical-align: 1px; }

/* ---------- summary bar ---------- */
.summary { display: flex; align-items: center; gap: 18px 20px; flex-wrap: wrap; padding: 11px 16px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.summary .grp { display: inline-flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.cnt { display: inline-flex; align-items: center; gap: 6px; color: var(--st); }
.cnt .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.cnt b { font-weight: 700; } .cnt small { color: var(--muted); font-weight: 400; }
.summary .div { width: 1px; height: 16px; background: var(--border); }
.metric { display: inline-flex; align-items: center; gap: 7px; color: var(--text); }
.metric .lbl { color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; font-size: 10px; }
.metric.rc b { color: var(--working); }
.summary .push { flex: 1; }
.metric.hiddenm { color: var(--faint); background: none; border: none; padding: 0; cursor: pointer; }
.metric.hiddenm:hover { color: var(--accent); }
.metric.hiddenm.on { color: var(--accent); }

/* ---------- table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 1000px; }
thead th { position: sticky; top: 0; z-index: 1; text-align: left; font-weight: 500; color: var(--muted); font-size: 10.5px; letter-spacing: 0.8px; text-transform: uppercase; padding: 10px 11px; background: var(--surface); border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; transition: color 0.12s ease; }
thead th:hover { color: var(--text); }
thead th.nosort { cursor: default; } thead th.nosort:hover { color: var(--muted); }
thead th.num { text-align: right; } tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
th .arrow { color: var(--accent); margin-left: 4px; font-size: 9px; }
th.sorted { color: var(--text); }
tbody tr { cursor: pointer; border-left: 3px solid transparent; transition: background 0.12s ease; }
tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.attn { border-left-color: var(--st); }
tbody tr:hover .det-btn, tbody tr:focus-within .det-btn { border-color: var(--accent); color: var(--accent); }
tbody td { padding: 9px 11px; white-space: nowrap; vertical-align: middle; }
td.name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
td.name .nm { font-weight: 600; color: var(--st); }
td.proj { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
td.branch { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
td.dim { color: var(--muted); } td.faint { color: var(--faint); }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; color: var(--st); background: color-mix(in srgb, var(--st) 13%, transparent); border: 1px solid color-mix(in srgb, var(--st) 26%, transparent); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill .code { font-weight: 500; opacity: 0.8; }
.rc-on { color: var(--working); } .rc-off { color: var(--faint); }
.doing { color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.doing.wait { color: var(--waiting); font-weight: 600; }
.spark { display: block; }
.det-btn { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; border-radius: 7px; background: transparent; border: 1px solid transparent; color: var(--faint); transition: all 0.12s ease; }
.det-btn svg { width: 15px; height: 15px; }
.det-btn:hover, .det-btn:focus-visible { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); outline: none; }

/* ---------- machines ---------- */
.mach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.mach { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.mach-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.mach-head .nm { font-weight: 700; font-size: 15px; } .mach-head .u { color: var(--faint); font-size: 11px; }
.mach-row .big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mach-row .big small { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 5px; }
.mach-brk { display: flex; gap: 12px; flex-wrap: wrap; }
.mach-brk .b { display: inline-flex; align-items: center; gap: 5px; color: var(--st); font-variant-numeric: tabular-nums; }
.mach-brk .b .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; } .mach-brk .b small { color: var(--muted); }
.mach-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; border-top: 1px solid var(--border); padding-top: 10px; }
.mach-foot b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- stats ---------- */
.stat-periods { display: flex; gap: 6px; margin-bottom: 14px; }
.period { background: var(--surface); border: 1px solid var(--border); color: var(--muted); padding: 5px 13px; border-radius: 8px; font-weight: 500; }
.period.active { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: var(--accent-soft); font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 18px; }
.kpi .k { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; }
.kpi .v { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 13px; font-weight: 500; color: var(--muted); }
.stat-cols { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 820px) { .stat-cols { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 4px 18px 16px; }
.card h3 { font-size: 10.5px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 16px 0 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.top { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.top:not(:last-child) { border-bottom: 1px solid var(--surface-2); }
.top .rk { color: var(--faint); width: 18px; font-variant-numeric: tabular-nums; }
.top .nm { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .mc { color: var(--muted); font-size: 11px; } .top .tk { font-variant-numeric: tabular-nums; font-weight: 600; }
.timebar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 6px 0 10px; background: var(--surface-2); }
.timebar i { display: block; height: 100%; background: var(--st); }
.timeleg { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 11px; }
.timeleg .b { display: inline-flex; align-items: center; gap: 6px; color: var(--st); }
.timeleg .b .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; } .timeleg .b b { color: var(--text); font-variant-numeric: tabular-nums; }
.muted-note { color: var(--muted); padding: 8px 0; }

/* ---------- settings ---------- */
.settings { max-width: 640px; }
.set-note { display: flex; gap: 9px; align-items: flex-start; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent); border-radius: 10px; padding: 11px 14px; margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.set-note b { color: var(--accent); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 2px; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-row .k { font-weight: 600; } .set-row .k small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; margin-top: 2px; }
.set-row .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.set-row .v.ok { color: var(--working); }
.set-row .v .signout2 { background: var(--surface); border: 1px solid var(--border); color: var(--muted); padding: 5px 12px; border-radius: 8px; margin-left: 8px; }
.set-row .v .signout2:hover { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, var(--border)); }

/* ---------- detail page ---------- */
.back { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 14px; padding: 6px 12px 6px 9px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); transition: all 0.12s ease; }
.back:hover, .back:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.d-hero { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--st); border-radius: 12px; box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 14px; display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.d-hero .h-main { min-width: 0; flex: 1; }
.d-hero h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.4px; word-break: break-word; }
.d-hero .h-sub { color: var(--muted); margin-top: 5px; font-size: 12.5px; word-break: break-word; }
.d-hero .h-facts { display: flex; gap: 22px; margin-top: 14px; flex-wrap: wrap; }
.fact { display: flex; flex-direction: column; gap: 1px; }
.fact .k { color: var(--faint); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; } .fact .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.d-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 820px) { .d-grid { grid-template-columns: 1fr; } }
.field { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 7px 0; align-items: baseline; }
.field:not(:last-child) { border-bottom: 1px solid var(--surface-2); }
.field .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.field .v { word-break: break-word; } .field .v.mut { color: var(--muted); } .field .v.wait { color: var(--waiting); font-weight: 600; }
.field .v a { color: var(--accent); text-decoration: none; word-break: break-all; }
.field .v a:hover { text-decoration: underline; }
.tok { display: flex; justify-content: space-between; padding: 7px 0; font-variant-numeric: tabular-nums; }
.tok:not(:last-child) { border-bottom: 1px solid var(--surface-2); }
.tok .k { color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-size: 11px; }
.tok.total { font-weight: 700; font-size: 15px; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 10px; } .tok.total .k { color: var(--text); font-size: 11px; }
.act-block { margin-top: 4px; min-height: 46px; display: flex; align-items: center; }

/* ---------- bottom bar (usage + platform) ---------- */
.botbar { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin-top: 18px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.gauges { display: flex; gap: 22px; flex-wrap: wrap; }
.gauge { display: flex; align-items: center; gap: 9px; }
.gauge .lbl { color: var(--muted); text-transform: uppercase; letter-spacing: 1px; font-size: 10px; }
.gauge .track { width: 120px; height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.gauge .track i { display: block; height: 100%; border-radius: 3px; background: var(--working); }
.gauge .track.warn i { background: var(--waiting); }
.gauge .pct { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 34px; }
.gauge .rst { color: var(--faint); font-size: 10.5px; }
.botbar .push { flex: 1; }
.plat { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.plat .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.plat.ok { color: var(--working); } .plat.warn { color: var(--waiting); } .plat.bad { color: var(--error); }

/* ---------- token gate ---------- */
.gate { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 20px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(4px); }
.gate-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 26px; }
.gate-card h1 { margin: 2px 0 0; font-size: 18px; font-weight: 700; letter-spacing: -0.3px; color: var(--text); }
.gate-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.gate-card input { width: 100%; font: inherit; padding: 10px 12px; border-radius: 9px; background: var(--bg); border: 1px solid var(--border-strong); color: var(--text); }
.gate-card input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.gate-err { color: var(--error); font-size: 11.5px; }
.gate-card button { width: 100%; padding: 10px 12px; border-radius: 9px; font-weight: 600; background: var(--accent); color: #fff; border: none; transition: filter 0.12s ease; }
.gate-card button:hover { filter: brightness(1.05); }
