:root {
  --bg: #0B0F1A;
  --bg-soft: #111827;
  --bg-elev: #161E2E;
  --bg-card: #1B2433;
  --line: #243042;
  --line-soft: #1C2535;
  --text: #E2E8F0;
  --text-soft: #94A3B8;
  --text-dim: #64748B;
  --accent: #60A5FA;
  --accent-strong: #3B82F6;
  --good: #34D399;
  --warn: #FBBF24;
  --bad: #F87171;
  --violet: #A78BFA;
  --pink: #F472B6;
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; }

.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────────────────────── */
.side {
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  padding: 18px 14px 24px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 16px; margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #4F8EFF 0%, #2563EB 60%, #1E3A8A 100%);
  display: grid; place-items: center;
  color: white; font-weight: 800; font-size: 14px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 6px 18px -8px rgba(59,130,246,.7);
}
.brand-text { font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.brand-sub { font-size: 11px; color: var(--text-dim); }

.nav { display: flex; flex-direction: column; gap: 2px; padding-top: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text-soft); cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
}
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active {
  background: linear-gradient(180deg, rgba(96,165,250,.14) 0%, rgba(96,165,250,.06) 100%);
  color: var(--text);
  border-color: rgba(96,165,250,.22);
}
.nav-item .icon { width: 16px; height: 16px; opacity: .85; }
.nav-section {
  padding: 14px 10px 6px; font-size: 10px;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-dim);
}

.side-foot {
  margin-top: auto; padding: 12px 8px 0;
  border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px;
  font-size: 11px; color: var(--text-dim);
}
.side-foot .who { color: var(--text); font-size: 12px; word-break: break-all; }

/* ── Main ───────────────────────────────────────────────────── */
.main { padding: 22px 28px 80px; max-width: 100%; }

.head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.head h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.head .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.toolbar { display: flex; gap: 8px; align-items: center; }
.btn {
  background: var(--bg-card); border: 1px solid var(--line);
  color: var(--text); padding: 6px 12px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 6px; font-weight: 500;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--bg-elev); border-color: #2F3D54; }
.btn.primary {
  background: linear-gradient(180deg, #3B82F6 0%, #2563EB 100%);
  border-color: #1D4ED8; color: white;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger {
  background: linear-gradient(180deg, #EF4444 0%, #B91C1C 100%);
  border-color: #B91C1C; color: white;
}
.btn.ghost { background: transparent; }
.btn .icon { width: 14px; height: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ── Card grid ──────────────────────────────────────────────── */
.cards { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cards-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cards-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px;
  position: relative;
  display: flex; flex-direction: column; gap: 6px;
}
.card.dense { padding: 12px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; color: var(--text-dim); letter-spacing: .04em; text-transform: uppercase;
}
.card-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.card-foot { font-size: 11px; color: var(--text-dim); }
.card-foot .pos { color: var(--good); }
.card-foot .neg { color: var(--bad); }
.card .spark { height: 36px; margin-top: 8px; }

/* ── Section ────────────────────────────────────────────────── */
.section { margin-top: 24px; }
.section h2 { font-size: 14px; margin: 0 0 12px; font-weight: 600; color: var(--text); }
.section .sub { color: var(--text-dim); font-size: 12px; }

.panel {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px;
}

/* ── Table ──────────────────────────────────────────────────── */
.tbl {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
.tbl th, .tbl td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.tbl thead th {
  position: sticky; top: 0;
  background: var(--bg-elev);
  color: var(--text-dim); font-weight: 500;
  text-transform: uppercase; font-size: 10px; letter-spacing: .06em;
  border-bottom: 1px solid var(--line);
}
.tbl tbody tr:hover { background: rgba(96,165,250,.04); }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px;
  overflow: auto; max-height: 70vh;
}
.tbl-row-clickable { cursor: pointer; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 6px;
  font-size: 10.5px; font-weight: 500;
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--text-soft);
}
.badge.ok { color: var(--good); border-color: rgba(52,211,153,.3); background: rgba(52,211,153,.07); }
.badge.warn { color: var(--warn); border-color: rgba(251,191,36,.3); background: rgba(251,191,36,.07); }
.badge.bad { color: var(--bad); border-color: rgba(248,113,113,.3); background: rgba(248,113,113,.07); }
.badge.info { color: var(--accent); border-color: rgba(96,165,250,.3); background: rgba(96,165,250,.07); }
.badge.violet { color: var(--violet); border-color: rgba(167,139,250,.3); background: rgba(167,139,250,.07); }

.input, .textarea, .select {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 10px; border-radius: 8px;
  outline: none;
  width: 100%;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(96,165,250,.15);
}
.textarea { min-height: 160px; resize: vertical; line-height: 1.5; }

.row { display: flex; gap: 8px; align-items: center; }
.row.gap-12 { gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spread { display: flex; justify-content: space-between; align-items: center; }
.muted { color: var(--text-dim); }
.softer { color: var(--text-soft); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 12px; }
.kv .k { color: var(--text-dim); }
.kv .v { color: var(--text); word-break: break-word; }

/* ── Sparkline & charts ─────────────────────────────────────── */
.spark { width: 100%; }
.bar-row {
  display: grid; grid-template-columns: 130px 1fr 50px; gap: 8px; align-items: center;
  padding: 4px 0; font-size: 12px;
}
.bar-row .lbl { color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar {
  height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, #3B82F6 0%, #60A5FA 100%);
  min-width: 2px;
}
.bar-row .bg-bar { background: var(--bg-elev); height: 8px; border-radius: 4px; }
.bar-row .num { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }

.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 16px); gap: 3px; }
.heatmap .cell {
  width: 16px; height: 16px; border-radius: 3px;
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
}
.heatmap .cell.l1 { background: rgba(96,165,250,.18); border-color: rgba(96,165,250,.22); }
.heatmap .cell.l2 { background: rgba(96,165,250,.36); border-color: rgba(96,165,250,.38); }
.heatmap .cell.l3 { background: rgba(96,165,250,.6); border-color: rgba(96,165,250,.6); }
.heatmap .cell.l4 { background: rgba(96,165,250,.85); border-color: rgba(96,165,250,.9); }

/* ── Drawer ─────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(2,6,17,.6);
  backdrop-filter: blur(6px);
  display: flex; align-items: stretch; justify-content: flex-end;
  z-index: 100;
}
.drawer {
  width: 560px; max-width: 95vw;
  background: var(--bg);
  border-left: 1px solid var(--line);
  padding: 20px 22px; overflow-y: auto;
  box-shadow: -20px 0 60px -10px rgba(0,0,0,.6);
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer h3 { margin: 0; font-size: 17px; }
.drawer h4 { margin: 18px 0 8px; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

.empty {
  padding: 28px; text-align: center; color: var(--text-dim);
  border: 1px dashed var(--line); border-radius: 12px;
}

.spinner {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(96,165,250,.25);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
  display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 18px; right: 18px;
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; font-size: 13px; z-index: 200;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,.5);
}
.toast.ok { border-color: rgba(52,211,153,.4); }
.toast.bad { border-color: rgba(248,113,113,.5); }

.kbd {
  display: inline-block; padding: 1px 6px;
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; font-size: 10.5px; color: var(--text-dim);
  font-family: ui-monospace, Menlo, monospace;
  background: var(--bg-soft);
}

.gate {
  display: grid; place-items: center; min-height: 100vh;
  padding: 24px;
}
.gate .panel {
  width: 420px; max-width: 100%;
  text-align: center;
  padding: 28px 24px;
}
.gate h1 { font-size: 18px; margin: 8px 0; }
.gate p { color: var(--text-soft); }
