:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #6a717c;
  --line: #e3e5e9;
  --accent: #2457d6;
  --accent-ink: #ffffff;
  --danger: #c62f2f;
  --ok: #18794e;
  --warn: #a35c00;
  --chip: #eef1f6;
  --side: #14181f;
  --side-text: #c9ced6;
  --side-active: #2a3140;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --text: #e6e8eb;
    --muted: #949ba6;
    --line: #2a3038;
    --accent: #5b8cff;
    --accent-ink: #0b0d10;
    --danger: #ff6b6b;
    --ok: #4cc38a;
    --warn: #f0a640;
    --chip: #222831;
    --side: #0b0e12;
    --side-text: #b4bac4;
    --side-active: #1f2530;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.boot { padding: 40px; color: var(--muted); }
.hidden { display: none !important; }

/* ---------- auth screens ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p { color: var(--muted); margin: 0 0 20px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; color: #fff; font-size: 16px; padding: 4px 10px 16px; letter-spacing: .2px; }
.brand small { display: block; font-weight: 400; color: var(--side-text); font-size: 12px; }
.nav a { display: block; color: var(--side-text); text-decoration: none; padding: 8px 10px; border-radius: 6px; }
.nav a:hover { background: var(--side-active); color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; font-weight: 600; }
.side .spacer { flex: 1; }
.side .who { font-size: 12px; padding: 8px 10px; border-top: 1px solid #262c36; margin-top: 8px; }
.side .who b { color: #fff; }
.side .who button { margin-top: 8px; width: 100%; }
.main { padding: 24px 28px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 20px; flex: 1; }
.menu-btn { display: none; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .main { padding: 16px; }
  .menu-btn { display: inline-flex; }
}

/* ---------- components ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px 18px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 14px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; min-width: 150px; }
td.actions button { margin: 2px 0 2px 4px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 6px; padding: 7px 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); display: inline-flex; align-items: center; gap: 6px;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
button.sm { padding: 4px 9px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
label.field > small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: auto; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--chip); }
.badge.live { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge.scheduled { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.badge.ended, .badge.off { color: var(--muted); }
.badge.disabled { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.on { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--chip); border-radius: 4px; padding: 2px 6px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; display: inline-flex; gap: 4px; align-items: center; }
.chip button { border: 0; background: none; padding: 0 2px; color: var(--danger); font-size: 14px; line-height: 1; }

.secret-box { background: var(--bg); border: 1px dashed var(--line); padding: 10px; border-radius: 6px; word-break: break-all; }
pre.code { background: var(--side); color: #dde3ec; padding: 14px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; line-height: 1.5; margin: 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.note { background: color-mix(in srgb, var(--warn) 10%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bars .fill { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .lbl { font-size: 11px; color: var(--muted); }
.bars .v { font-size: 11px; font-variant-numeric: tabular-nums; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--text);
  width: min(560px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog .d-head { padding: 16px 18px 0; font-size: 17px; font-weight: 700; }
dialog .d-body { padding: 14px 18px; max-height: 70vh; overflow-y: auto; }
dialog .d-foot { padding: 12px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--side); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); max-width: 360px; }
.toast.error { background: var(--danger); }
