:root {
  --bg: #0f1117; --panel: #171a23; --panel2: #1e222e; --border: #2a2f3c;
  --text: #e6e9ef; --muted: #949bb0; --accent: #5b8cff; --accent2: #7c5cff;
  --green: #35c68a; --red: #ff5c72; --amber: #ffb454; --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: light) {
  :root { --bg:#f4f6fb; --panel:#fff; --panel2:#f6f8fc; --border:#e3e8f0; --text:#1b2030; --muted:#69708a; --shadow:0 6px 20px rgba(20,30,60,.08); }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 34px; width: 360px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; }
.brand { font-weight: 700; font-size: 17px; padding: 6px 10px 18px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 3px; background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; color: var(--muted); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--panel2); color: var(--text); }
.nav a.active { background: linear-gradient(135deg, rgba(91,140,255,.16), rgba(124,92,255,.16)); color: var(--text); }
.sidebar .spacer { flex: 1; }
.main { padding: 26px 30px; overflow: auto; max-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.topbar h2 { margin: 0; font-size: 20px; }

/* ---------- primitives ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .cols-4 { grid-template-columns: repeat(2,1fr); } .cols-2 { grid-template-columns: 1fr; } .layout { grid-template-columns: 1fr; } }
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 28px; font-weight: 700; }
.stat .sub { color: var(--muted); font-size: 12px; }

label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea { width: 100%; padding: 10px 12px; background: var(--panel2); border: 1px solid var(--border); border-radius: 9px; color: var(--text); }
textarea { min-height: 84px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.btn { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: none; padding: 10px 16px; border-radius: 9px; font-weight: 600; }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--red); }
.btn.ok { background: var(--green); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: var(--panel2); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.pill.green { background: rgba(53,198,138,.16); color: var(--green); }
.pill.red { background: rgba(255,92,114,.16); color: var(--red); }
.pill.amber { background: rgba(255,180,84,.16); color: var(--amber); }
.pill.gray { background: var(--panel2); color: var(--muted); }
code, .mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.keychip { background: var(--panel2); border: 1px solid var(--border); border-radius: 7px; padding: 3px 8px; font-family: ui-monospace, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: 520px; max-width: 100%; max-height: 88vh; overflow: auto; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 14px; }
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--green); padding: 12px 16px; border-radius: 9px; box-shadow: var(--shadow); z-index: 60; }
.toast.err { border-left-color: var(--red); }

/* charts */
.bar-track { background: var(--panel2); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
svg .grid-line { stroke: var(--border); stroke-width: 1; }
svg .hits { fill: var(--accent); }
svg .errs { fill: var(--red); }
