:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #0f172a; --muted: #64748b; --border: #e2e8f0;
  --accent: #2563eb; --pos: #059669; --neg: #dc2626; --warn: #d97706; --chip: #eef2f7;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 8px rgba(15, 23, 42, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --surface: #121a2e; --text: #e5e9f2; --muted: #8b97b0; --border: #222c45;
    --accent: #60a5fa; --pos: #34d399; --neg: #f87171; --warn: #fbbf24; --chip: #1a2440;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--neg); min-height: 1.2em; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 14px; margin: 0 0 12px; font-weight: 600; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge, .pill { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--chip);
  text-transform: uppercase; letter-spacing: .03em; }
.pill.ok { color: var(--pos); } .pill.bad { background: var(--neg); color: #fff; } .pill.warn { color: var(--warn); }

.tabs { display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; border-bottom: 1px solid var(--border);
  background: var(--surface); }
.tabs button { border: 0; background: none; color: var(--muted); padding: 10px 12px; font: inherit; cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
main > section { display: grid; gap: 16px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
  box-shadow: var(--shadow); min-width: 0; overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.wrap { white-space: normal; min-width: 220px; max-width: 520px; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); padding: 8px 0; }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px;
  padding: 8px 14px; font: inherit; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--text); width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; } .row input { flex: 1 1 240px; }
.danger-zone { border-color: var(--neg); }

.switch { position: relative; width: 40px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff;
  border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--pos); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:disabled + span { opacity: .4; cursor: not-allowed; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--chip); margin-right: 4px; }

.chart svg { width: 100%; height: 240px; display: block; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: var(--accent); opacity: .08; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 12px; }
.login-card label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }

@media (max-width: 640px) {
  .kpi .value { font-size: 17px; }
  main { padding: 12px; }
}
