:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #dfe1e6;
  --text: #16181d;
  --text-2: #4f5562;
  --muted: #7a8090;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #c02626;
  --ok-bg: #dcfce7;
  --warn-bg: #fef3c7;
  --bad-bg: #fee2e2;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2b303a;
    --text: #e8eaee;
    --text-2: #b4b9c4;
    --muted: #868c99;
    --accent: #4f8ef7;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --ok-bg: #12301f;
    --warn-bg: #3a2d0b;
    --bad-bg: #3b1515;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-2); }

/* ---------- layout ---------- */
.topbar { display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 54px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand svg { width: 22px; height: 22px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { padding: 7px 12px; border-radius: 6px; color: var(--text-2); white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; white-space: nowrap; }
main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; }
textarea { font-family: var(--mono); font-size: 13px; width: 100%; min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 99px; font-size: 12px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--ok); }
.tag { display: inline-block; padding: 0 7px; margin: 1px 2px 1px 0; border-radius: 4px; font-size: 12px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--bad); }

/* ---------- meters ---------- */
.meter { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.meter .bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 60px; }
.meter .bar > span { display: block; height: 100%; background: var(--s1); border-radius: 3px; }
.meter .bar > span.warn { background: var(--warn); }
.meter .bar > span.bad { background: var(--bad); }
.meter .val { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--text-2); width: 44px; text-align: right; }

.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--text-2); font-size: 12.5px; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- output ---------- */
pre.out { background: #0b0d10; color: #d6dae2; padding: 12px; border-radius: 6px; overflow: auto; max-height: 520px;
  white-space: pre-wrap; word-break: break-all; margin: 0; }
pre.out .stderr { color: #f59e9e; }

.term-wrap { background: #0b0d10; border-radius: var(--radius); padding: 8px; height: calc(100vh - 290px); min-height: 380px; }
.term-wrap .xterm { height: 100%; }

/* ---------- chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 180px; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.15); white-space: nowrap; display: none; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 60px 16px; overflow: auto; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; width: 100%; max-width: 720px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: 10px 14px;
  border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 420px; }
.toast.error { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }

.login-box { max-width: 420px; margin: 12vh auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px; text-align: center; }
.login-box h1 { margin-bottom: 8px; font-size: 24px; }
.login-box p { color: var(--text-2); }
.copy { position: relative; }
.copy pre { margin: 0; padding: 10px 92px 10px 12px; background: var(--surface-2); border-radius: 6px; white-space: pre-wrap; word-break: break-all; }
.copy .btn { position: absolute; top: 6px; right: 6px; }

details.result { border-bottom: 1px solid var(--border); }
details.result summary { padding: 9px 12px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
details.result[open] summary { background: var(--surface-2); }
details.result .body { padding: 10px 12px; }

@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .userbox .who { display: none; }
  main { padding: 16px; }
  .grid.cols-2 { grid-template-columns: 1fr; }
}

/* ---------- git scripts ---------- */
textarea.readonly { background: var(--surface-2); color: var(--text-2); cursor: default; }
.gitinfo { border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 6px; padding: 8px 12px; margin-bottom: 10px; background: var(--surface-2); }
.gitinfo a { cursor: pointer; }
optgroup { font-weight: 600; }
