:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --sunken: #f0f0ed;
  --line: #e2e2de;
  --line-strong: #cfcfca;
  --text: #1a1a1c;
  --muted: #66666c;
  --faint: #95959b;
  --accent: #ffa600;
  --accent-hover: #f09c00;
  --accent-ink: #1a1200;
  --ok: #1f9d55;
  --warn: #b7791f;
  --bad: #c53030;
  --focus: rgba(255, 166, 0, .35);
  --logo-filter: invert(1);
  --radius: 6px;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #18181b;
    --sunken: #141416;
    --line: #29292d;
    --line-strong: #3a3a3f;
    --text: #ececee;
    --muted: #a0a0a7;
    --faint: #6e6e75;
    --ok: #3fb97a;
    --warn: #d9a441;
    --bad: #f06464;
    --logo-filter: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }

/* Header */
.topbar {
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 max(16px, calc((100vw - 1080px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.brand img { height: 26px; width: auto; display: block; filter: var(--logo-filter); }
.brand-name { padding-left: 12px; border-left: 1px solid var(--line-strong); font-size: 15px; font-weight: 500; }
.topbar .spacer { flex: 1; }
.who { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }

/* Buttons and inputs */
button {
  font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--sunken); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 0 8px; }
button.ghost:hover { color: var(--text); background: var(--sunken); }
button.danger { color: var(--bad); }
button.small { height: 28px; padding: 0 10px; font-size: 13px; }

label { display: grid; gap: 5px; font-size: 13px; font-weight: 500; }
input {
  font: inherit; color: var(--text);
  height: 36px; padding: 0 10px; width: 100%;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--accent); }
input.mono { font-size: 13px; }
input[readonly] { background: var(--sunken); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.form-error { color: var(--bad); font-size: 13px; margin: 0; }
.form-error:empty { display: none; }

/* Status: a dot and a word, no badges */
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.status.live { color: var(--ok); }
.status.live::before { background: var(--ok); }
.status.connecting, .status.waiting, .status.retrying { color: var(--warn); }
.status.connecting::before, .status.waiting::before, .status.retrying::before { background: var(--warn); }
.status.failed { color: var(--bad); }
.status.failed::before { background: var(--bad); }
.status.online { color: var(--ok); }
.status.online::before { background: var(--ok); }

/* Input strip */
.ingest {
  display: flex; align-items: center; gap: 8px 24px; flex-wrap: wrap;
  padding: 12px 16px; margin-bottom: 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.ingest .title { font-weight: 500; }
.ingest .stats { display: flex; gap: 6px 20px; flex-wrap: wrap; margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ingest .stats b { color: var(--text); font-weight: 400; }
.ingest .stats .note { font-family: var(--sans); font-size: 13px; }

/* Tabs */
.tabs { display: flex; gap: 20px; margin-bottom: 24px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  height: 38px; padding: 0; border: 0; border-radius: 0; background: none; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { background: none; color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }

.section-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 14px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.section-head p { margin: 0; color: var(--muted); }
.section-head .spacer { flex: 1; }

/* Output panels */
.outputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: grid; gap: 14px; align-content: start; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.card-head .sub { font-family: var(--mono); font-size: 12px; color: var(--faint); overflow-wrap: anywhere; margin-top: 2px; }
.card-head .grow { flex: 1; min-width: 0; }

.live-row { display: flex; gap: 32px; }
.live-row span { font-size: 12px; color: var(--muted); }
.live-row b { display: block; font-family: var(--mono); font-size: 15px; font-weight: 400; color: var(--text); }
.alert { padding: 8px 10px; border-radius: var(--radius); font-size: 13px; background: var(--sunken); border-left: 3px solid var(--bad); }
.alert.warn { border-left-color: var(--warn); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions .spacer { flex: 1; }

.events { margin: 0; padding: 10px 0 0; list-style: none; display: grid; gap: 2px; border-top: 1px solid var(--line); }
.events li { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.events time { font-family: var(--mono); color: var(--faint); flex: none; }

.empty { padding: 28px 18px; text-align: center; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.form-grid { display: grid; gap: 12px; }
.howto { margin: 0; padding: 0 0 0 18px; color: var(--muted); font-size: 13px; }
.howto li + li { margin-top: 2px; }
.howto b { color: var(--text); font-weight: 500; }

/* Admin: media table */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.disabled td { color: var(--faint); }
td .login { font-family: var(--mono); font-size: 12px; color: var(--faint); }
td.num { font-family: var(--mono); font-size: 13px; }
.mini-outputs { display: grid; gap: 6px; }
.mini { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 13px; }
.mini .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .rate { font-family: var(--mono); font-size: 12px; color: var(--faint); white-space: nowrap; }
.mini-empty { font-size: 13px; color: var(--faint); }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; flex-wrap: wrap; }
.new-media { margin-top: 24px; }
.new-media h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.new-media form { display: grid; grid-template-columns: 1.4fr 1fr 110px auto; gap: 12px; align-items: end; }

/* Admin: input */
.ingest-detail { display: grid; gap: 16px; max-width: 760px; }
.copy-field { display: flex; gap: 8px; }
.copy-field input { flex: 1; min-width: 0; }
.specs { display: grid; grid-template-columns: max-content 1fr; gap: 6px 24px; margin: 0; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.specs div { display: contents; }
.specs dt { color: var(--muted); }
.specs dd { margin: 0; font-family: var(--mono); font-size: 13px; }

/* Dialog */
dialog {
  width: min(440px, calc(100vw - 32px)); padding: 0; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { padding: 20px; display: grid; gap: 14px; }
dialog h3 { margin: 0; font-size: 16px; font-weight: 600; }
dialog p { margin: 0; color: var(--muted); }
.secret {
  font-family: var(--mono); font-size: 18px; text-align: center;
  padding: 12px; border-radius: var(--radius); background: var(--sunken); border: 1px solid var(--line-strong);
  user-select: all;
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(360px, 100%); padding: 28px 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  display: grid; gap: 20px;
}
.login-card .brand img { height: 30px; }
.login-card h1 { margin: 0; font-size: 14px; font-weight: 400; color: var(--muted); }
.login-card form { display: grid; gap: 12px; }
.login-card button { height: 38px; margin-top: 4px; }
.foot { margin: 0; font-size: 12px; color: var(--faint); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  padding: 8px 14px; border-radius: var(--radius); background: var(--text); color: var(--bg);
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 20;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; }
.toast.error { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .brand img { height: 22px; }
  .who { display: none; }
  .ingest .stats { margin-left: 0; width: 100%; }
  .new-media form { grid-template-columns: 1fr; }
  thead { display: none; }
  table, tbody, tr, td { display: block; }
  tr { border-bottom: 1px solid var(--line); padding: 6px 0; }
  tr:last-child { border-bottom: 0; }
  td { border: 0; padding: 6px 14px; }
  .row-actions { justify-content: flex-start; }
}

[data-slot="live"] { display: grid; gap: 12px; }
[data-slot="live"]:empty { display: none; }
.topbar button.ghost { font-weight: 400; }
th:nth-child(3), td.num { width: 1%; text-align: right; }

/* Guide (/navod) */
.topbar-link { color: var(--muted); text-decoration: none; font-size: 13px; padding: 4px 8px; border-radius: var(--radius); }
.topbar-link:hover { color: var(--text); background: var(--sunken); }
.doc { max-width: 720px; padding-top: 40px; font-size: 15px; line-height: 1.6; }
.doc h1 { margin: 0 0 12px; font-size: 26px; font-weight: 600; line-height: 1.25; }
.doc .lead { margin: 0 0 24px; color: var(--muted); font-size: 16px; }
.doc section { margin-top: 44px; scroll-margin-top: 16px; }
.doc h2 { margin: 0 0 12px; font-size: 19px; font-weight: 600; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.doc h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.doc p { margin: 0 0 10px; }
.doc ul { margin: 0; padding-left: 20px; }
.doc li + li { margin-top: 6px; }
.doc b { font-weight: 600; }
.toc { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--text); text-decoration: underline; }
.steps { list-style: none; counter-reset: step; margin: 16px 0 0; padding: 0; display: grid; gap: 14px; }
.steps > li { counter-increment: step; position: relative; padding: 16px 18px 8px 58px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.steps > li + li { margin-top: 0; }
.steps > li::before {
  content: counter(step); position: absolute; left: 18px; top: 15px;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 13px;
}
.note { margin: 4px 0 10px; padding: 10px 12px; background: var(--sunken); border-left: 3px solid var(--accent); border-radius: var(--radius); font-size: 14px; }
.example { display: grid; gap: 6px; margin: 0 0 10px; padding: 10px 12px; background: var(--sunken); border-radius: var(--radius); }
.example div { display: grid; grid-template-columns: 160px 1fr; gap: 12px; }
.example dt { color: var(--muted); font-size: 14px; }
.example dd { margin: 0; font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.states { margin: 0; display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.states div { display: grid; grid-template-columns: 190px 1fr; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.states div:last-child { border-bottom: 0; }
.states dd { margin: 0; color: var(--muted); font-size: 14px; }
.faq { margin: 0; display: grid; gap: 18px; }
.faq dt { font-weight: 600; margin-bottom: 4px; }
.faq dd { margin: 0; color: var(--muted); }
.contact { margin-top: 28px !important; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); }
.doc .status { vertical-align: -1px; }
@media (max-width: 760px) {
  .doc { padding-top: 24px; }
  .doc h1 { font-size: 22px; }
  .steps > li { padding-left: 52px; }
  .example div, .states div { grid-template-columns: 1fr; gap: 2px; }
}
.foot a, .contact a, .doc a, .empty a { text-decoration: underline; text-underline-offset: 2px; }
