:root {
  --bg: #0d1117; --panel: #151b23; --panel-2: #1b222c; --border: #263040; --text: #e6edf3; --muted: #8b98a9;
  --ok: #3fb950; --warn: #e3a008; --bad: #f85149; --idle: #7d8da1; --accent: #58a6ff;
  --c1: #58a6ff; --c2: #bc8cff; --c3: #f0883e; --c4: #39c5bb;
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f4f6f9; --panel: #ffffff; --panel-2: #f0f3f7; --border: #dbe1e8; --text: #18212d; --muted: #5b6878;
    --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e; --idle: #6b7785; --accent: #0969da;
    --c1: #0969da; --c2: #8250df; --c3: #bc4c00; --c4: #0e8a82; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }

/* header */
.top { display: flex; align-items: center; gap: 16px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--panel); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .01em; }
.brand svg { width: 26px; height: 26px; }
.brand small { color: var(--muted); font-weight: 450; }
.spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); font-weight: 600; }
.btn { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
.live.stale i { background: var(--bad); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

main { max-width: 1500px; margin: 0 auto; padding: 20px 24px 60px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.tile .v { font-size: 28px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 13px; color: var(--muted); font-weight: 450; margin-left: 4px; }
.tile.ok .v { color: var(--ok); } .tile.warn .v { color: var(--warn); } .tile.bad .v { color: var(--bad); }
.tile.dim .v { color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.panel > h2 { margin: 0; padding: 12px 16px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.panel .body { padding: 14px 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; }
.chart-card h3 .legend { font-weight: 450; color: var(--muted); font-size: 12px; display: flex; gap: 12px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .tip { position: absolute; pointer-events: none; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap; display: none; z-index: 3; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.chart .tip b { font-weight: 600; }
.empty-chart { color: var(--muted); padding: 34px 0; text-align: center; font-size: 13px; }
.axis { fill: var(--muted); font-size: 10.5px; }
.gridline { stroke: var(--border); stroke-width: 1; }

/* table */
.tools { display: flex; gap: 10px; align-items: center; margin-left: auto; text-transform: none; letter-spacing: 0; }
.tools input { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; width: 220px; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 9px 12px; white-space: nowrap; border-bottom: 1px solid var(--border); }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: right; }
.name { font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; }
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 10px 2px 8px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s-online { color: var(--ok); } .s-degraded { color: var(--warn); } .s-offline { color: var(--bad); } .s-idle, .s-pending { color: var(--idle); }
.meter { display: inline-block; width: 56px; height: 6px; border-radius: 3px; background: var(--panel-2); border: 1px solid var(--border); vertical-align: middle; margin-right: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ok); }
.meter i.w { background: var(--warn); } .meter i.b { background: var(--bad); }
.spark { width: 96px; height: 24px; display: block; }
.reason { color: var(--warn); font-size: 12px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.offline-row td { opacity: .85; }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin: 0 0 8px; }
.empty code, .code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px; font-family: var(--mono); font-size: 12.5px; }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(980px, 100%); background: var(--bg); z-index: 11; overflow-y: auto; border-left: 1px solid var(--border); box-shadow: -20px 0 50px rgba(0,0,0,.35); }
.drawer header { display: flex; gap: 14px; align-items: center; padding: 16px 22px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.drawer header h1 { margin: 0; font-size: 18px; }
.drawer .inner { padding: 18px 22px 40px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 20px; }
.kv div span { display: block; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.kv div b { font-weight: 550; word-break: break-all; }
.alert { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); border-radius: 8px; padding: 9px 12px; margin-bottom: 14px; }
.alert.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.events li { padding: 7px 0; border-bottom: 1px solid var(--border); list-style: none; display: flex; gap: 12px; }
.events { margin: 0; padding: 0; }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); min-width: 118px; font-size: 12px; font-variant-numeric: tabular-nums; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: 340px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login label { display: block; margin: 14px 0 5px; color: var(--muted); font-size: 12px; }
.login input { width: 100%; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; }
.login input:focus, .tools input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login button { width: 100%; margin-top: 18px; background: var(--accent); color: #fff; border: 0; padding: 10px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.login .err { color: var(--bad); min-height: 20px; margin-top: 12px; font-size: 13px; }

@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(3, 1fr); } .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 640px) { main { padding: 14px 12px 40px; } .top { padding: 10px 12px; } .tiles { grid-template-columns: repeat(2, 1fr); } .tools input { width: 130px; } }
