:root {
  --bg: #0e1116; --surface: #161b22; --surface-2: #1c2330; --border: #2a3342;
  --text: #e6edf3; --muted: #8b98a9; --accent: #4c9aff; --accent-ink: #06111f;
  --ok: #3fb950; --warn: #d29922; --bad: #f85149; --idle: #6e7b8c;
  --k-venv: #8957e5; --k-database: #4c9aff; --k-logs: #d29922; --k-data: #3fb950; --k-files: #8b98a9; --k-cache: #5b6676;
  --radius: 12px; --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef1f5; --border: #d8dee6;
    --text: #1b2430; --muted: #5f6b7a; --accent: #1f6feb; --accent-ink: #ffffff;
    --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e; --idle: #8792a2;
    --k-venv: #7c4dd6; --k-database: #1f6feb; --k-logs: #bf8700; --k-data: #2da44e; --k-files: #8792a2; --k-cache: #aab3c0;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 28px 0 12px; font-weight: 600; }
h2 .muted { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 6px; }
h3 { margin: 0; font-size: 16px; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* buttons */
.btn { font: inherit; font-weight: 500; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; min-height: 34px; transition: background .12s, border-color .12s; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; min-height: 28px; font-size: 13px; }

/* top bar */
.top { display: flex; align-items: center; gap: 14px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; display: inline-block; }
.logo::after { content: ""; position: absolute; inset: 6px 4px 5px; border: 2px solid var(--accent-ink); border-width: 0 0 2px 2px; transform: skewX(-30deg); }
.host-meta { font-size: 13px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.live.off i { background: var(--bad); }
.live.off { color: var(--bad); }
.page { max-width: 1200px; margin: 0 auto; padding: 4px 20px 60px; }

/* host tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-top: 20px; }
.tile, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; min-height: 18px; }
.tile svg.spark { margin-top: 8px; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.meter.hot i { background: var(--warn); }
.meter.crit i { background: var(--bad); }

/* bot cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.card { display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-head h3 { overflow-wrap: anywhere; }
.card-head .desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.pill.running::before { background: var(--ok); }
.pill.starting::before, .pill.stopping::before { background: var(--warn); animation: pulse 1s infinite; }
.pill.failed::before, .pill.missing::before { background: var(--bad); }
.pill.failed { color: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.note { font-size: 12.5px; color: var(--bad); overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.actions .btn { flex: 0 0 auto; }
svg.spark { display: block; width: 100%; height: 34px; }
svg.spark path.line { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
svg.spark path.area { fill: var(--accent); opacity: .14; }

/* usage by bot */
.usage { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.usage .card { gap: 10px; }
.usage .card h4 { margin: 0; font-size: 13px; display: flex; justify-content: space-between; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 72px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }

/* activity */
.events { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.events li { padding: 9px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; font-size: 13px; }
.events li:last-child { border-bottom: 0; }
.events .when { color: var(--muted); min-width: 74px; }
.events .fail { color: var(--bad); }
.events.empty li { color: var(--muted); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card p { margin: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input:not([type]), select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; }
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.form-error { color: var(--bad); font-size: 13px; }

/* detail dialog */
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.detail { width: min(920px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
.detail[open] { display: flex; flex-direction: column; }
.d-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.d-head .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; padding: 0 14px; border-bottom: 1px solid var(--border); }
.tab { font: inherit; background: none; border: 0; color: var(--muted); padding: 11px 12px; cursor: pointer; border-bottom: 2px solid transparent; }
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
.d-body { padding: 18px 20px 22px; overflow: auto; display: flex; flex-direction: column; gap: 22px; }
.d-section h4 { margin: 0 0 8px; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.d-section h4 .spacer { flex: 1; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 18px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 12px; background: none; color: var(--muted); border: 0; padding: 4px 10px; cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--surface-2); color: var(--text); }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; }
.chart .area { fill: var(--accent); opacity: .13; }
.chart .cursor { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .tip { position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -125%); }
.chart .empty { padding: 36px 0; text-align: center; color: var(--muted); }
.stack { margin-top: 8px; display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.stack i { display: block; height: 100%; min-width: 2px; }
.k-venv { background: var(--k-venv); } .k-database { background: var(--k-database); } .k-logs { background: var(--k-logs); }
.k-data { background: var(--k-data); } .k-files { background: var(--k-files); } .k-cache { background: var(--k-cache); }
.files { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.files td { padding: 5px 0; border-bottom: 1px solid var(--border); }
.files tr:last-child td { border-bottom: 0; }
.files td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); padding-left: 14px; white-space: nowrap; }
.files .sw { width: 14px; }
.files .sw i { display: block; width: 10px; height: 10px; border-radius: 3px; }
.files td.name { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.logbar { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 13px; }
.logbar label { flex-direction: row; align-items: center; gap: 6px; }
pre.log { margin: 0; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; height: min(60vh, 520px); overflow: auto;
  font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
pre.log .err { color: var(--bad); } pre.log .warn { color: var(--warn); }

/* confirm + toasts */
.confirm { width: min(400px, calc(100vw - 24px)); padding: 22px; }
.confirm form { display: flex; flex-direction: column; gap: 10px; }
.confirm p { margin: 0 0 8px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.toast.error { border-left-color: var(--bad); }

@media (max-width: 640px) {
  .top { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .host-meta { order: 5; width: 100%; }
  .page { padding: 0 14px 50px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .tile { padding: 12px; }
  .tile .value { font-size: 22px; }
  .tile svg.spark { display: none; }
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 84px 1fr 64px; }
  #whoami { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
