:root {
  --bg: #f4f6f9; --panel: #ffffff; --panel-2: #f8fafc; --border: #e2e8f0;
  --text: #0f172a; --muted: #64748b; --accent: #2563eb; --accent-soft: #dbeafe;
  --ok: #16a34a; --warn: #d97706; --crit: #dc2626; --info: #0891b2;
  --ok-soft: #dcfce7; --warn-soft: #fef3c7; --crit-soft: #fee2e2; --info-soft: #cffafe;
  --c1: #2563eb; --c2: #db2777; --c3: #16a34a; --c4: #d97706;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --panel: #111827; --panel-2: #0f172a; --border: #1f2a3c;
    --text: #e2e8f0; --muted: #94a3b8; --accent: #60a5fa; --accent-soft: #1e3a5f;
    --ok: #4ade80; --warn: #fbbf24; --crit: #f87171; --info: #22d3ee;
    --ok-soft: #12321f; --warn-soft: #3b2a0b; --crit-soft: #3f1515; --info-soft: #0c3440;
    --c1: #60a5fa; --c2: #f472b6; --c3: #4ade80; --c4: #fbbf24;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --panel: #111827; --panel-2: #0f172a; --border: #1f2a3c;
  --text: #e2e8f0; --muted: #94a3b8; --accent: #60a5fa; --accent-soft: #1e3a5f;
  --ok: #4ade80; --warn: #fbbf24; --crit: #f87171; --info: #22d3ee;
  --ok-soft: #12321f; --warn-soft: #3b2a0b; --crit-soft: #3f1515; --info-soft: #0c3440;
  --c1: #60a5fa; --c2: #f472b6; --c3: #4ade80; --c4: #fbbf24;
  --shadow: none; color-scheme: dark;
}

* { 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); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); }
.brand img { width: 34px; height: 34px; }
.brand div { display: flex; flex-direction: column; line-height: 1.2; }
.brand span { font-size: 12px; }
.sidebar nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; overflow-y: auto; flex: 1; }
.sidebar nav a { padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; }
.sidebar nav a:hover { background: var(--panel-2); }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.logout { padding: 12px; border-top: 1px solid var(--border); }
.logout .btn { width: 100%; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }
.content { padding: 24px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; width: 100%; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live-dot.on { background: var(--ok); }

/* Components */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.stat .sub { color: var(--muted); font-size: 12px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 8px; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.warn > span { background: var(--warn); }
.bar.crit > span { background: var(--crit); }

.btn { font: inherit; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--crit); border-color: var(--crit); }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.crit { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 8px; border-left: 4px solid; text-decoration: none; color: var(--text); }
.alert.crit { background: var(--crit-soft); border-color: var(--crit); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); }
.alert.info { background: var(--info-soft); border-color: var(--info); }
.alert.ok { background: var(--ok-soft); border-color: var(--ok); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td .btn + .btn { margin-left: 4px; }

pre.log { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0; max-height: 65vh; overflow: auto; font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-all; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
input, select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }
.error-box { color: var(--crit); background: var(--crit-soft); padding: 10px 12px; border-radius: 8px; }

/* Charts */
.chart { width: 100%; height: 200px; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .hover-line { stroke: var(--muted); stroke-dasharray: 3 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; 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; }
.chart-tip { font-size: 12px; color: var(--muted); min-height: 18px; font-variant-numeric: tabular-nums; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: min(820px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal-box header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-box h2 { font-size: 16px; margin: 0; }
#modal-body { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px; width: min(380px, 100%); box-shadow: var(--shadow); text-align: center; }
.login-logo { width: 56px; height: 56px; }
.login-card h1 { margin: 8px 0 0; font-size: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
.login-card .btn { padding: 10px; }
.form-error { color: var(--crit); background: var(--crit-soft); border-radius: 8px; padding: 8px 10px; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px; }
  .grid.wide { grid-template-columns: 1fr; }
  #updated { display: none; }
}
