:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f8f9fc;
  --text: #1b2030;
  --muted: #687089;
  --border: #e2e6ef;
  --accent: #4f7cff;
  --ok: #1fa971;
  --bad: #e5484d;
  --warn: #f5a524;
  --k-song: #4f7cff;
  --k-music: #b9c9ff;
  --k-jingle: #f59e0b;
  --k-ad: #e5484d;
  --k-promo: #c056e0;
  --k-other: #8b8fa3;
  --k-speech: #1fa971;
  --k-silence: #9aa0b1;
  --k-offline: #3a3f4f;
  --k-meta: #7c5cff;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 2px 8px rgba(20, 30, 60, .04);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --panel: #171b24; --panel-2: #1c212c; --text: #e6e9f2; --muted: #8d95ab;
    --border: #2a3040; --k-music: #34406b; --k-silence: #5b6275; --k-offline: #c9cede;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --panel: #171b24; --panel-2: #1c212c; --text: #e6e9f2; --muted: #8d95ab;
  --border: #2a3040; --k-music: #34406b; --k-silence: #5b6275; --k-offline: #c9cede;
  --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", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 54px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 18px; height: 18px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
nav a:hover { background: var(--panel-2); text-decoration: none; }
nav a.active { color: var(--text); background: var(--panel-2); font-weight: 600; }
.engine-state { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.spacer { flex: 1; }
.section { margin-top: 16px; }

button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.seg-btns { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btns button { border: 0; border-radius: 0; border-right: 1px solid var(--border); }
.seg-btns button:last-child { border-right: 0; }
.seg-btns button.on { background: var(--accent); color: #fff; }
input, select {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 8px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { display: flex; gap: 6px; align-items: center; }

/* ---- station cards ---- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.alarm { border-color: var(--bad); box-shadow: 0 0 0 2px color-mix(in srgb, var(--bad) 30%, transparent); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head a { font-size: 16px; font-weight: 700; color: var(--text); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--k-silence); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.bad { background: var(--bad); }
.badges { margin-left: auto; display: flex; gap: 6px; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.on.music { background: var(--k-song); color: #fff; border-color: transparent; }
.badge.on.speech { background: var(--k-speech); color: #fff; border-color: transparent; }
.badge.on.silence { background: var(--k-silence); color: #fff; border-color: transparent; }
.alarm-banner { background: var(--bad); color: #fff; border-radius: 8px; padding: 8px 12px; font-weight: 600; }
.now .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.now .song { font-size: 17px; font-weight: 600; margin-top: 2px; }
.now .sub { font-size: 12px; color: var(--muted); }
.meta-line { font-size: 12px; color: var(--muted); }
.meta-line b { color: var(--text); font-weight: 500; }
.quote { font-size: 13px; padding: 8px 10px; border-left: 3px solid var(--k-speech); background: var(--panel-2);
  border-radius: 0 6px 6px 0; }
.spark { width: 100%; height: 56px; display: block; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 8px; }
.kpi { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.kpi .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .k { font-size: 11px; color: var(--muted); }
.meter { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.meter > div { height: 100%; background: var(--ok); }

/* ---- timeline ---- */
.tl { position: relative; user-select: none; }
.tl-axis { position: relative; height: 20px; margin-left: 130px; border-bottom: 1px solid var(--border); }
.tl-tick { position: absolute; top: 0; font-size: 11px; color: var(--muted); transform: translateX(-50%); white-space: nowrap; }
.tl-lane { display: flex; align-items: center; height: 30px; border-bottom: 1px dashed var(--border); }
.tl-lane .name { width: 130px; flex: none; font-size: 12px; color: var(--muted); padding-right: 8px; }
.tl-lane .track { position: relative; flex: 1; height: 20px; }
.seg { position: absolute; top: 2px; bottom: 2px; min-width: 2px; border-radius: 3px; cursor: pointer; }
.seg:hover { outline: 2px solid var(--text); z-index: 2; }
.seg.music { background: var(--k-music); top: 5px; bottom: 5px; }
.seg.song { background: var(--k-song); }
.seg.jingle { background: var(--k-jingle); }
.seg.ad { background: var(--k-ad); }
.seg.promo { background: var(--k-promo); }
.seg.other { background: var(--k-other); }
.seg.speech { background: var(--k-speech); }
.seg.silence { background: var(--k-silence); }
.seg.offline { background: repeating-linear-gradient(45deg, var(--k-offline) 0 4px, transparent 4px 8px); }
.seg.meta { background: var(--k-meta); width: 2px !important; min-width: 2px; }
.seg.new { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .7); }
.tl-now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); opacity: .6; }
.tooltip { position: fixed; z-index: 100; pointer-events: none; max-width: 380px; background: var(--text); color: var(--bg);
  padding: 8px 10px; border-radius: 8px; font-size: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }
.tooltip b { display: block; margin-bottom: 2px; }

/* ---- bars ---- */
.bars { display: flex; align-items: flex-end; gap: 2px; height: 140px; padding-top: 4px; }
.bar { flex: 1; display: flex; flex-direction: column-reverse; height: 100%; min-width: 4px;
  background: var(--panel-2); border-radius: 3px 3px 0 0; overflow: hidden; }
.bar > div { width: 100%; }
.bar-labels { display: flex; gap: 2px; font-size: 10px; color: var(--muted); }
.bar-labels span { flex: 1; text-align: center; overflow: hidden; white-space: nowrap; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--panel-2); }
td.t { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.kind { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; color: #fff; white-space: nowrap; }
.kind.song { background: var(--k-song); } .kind.music { background: var(--k-music); color: var(--text); }
.kind.jingle { background: var(--k-jingle); } .kind.ad { background: var(--k-ad); }
.kind.promo { background: var(--k-promo); } .kind.other { background: var(--k-other); }
.kind.speech { background: var(--k-speech); } .kind.silence { background: var(--k-silence); }
.kind.offline { background: var(--k-offline); color: var(--bg); } .kind.meta { background: var(--k-meta); }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-left: 6px; white-space: nowrap; }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.table-wrap { overflow-x: auto; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.list li .n { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.transcript { max-height: 420px; overflow-y: auto; }
.transcript p { margin: 0; padding: 6px 0; border-bottom: 1px solid var(--border); }
.transcript time { color: var(--muted); font-size: 12px; margin-right: 8px; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.detail { min-height: 48px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.probe { font-size: 12px; background: var(--panel-2); border-radius: 8px; padding: 8px 12px; }
.probe.bad { color: var(--bad); }
.notice { padding: 12px 16px; border-radius: var(--radius); background: color-mix(in srgb, var(--warn) 15%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border)); margin-bottom: 16px; }

@media (max-width: 720px) {
  .topbar { gap: 12px; padding: 0 12px; }
  .engine-state { display: none; }
  main { padding: 16px; }
  .grid.cards { grid-template-columns: 1fr; }
  .tl-axis { margin-left: 80px; }
  .tl-lane .name { width: 80px; font-size: 11px; }
}

/* ---- login / user ---- */
.user-box { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 13px; }
body.login-mode .topbar nav, body.login-mode .engine-state, body.login-mode .user-box { visibility: hidden; }
.login-wrap { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.login { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
.brand.big { font-size: 20px; margin-bottom: 8px; }
.err { color: var(--bad); }
code.pw { font-size: 18px; padding: 6px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; user-select: all; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; }

/* ---- play buttons + player bar ---- */
button.play {
  width: 22px; height: 22px; padding: 0; border-radius: 50%; font-size: 9px; line-height: 20px;
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border)); background: var(--panel);
  flex: none; cursor: pointer;
}
button.play:hover { background: var(--accent); color: #fff; }
.transcript p button.play { margin-right: 6px; }
.said { margin: 6px 0; padding: 8px 10px; border-left: 3px solid var(--k-jingle); background: var(--panel-2); border-radius: 0 6px 6px 0; }
main { padding-bottom: 90px; }
.player {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 12px; z-index: 30;
  width: min(720px, calc(100% - 32px)); display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 6px 24px rgba(20, 30, 60, .18);
}
.pl-btn { min-width: 36px; height: 32px; padding: 0 8px; font-size: 12px; }
.pl-btn.main { min-width: 44px; height: 38px; font-size: 14px; background: var(--accent); color: #fff; border-color: var(--accent); }
.pl-info { flex: 1; min-width: 0; }
.pl-label { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-head { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--warn); z-index: 2; pointer-events: none; }
.tl-lane .track { cursor: crosshair; }
.replay { flex-wrap: wrap; gap: 8px; padding: 8px 10px; background: var(--panel-2); border-radius: 8px; }
@media (max-width: 640px) {
  .user-box .small, .engine-state { display: none; }
  .pl-btn:not(.main) { min-width: 30px; padding: 0 4px; }
}
.player[hidden] { display: none; }
button.play.on { background: var(--bad); border-color: var(--bad); color: #fff; }
.pl-btn.stop { color: var(--bad); font-weight: 600; white-space: nowrap; }
.pl-btn.stop:hover { background: var(--bad); color: #fff; border-color: var(--bad); }

/* ---- checkboxes as clear on/off switches ---- */
label.check {
  gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-2); cursor: pointer; user-select: none; align-self: start;
}
label.check:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
label.check:has(input:checked) {
  border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel)); font-weight: 600;
}
label.check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; cursor: pointer;
  width: 42px; height: 24px; padding: 0; margin: 0; border: 0; border-radius: 12px;
  background: color-mix(in srgb, var(--muted) 45%, var(--border)); transition: background .15s;
}
label.check input[type="checkbox"]::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: left .15s;
}
label.check input[type="checkbox"]:checked { background: var(--ok); }
label.check input[type="checkbox"]:checked::before { left: 21px; }
label.check input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label.check::after { content: "OFF"; margin-left: auto; padding-left: 8px; font-size: 11px; font-weight: 700; color: var(--muted); }
label.check:has(input:checked)::after { content: "ON"; color: var(--ok); }

/* ---- live listening ---- */
button.live-btn {
  margin-left: 8px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 50%, var(--border)); background: var(--panel); cursor: pointer;
}
button.live-btn:hover, button.live-btn.on { background: var(--bad); color: #fff; border-color: var(--bad); }
.live-badge {
  flex: none; padding: 4px 10px; border-radius: 999px; background: var(--bad); color: #fff;
  font-size: 12px; font-weight: 700; animation: livepulse 1.6s ease-in-out infinite;
}
@keyframes livepulse { 50% { opacity: .55; } }
