/* TasteVN Server — light/dark follows the OS, overridable with the theme toggle (html[data-theme]). */
:root {
  color-scheme: light;
  --plane: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f3f5;
  --surface-3: #e9ebee;
  --text: #191919;
  --text-2: #5f6368;
  --text-3: #8a8f96;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --accent: #257de0;
  --accent-ink: #1b64be;
  --accent-wash: rgba(37, 125, 224, 0.10);
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --good: #0aac23;
  --good-ink: #006c10;
  --warning: #fbb315;
  --warning-ink: #8a5a00;
  --serious: #f18a59;
  --critical: #dc3c3d;
  --critical-ink: #b42324;
  --meter-track: #e3edf9;
  --code-bg: #fbfbfc;
  --tok-comment: #6a737d;
  --tok-site: #1b64be;
  --tok-directive: #8a3fbf;
  --tok-placeholder: #b45309;
  --tok-string: #0a7d33;
  --diff-add: rgba(10, 172, 35, 0.12);
  --diff-del: rgba(220, 60, 61, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --shadow-pop: 0 8px 32px rgba(0, 0, 0, 0.18);
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0b0b0b;
    --surface: #191919;
    --surface-2: #212121;
    --surface-3: #2a2a2a;
    --text: #efefef;
    --text-2: #a3a3a3;
    --text-3: #7a7a7a;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --grid: #303030;
    --axis: #474747;
    --accent: #338ced;
    --accent-ink: #6aabf1;
    --accent-wash: rgba(51, 140, 237, 0.14);
    --series-1: #338ced;
    --series-2: #e76624;
    --series-3: #00a888;
    --good-ink: #53c556;
    --warning-ink: #fbb315;
    --critical-ink: #ff7a7b;
    --meter-track: #1d3250;
    --code-bg: #141414;
    --tok-comment: #7d8590;
    --tok-site: #6aabf1;
    --tok-directive: #c59af0;
    --tok-placeholder: #f2a64a;
    --tok-string: #6fd08c;
    --diff-add: rgba(10, 172, 35, 0.18);
    --diff-del: rgba(220, 60, 61, 0.20);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-pop: 0 8px 32px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0b0b0b;
  --surface: #191919;
  --surface-2: #212121;
  --surface-3: #2a2a2a;
  --text: #efefef;
  --text-2: #a3a3a3;
  --text-3: #7a7a7a;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --grid: #303030;
  --axis: #474747;
  --accent: #338ced;
  --accent-ink: #6aabf1;
  --accent-wash: rgba(51, 140, 237, 0.14);
  --series-1: #338ced;
  --series-2: #e76624;
  --series-3: #00a888;
  --good-ink: #53c556;
  --warning-ink: #fbb315;
  --critical-ink: #ff7a7b;
  --meter-track: #1d3250;
  --code-bg: #141414;
  --tok-comment: #7d8590;
  --tok-site: #6aabf1;
  --tok-directive: #c59af0;
  --tok-placeholder: #f2a64a;
  --tok-string: #6fd08c;
  --diff-add: rgba(10, 172, 35, 0.18);
  --diff-del: rgba(220, 60, 61, 0.20);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-pop: 0 8px 32px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 var(--font);
  background: var(--plane);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.ico { display: inline-flex; flex: none; }
.ico svg { width: 16px; height: 16px; }
.tile-label .ico svg { width: 14px; height: 14px; }
.faint { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------------- layout ---------------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #6a4ce2);
  display: grid; place-items: center; color: #fff;
}
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand-host { font-size: 12px; color: var(--text-2); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 4px; }
.nav-group:first-child { padding-top: 0; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-wash); color: var(--accent-ink); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 8px; font-size: 12px; color: var(--text-3); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 28px;
  background: color-mix(in srgb, var(--plane) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1600px; width: 100%; }
.menu-btn { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-pop); }
  .app.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-flex; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}

