:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #16191d;
  --muted: #646d78;
  --accent: #5b5bd6;
  --accent-text: #ffffff;
  --live: #e5484d;
  --ok: #2b9a66;
  --warn: #c98a00;
  --err: #d13438;
  --shadow: 0 1px 2px rgb(0 0 0 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d22;
    --surface-2: #22262c;
    --border: #2e333a;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --accent: #8b8bf0;
    --accent-text: #0e0e1a;
    --live: #ff6369;
    --ok: #3dd68c;
    --warn: #f1b13b;
    --err: #ff6b6f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; }
.muted { color: var(--muted); font-weight: 400; }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }

.btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 6px 12px; border-radius: 6px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
.btn.danger { color: var(--err); }

input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; width: 100%;
}
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }
.error { color: var(--err); min-height: 1em; margin: 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
}

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); padding: 24px; display: grid; gap: 14px; }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.summary { color: var(--muted); flex: 1; min-width: 0; }
.top-actions { display: flex; gap: 4px; }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.live { background: var(--live); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 25%, transparent); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }

.banner { margin: 16px 16px 0; padding: 10px 14px; border-radius: 8px; background: color-mix(in srgb, var(--err) 14%, var(--surface)); color: var(--text); }

.section { padding: 20px 16px 4px; max-width: 1200px; margin: 0 auto; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { width: 220px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.list { display: grid; gap: 10px; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; }

.src { padding: 14px; display: grid; gap: 10px; }
.src.program { border-color: var(--accent); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.title { font-weight: 600; font-size: 15px; }
.stats { display: flex; gap: 14px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.stats b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.badge { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.badge.live { background: color-mix(in srgb, var(--live) 18%, transparent); color: var(--live); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.err { background: color-mix(in srgb, var(--err) 18%, transparent); color: var(--err); }
.badge.accent { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

.setup { background: var(--surface-2); border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
.kv { display: grid; grid-template-columns: 92px 1fr auto; gap: 8px; align-items: center; }
.kv .k { color: var(--muted); font-size: 12.5px; }
.kv .v { overflow-wrap: anywhere; }

.dest { padding: 12px 14px; display: grid; gap: 8px; }
.dest-main { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.plat { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; }
.plat.twitch { background: #9146ff; }
.plat.youtube { background: #ff0033; }
.plat.kick { background: #2f9e2f; }
.plat.facebook { background: #1877f2; }
.plat.custom { background: #6b7280; }
.dest-info { min-width: 0; }
.dest-info .sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest-side { display: flex; align-items: center; gap: 10px; }
.dest-err { color: var(--err); font-size: 12.5px; overflow-wrap: anywhere; }
.log { margin: 0; background: var(--surface-2); border-radius: 8px; padding: 10px; max-height: 240px; overflow: auto; white-space: pre-wrap; }

.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 0; width: min(460px, calc(100% - 32px)); }
dialog.wide { width: min(900px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog-body { padding: 20px; display: grid; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
video { width: 100%; background: #000; border-radius: 8px; aspect-ratio: 16 / 9; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 20; }

@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
  .inline-form { width: 100%; }
  .inline-form input { width: auto; flex: 1; min-width: 0; }
  .dest-main { grid-template-columns: auto 1fr; }
  .dest-side { grid-column: 1 / -1; justify-content: space-between; }
  .kv { grid-template-columns: 70px 1fr auto; }
}
