/* ---------- Tokens ---------- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #0f172a;
  --muted: #5b6474;
  --accent: #2563eb;
  --accent-soft: #dbe6fd;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --chart-1: #2563eb;
  --chart-2: #d97706;
  --chart-3: #16a34a;
  --grid: #e8ebf0;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --surface: #121826; --surface-2: #192133; --border: #253047;
    --text: #e6eaf2; --muted: #93a0b8; --accent: #60a5fa; --accent-soft: #1e3a5f;
    --ok: #4ade80; --ok-soft: #123524; --warn: #fbbf24; --warn-soft: #3b2e0e;
    --bad: #f87171; --bad-soft: #3f1515; --chart-1: #60a5fa; --chart-2: #fbbf24; --chart-3: #4ade80;
    --grid: #1f2940; --code-bg: #070a10; --code-text: #d7deea; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --surface: #121826; --surface-2: #192133; --border: #253047;
  --text: #e6eaf2; --muted: #93a0b8; --accent: #60a5fa; --accent-soft: #1e3a5f;
  --ok: #4ade80; --ok-soft: #123524; --warn: #fbbf24; --warn-soft: #3b2e0e;
  --bad: #f87171; --bad-soft: #3f1515; --chart-1: #60a5fa; --chart-2: #fbbf24; --chart-3: #4ade80;
  --grid: #1f2940; --code-bg: #070a10; --code-text: #d7deea; --shadow: none;
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
small, .muted { color: var(--muted); }
button, select, input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.active, .seg button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: url(../favicon.svg) center/cover; }
.brand-name { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: var(--text); padding: 7px 10px; border-radius: 8px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a.sub { padding-left: 18px; }
.nav-group { margin: 14px 10px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sidebar-foot { margin-top: auto; padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.content { padding: 24px 28px 48px; min-width: 0; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head p { margin: 0; color: var(--muted); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-group { display: none; }
  .nav a.sub { padding-left: 10px; }
  .sidebar-foot { margin-top: 8px; padding: 0; }
  .content { padding: 16px; }
}

/* ---------- Building blocks ---------- */
.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(340px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

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

.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.meter > span { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.plain::before { display: none; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.selected td { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

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; min-width: 0; overflow-wrap: anywhere; }

.seg { display: inline-flex; gap: 4px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input[type="search"] { min-width: 200px; }
.error { padding: 12px 14px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); }
.empty { color: var(--muted); padding: 12px 0; }
.loading { color: var(--muted); }

/* ---------- Charts ---------- */
.chart { position: relative; height: 180px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; transform: translate(-50%, -110%);
}
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---------- Logs ---------- */
.logs-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .logs-layout { grid-template-columns: 1fr; } }
.source-list { display: flex; flex-direction: column; gap: 2px; }
.source-list .group { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); margin: 10px 8px 4px; letter-spacing: .06em; }
.source-list button { text-align: left; border: 0; background: transparent; border-radius: 8px; padding: 7px 10px; }
.source-list button:hover { background: var(--surface-2); }
.source-list button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.logbox {
  background: var(--code-bg); color: var(--code-text); border-radius: 8px; padding: 12px;
  height: min(65vh, 640px); overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 12px 0 0;
}
.logbox .l-err { color: #fca5a5; }
.logbox .l-warn { color: #fcd34d; }
.logbox .ts { color: #7c8aa5; }

/* ---------- Docs / Markdown ---------- */
.docs-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .docs-layout { grid-template-columns: 1fr; } }
.doc-list a { display: block; padding: 6px 10px; border-radius: 8px; color: var(--text); }
.doc-list a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.doc-list .folder { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); margin: 10px 10px 2px; letter-spacing: .06em; }
.markdown { line-height: 1.65; max-width: 900px; }
.markdown h1 { font-size: 1.4rem; margin-bottom: 12px; }
.markdown h2 { margin-top: 24px; font-size: 1.1rem; }
.markdown h3 { margin-top: 18px; }
.markdown table { margin: 12px 0; font-size: 13.5px; }
.markdown th, .markdown td { border: 1px solid var(--border); }
.markdown code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.markdown pre:not(.mermaid) { background: var(--code-bg); color: var(--code-text); padding: 12px; border-radius: 8px; overflow-x: auto; }
.markdown pre:not(.mermaid) code { background: none; padding: 0; color: inherit; }
.markdown blockquote { margin: 12px 0; padding: 4px 14px; border-left: 3px solid var(--accent); color: var(--muted); }

/* ---------- Diagrams ---------- */
.diagram { overflow-x: auto; padding: 8px 0; }
pre.mermaid { background: transparent; text-align: center; margin: 0; }
pre.mermaid svg { max-width: 100%; height: auto; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- Websites ---------- */
.site-card { display: flex; flex-direction: column; }
.site-card h2 a { color: var(--text); }
.site-source { margin: 0 0 8px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.site-summary { margin: 0 0 12px; }
.site-hosts { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.site-hosts li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.site-foot { margin: auto 0 0; font-size: 12.5px; }
.crumb { margin: 0 0 2px; font-size: 13px; }
.nav-sites { display: contents; }
.page-head h1 .badge { vertical-align: middle; margin-left: 6px; }
.tabs { flex-wrap: wrap; }

/* ---------- Login page ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { padding: 0 0 16px; }
.login-card form { display: grid; gap: 12px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input { width: 100%; padding: 9px 11px; }
.login-card button[type=submit] { background: var(--accent); border-color: var(--accent); color: #fff; padding: 9px; font-weight: 600; }
.login-card .error:empty { display: none; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 10px; margin-top: 12px; }
.form-grid label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form-grid input, .form-grid select { width: 100%; }
td.actions { white-space: nowrap; }

/* ---------- one.com actions ---------- */
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button.danger { border-color: var(--bad); color: var(--bad); }
button.danger:hover { background: var(--bad-soft); }