/* ---------------- cards & grids ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; }
.card-head h2, .card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-head .sub { color: var(--text-2); font-size: 12.5px; }
.card-body { padding: 14px 16px 16px; }
.card-body.flush { padding: 8px 0 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
@media (max-width: 1100px) { .g2, .g3 { grid-template-columns: 1fr; } }

/* stat tile */
.tile { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile-label { color: var(--text-2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.tile-value { font-size: 26px; font-weight: 620; letter-spacing: -0.02em; line-height: 1.2; }
.tile-value small { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.tile-sub { color: var(--text-2); font-size: 12.5px; }
.tile .meter { margin-top: 6px; }

/* meter */
.meter { height: 8px; border-radius: 99px; background: var(--meter-track); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s; }
.meter.warn > span { background: var(--warning); }
.meter.crit > span { background: var(--critical); }
.meter.thin { height: 4px; }

/* status */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 550; white-space: nowrap; }
.status .dot { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; }
.status .dot svg { width: 10px; height: 10px; }
.status.good .dot { background: var(--good); }
.status.good { color: var(--good-ink); }
.status.warning .dot { background: var(--warning); color: #0b0b0b; }
.status.warning { color: var(--warning-ink); }
.status.critical .dot { background: var(--critical); }
.status.critical { color: var(--critical-ink); }
.status.neutral .dot { background: var(--text-3); }
.status.neutral { color: var(--text-2); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 550;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.accent { background: var(--accent-wash); color: var(--accent-ink); border-color: transparent; }
.badge.crit { background: var(--critical); color: #fff; border-color: transparent; }
.chip { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); font-size: 12px; font-family: var(--mono); color: var(--text-2); }

/* alerts */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
}
.alert.critical { border-left: 3px solid var(--critical); }
.alert.warning { border-left: 3px solid var(--warning); }
.alert.good { border-left: 3px solid var(--good); }

/* ---------------- controls ---------------- */
button, .btn {
  font: inherit; font-size: 13px; font-weight: 550;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
button svg { width: 15px; height: 15px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.06); background: var(--accent); }
button.danger { color: var(--critical-ink); }
button.danger.solid { background: var(--critical); border-color: var(--critical); color: #fff; }
button.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.icon { width: 32px; padding: 0; }
button.sm { height: 26px; padding: 0 8px; font-size: 12px; }
button.sm.icon { width: 26px; }
input, select, textarea {
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 0 10px; height: 32px; min-width: 0;
}
textarea { padding: 8px 10px; height: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }

.seg { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { height: 26px; border: 0; background: transparent; color: var(--text-2); padding: 0 10px; border-radius: 7px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; border-radius: 0; background: none; height: 38px; color: var(--text-2); border-bottom: 2px solid transparent; padding: 0 12px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:hover { background: none; color: var(--text); }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 550; color: var(--text-2); font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
table.t td.r, table.t th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t .clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.t .name { font-weight: 560; }
table.t .actions { display: flex; gap: 4px; justify-content: flex-end; }
tr.detail td { background: var(--surface-2); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 12.5px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-all; }

/* ---------------- charts ---------------- */
.chart { position: relative; }
.chart canvas { display: block; width: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); padding: 0 0 6px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 14px; height: 3px; border-radius: 2px; }
.legend .swatch.box { width: 10px; height: 10px; border-radius: 2px; }
.legend b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: var(--shadow-pop); padding: 8px 10px; font-size: 12px; min-width: 120px;
  transform: translate(-50%, 0);
}
.tooltip .tt-time { color: var(--text-2); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row b { font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip .tt-row span { color: var(--text-2); }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; }
.chart.loading canvas { opacity: .5; }

.core-bars { display: flex; gap: 4px; align-items: flex-end; height: 28px; margin-top: 6px; }
.core-bars span { flex: 1; background: var(--meter-track); border-radius: 3px; position: relative; height: 100%; overflow: hidden; }
.core-bars span i { position: absolute; bottom: 0; left: 0; right: 0; background: var(--accent); border-radius: 3px 3px 0 0; transition: height .4s; }

/* ---------------- service rows ---------------- */
.svc-list { display: flex; flex-direction: column; }
.svc-item { display: flex; align-items: center; gap: 12px; padding: 9px 16px; border-top: 1px solid var(--border); }
.svc-item:first-child { border-top: 0; }
.svc-item .grow { flex: 1; min-width: 0; }
.svc-item .title { font-weight: 560; }
.svc-item .meta { color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind-ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.kind-ico svg { width: 16px; height: 16px; }

/* ---------------- editor ---------------- */
.editor { position: relative; display: grid; grid-template-columns: auto 1fr; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--code-bg); overflow: hidden; height: 62vh; min-height: 360px; }
.editor .gutter { font: 13px/20px var(--mono); color: var(--text-3); text-align: right; padding: 10px 10px 10px 12px; user-select: none; overflow: hidden; background: var(--surface-2); border-right: 1px solid var(--border); white-space: pre; }
.editor .gutter .hl { color: var(--accent-ink); font-weight: 700; }
.editor .area { position: relative; overflow: hidden; }
.editor pre, .editor textarea {
  margin: 0; position: absolute; inset: 0; padding: 10px 12px;
  font: 13px/20px var(--mono); tab-size: 4; white-space: pre; overflow: auto;
  border: 0; border-radius: 0; background: transparent;
}
.editor pre { pointer-events: none; color: var(--text); overflow: hidden; }
.editor textarea { color: transparent; caret-color: var(--text); resize: none; outline: none; height: 100%; }
.editor textarea::selection { background: rgba(51, 140, 237, 0.30); color: transparent; }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-site { color: var(--tok-site); font-weight: 650; }
.tok-directive { color: var(--tok-directive); }
.tok-placeholder { color: var(--tok-placeholder); }
.tok-string { color: var(--tok-string); }
.tok-matcher { color: var(--tok-placeholder); font-weight: 600; }

.output { font: 12.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; max-height: 340px; overflow: auto; margin: 0; }
.output.ok { border-left: 3px solid var(--good); }
.output.err { border-left: 3px solid var(--critical); }
.diff .add { background: var(--diff-add); display: block; }
.diff .del { background: var(--diff-del); display: block; }
.diff .hunk { color: var(--accent-ink); display: block; }
.diff .meta { color: var(--text-3); display: block; }

/* ---------------- logs ---------------- */
.logview { font: 12.5px/1.6 var(--mono); background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); height: calc(100vh - 230px); min-height: 320px; overflow: auto; padding: 8px 0; }
.logview div { padding: 0 12px; white-space: pre-wrap; word-break: break-word; }
.logview div:hover { background: var(--surface-2); }
.logview .ts { color: var(--text-3); }
.logview .lv-err { color: var(--critical-ink); }
.logview .lv-warn { color: var(--warning-ink); }
.logview mark { background: rgba(251, 179, 21, 0.35); color: inherit; border-radius: 2px; }

/* ---------------- modal & toast ---------------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 100; display: grid; place-items: center; padding: 16px; animation: fade .12s; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-pop); width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { width: min(980px, 100%); }
.modal-head { padding: 16px 20px 0; display: flex; align-items: center; gap: 8px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 14px 20px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 20px 16px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-pop); padding: 10px 14px; max-width: 420px; display: flex; gap: 10px; align-items: flex-start; animation: fade .15s; white-space: pre-wrap; }

/* ---------------- login ---------------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login h1 { margin: 0; font-size: 20px; }
.login input { height: 40px; }
.login button { height: 40px; }
.error-text { color: var(--critical-ink); font-size: 13px; }

.empty { padding: 28px; text-align: center; color: var(--text-2); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.live-dot.off { background: var(--text-3); box-shadow: none; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hbar { display: grid; grid-template-columns: minmax(120px, 260px) 1fr 90px; gap: 10px; align-items: center; font-size: 13px; padding: 5px 0; }
.hbar .meter { height: 10px; }

/* ---------------- journal ---------------- */
.journal { max-height: calc(100vh - 250px); min-height: 320px; overflow: auto; }
.jday { position: sticky; top: 0; z-index: 1; background: var(--surface); padding: 10px 16px 6px; font-weight: 650; font-size: 13px; border-bottom: 1px solid var(--border); text-transform: capitalize; }
.jrow { display: grid; grid-template-columns: 74px 22px 1fr auto; gap: 8px; align-items: baseline; padding: 4px 16px; font-size: 13px; cursor: pointer; border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
.jrow:hover, .jrow:focus { background: var(--surface-2); outline: none; }
.jrow .jtime { color: var(--text-3); font-size: 12px; }
.jrow .jmsg { white-space: pre-wrap; word-break: break-word; }
.jrow .jid { color: var(--text-2); font-size: 12px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.jrow.critical .jmsg { color: var(--critical-ink); }
.jrow.warning .jmsg { color: var(--warning-ink); }
.jrow .status .dot { width: 14px; height: 14px; }
