:root {
  --bg: #0b1120;
  --panel: #111a2e;
  --panel-2: #16213a;
  --line: #24324f;
  --text: #e5ebf5;
  --muted: #8a99b5;
  --accent: #38bdf8;
  --accent-ink: #04202d;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --idle: #64748b;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f9; --panel: #ffffff; --panel-2: #f6f8fc; --line: #dde3ee; --text: #0f172a; --muted: #5b6b86;
    --accent: #0284c7; --accent-ink: #ffffff; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.error { color: var(--bad); min-height: 1em; margin: 0; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap { gap: 8px; }
.grow { flex: 1; }
.right { margin-left: auto; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 10px; }
.login-card input { font-size: 16px; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.brand.big { font-size: 20px; margin-bottom: 8px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #6366f1); display: inline-block; }

/* layout */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-weight: 550; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.active { color: var(--accent-ink); background: var(--accent); }
.nav .sep { width: 1px; background: var(--line); margin: 4px 6px; }
.who { display: flex; align-items: center; gap: 8px; }
.content { padding: 16px; flex: 1; width: 100%; max-width: 1500px; margin: 0 auto; }
.footer { padding: 10px 16px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.banner { padding: 10px 16px; font-weight: 600; }
.banner.bad { background: rgba(239, 68, 68, .15); color: #fecaca; border-bottom: 1px solid rgba(239, 68, 68, .4); }
.banner.warn { background: rgba(245, 158, 11, .15); color: #fde68a; border-bottom: 1px solid rgba(245, 158, 11, .4); }
@media (prefers-color-scheme: light) { .banner.bad { color: #991b1b; } .banner.warn { color: #92400e; } }

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head p { margin: 0; }

/* cards */
.cards { display: grid; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head .title { font-weight: 650; font-size: 15px; }
.empty { padding: 30px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tile { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.tile .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }
.tile .v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile .v.bad { color: var(--bad); }
.tile .v.warn { color: var(--warn); }
.tiles.big .tile .v { font-size: 22px; }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.nodot::before { display: none; }
.pill.live, .pill.ok, .pill.running, .pill.recording, .pill.receiving, .pill.playing, .pill.connected, .pill.valid { color: var(--ok); border-color: rgba(34, 197, 94, .4); }
.pill.waiting, .pill.armed, .pill.connecting, .pill.starting, .pill.backoff, .pill.stalled, .pill.warn { color: var(--warn); border-color: rgba(245, 158, 11, .4); }
.pill.error, .pill.failed, .pill.bad, .pill.expired, .pill.invalid, .pill.nokey { color: var(--bad); border-color: rgba(239, 68, 68, .45); }
.pill.admin { color: var(--accent); border-color: var(--accent); }

/* tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--panel-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td.bad { color: var(--bad); font-weight: 650; }
td.wrap { white-space: normal; overflow-wrap: anywhere; }

/* forms */
input, select, textarea { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; }
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
label { color: var(--muted); font-size: 12px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 14px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field.check { display: flex; align-items: center; gap: 8px; padding-top: 18px; }
.field.check label { color: var(--text); font-size: 13px; }
.hint { color: var(--muted); font-size: 11.5px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; margin: 12px 0 0; }
legend { color: var(--muted); font-size: 12px; font-weight: 650; padding: 0 6px; }
.li { position: relative; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 40px 12px 12px; margin-top: 10px; }
.li .remove { position: absolute; top: 8px; right: 8px; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: rgba(239, 68, 68, .5); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* details */
details > summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-top: 8px; }
pre.log { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 180px; overflow: auto; font: 12px/1.4 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0 0; }
.url { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--line); padding: 2px 7px; border-radius: 6px; overflow-wrap: anywhere; }

/* summary flows */
.group { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 12px; }
.group.live { border-color: rgba(34, 197, 94, .45); }
.group-title { font-weight: 650; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.flow { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 12px; padding: 10px 0; border-top: 1px dashed var(--line); }
.flow:first-of-type { border-top: 0; }
.flow .src { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--idle); border-radius: 8px; padding: 10px; min-width: 0; }
.flow .src.live { border-left-color: var(--ok); }
.flow .src.error { border-left-color: var(--bad); }
.flow .src.waiting { border-left-color: var(--warn); }
.kind { font-size: 11px; font-weight: 700; letter-spacing: .6px; color: var(--muted); text-transform: uppercase; }
.outs { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.out { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; min-width: 0; max-width: 100%; }
.out .lbl { font-weight: 600; }
.out .tgt { font-family: var(--mono); font-size: 11.5px; color: var(--muted); overflow-wrap: anywhere; }
.out.link { border-style: dashed; border-color: var(--accent); }
@media (max-width: 760px) { .flow { grid-template-columns: 1fr; } }

/* overlay / modal / toast */
.overlay { position: fixed; inset: 0; background: rgba(5, 8, 16, .82); z-index: 50; display: grid; place-items: center; padding: 16px; }
.overlay-card { width: min(560px, 100%); background: var(--panel); border: 2px solid var(--bad); border-radius: 14px; padding: 26px; text-align: center; }
.overlay-title { font-size: 30px; font-weight: 800; color: var(--bad); letter-spacing: .5px; margin-bottom: 8px; }
.overlay-card .row { justify-content: center; }
.modal { position: fixed; inset: 0; background: rgba(5, 8, 16, .7); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(980px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.modal-head, .modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-foot { border-bottom: 0; border-top: 1px solid var(--line); justify-content: space-between; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 14px 16px; overflow: auto; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 60; background: var(--panel); border: 1px solid var(--accent); padding: 10px 14px; border-radius: 10px; max-width: calc(100vw - 32px); }
.toast.bad { border-color: var(--bad); }

@media (max-width: 640px) {
  .content { padding: 12px; }
  .topbar { gap: 8px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* logs */
.log.logbox { max-height: 72vh; }
.logline { white-space: pre-wrap; overflow-wrap: anywhere; }
.logline.bad { color: var(--bad); }
.logline.warn { color: var(--warn); }

/* preview */
.preview-video { width: 100%; max-height: 70vh; background: #000; border-radius: 8px; }
.preview-note { color: var(--muted); font-size: 12px; margin-top: 8px; }
