:root {
  --bg: #0d1117; --bg2: #131a24; --panel: #161f2c; --panel2: #1c2738; --line: #263449; --line2: #33445e;
  --text: #e6edf6; --muted: #8b9bb3; --dim: #5d6d86;
  --accent: #ff3d2e; --accent2: #ff7a1a; --ok: #22c55e; --warn: #f59e0b; --err: #ef4444; --info: #38bdf8;
  --purple: #a855f7; --gold: #fbbf24; --silver: #cbd5e1; --bronze: #d97706;
  --radius: 10px; --shadow: 0 6px 24px rgba(0,0,0,.35);
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .6em; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: .92em; }
small, .muted { color: var(--muted); }
.dim { color: var(--dim); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* layout */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg2); border-right: 1px solid var(--line); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 16px; font-weight: 800; font-size: 1.1rem; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; font-size: 16px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; color: var(--muted); margin: 1px 0; cursor: pointer; }
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--panel2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav .sep { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); padding: 14px 12px 4px; }
.main { padding: 22px 26px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.45rem; margin: 0; flex: 1; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .spanall { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.grow { flex: 1; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card.tight { padding: 10px 12px; }
.card-h { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-h h3 { margin: 0; flex: 1; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.stat .s { color: var(--dim); font-size: .8rem; }

/* gauge */
.gauge { position: relative; width: 100%; max-width: 230px; margin: 0 auto 14px; aspect-ratio: 2 / 1.15; }
.gauge svg { width: 100%; height: 100%; }
.gauge .gv { position: absolute; left: 0; right: 0; bottom: 6%; text-align: center; font-weight: 750; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.gauge .gl { position: absolute; left: 0; right: 0; bottom: -10%; text-align: center; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }

/* buttons & forms */
button, .btn { font: inherit; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; font-weight: 600; }
.btn-ok { background: #15803d; border-color: #16a34a; color: #fff; }
.btn-danger { background: #7f1d1d; border-color: #b91c1c; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--panel2); }
.btn-sm { padding: 4px 9px; font-size: .85rem; border-radius: 6px; }
input, select, textarea { font: inherit; background: var(--bg2); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(255,61,46,.35); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 13px; min-height: 380px; line-height: 1.5; tab-size: 2; white-space: pre; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; }
label.f > span { color: var(--muted); font-weight: 550; }
label.f .help { color: var(--dim); font-size: .78rem; }
label.chk { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 18px; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line2); border-radius: 22px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 9px 14px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tier-badge { font-size: .7rem; padding: 1px 7px; border-radius: 99px; background: var(--panel2); color: var(--muted); }

/* tables */
.tbl-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(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; position: sticky; top: 0; background: var(--panel); }
tr:hover td { background: rgba(255,255,255,.02); }
td.num, th.num { text-align: right; }
.pos { width: 34px; height: 24px; display: inline-grid; place-items: center; border-radius: 6px; background: var(--panel2); font-weight: 700; }
.pos.p1 { background: var(--gold); color: #1a1300; } .pos.p2 { background: var(--silver); color: #111; } .pos.p3 { background: var(--bronze); color: #1a0d00; }
.purple { color: var(--purple); font-weight: 650; }

/* badges & pills */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--panel2); color: var(--muted); border: 1px solid var(--line2); }
.badge.ok { color: #86efac; border-color: #166534; background: rgba(34,197,94,.1); }
.badge.err { color: #fca5a5; border-color: #7f1d1d; background: rgba(239,68,68,.1); }
.badge.warn { color: #fcd34d; border-color: #78350f; background: rgba(245,158,11,.1); }
.badge.info { color: #7dd3fc; border-color: #075985; background: rgba(56,189,248,.1); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); } .dot.err { background: var(--err); } .dot.warn { background: var(--warn); }

/* feed */
.feed { max-height: 420px; overflow-y: auto; }
.feed .it { display: flex; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.feed .it .t { color: var(--dim); font-size: .78rem; min-width: 52px; font-variant-numeric: tabular-nums; }
.feed .it .m { flex: 1; white-space: pre-line; }
.feed .it .k { font-size: .7rem; color: var(--dim); }

/* console */
.console { background: #070a0f; border: 1px solid var(--line); border-radius: 8px; font-family: var(--mono); font-size: 12.5px; height: 520px; overflow-y: auto; padding: 10px 12px; line-height: 1.5; }
.console .l { white-space: pre-wrap; word-break: break-word; }
.console .l.warning { color: #fcd34d; } .console .l.error { color: #fca5a5; } .console .l.debug { color: var(--dim); } .console .l.panel { color: #7dd3fc; }

/* map */
.map-wrap { position: relative; background: #0a0e14; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.map-wrap canvas { width: 100%; display: block; }
.map-empty { padding: 60px 20px; text-align: center; color: var(--muted); }

/* toasts & modal */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel2); border: 1px solid var(--line2); border-left: 4px solid var(--info); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); animation: slide .2s ease-out; white-space: pre-line; }
.toast.ok { border-left-color: var(--ok); } .toast.err { border-left-color: var(--err); } .toast.warn { border-left-color: var(--warn); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 900; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 12px; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: var(--shadow); }
.modal .mh { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .mh h3 { margin: 0; flex: 1; }
.modal .mb { padding: 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* misc */
.empty { padding: 30px; text-align: center; color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 10px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line2); font-size: .82rem; cursor: pointer; user-select: none; }
.chip.on { background: rgba(255,61,46,.18); border-color: var(--accent); color: #ffd1cc; }
.bar { height: 8px; border-radius: 8px; background: var(--panel2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .4s; }
.heat { display: grid; grid-template-columns: 34px repeat(24, 1fr); gap: 2px; font-size: .68rem; color: var(--dim); }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--panel2); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.kv > :nth-child(odd) { color: var(--muted); }
pre.json { background: #070a0f; padding: 10px; border-radius: 8px; overflow: auto; max-height: 300px; font-size: 12px; font-family: var(--mono); }
.hide { display: none !important; }
.flag { font-size: 1.05em; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: flex; flex-wrap: nowrap; overflow-x: auto; padding: 8px; }
  .sidebar .brand, .nav .sep { display: none; }
  .nav { display: flex; gap: 4px; }
  .nav a { white-space: nowrap; }
  .main { padding: 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
}
