:root {
  --bg: #0E1116;
  --surface: #171B22;
  --surface-2: #1D222B;
  --border: #262C36;
  --text: #E6E9EF;
  --muted: #8A93A2;
  --accent: #F5B83D;
  --accent-ink: #1A1303;
  --live: #FF4D4D;
  --ok: #3DDC97;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: rgba(14, 17, 22, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.28em; font-size: 14px; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: #5a2a2a; }
.brand-dot.on { background: var(--live); box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.6); animation: pulse 1.8s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(255, 77, 77, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); } }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap; font-weight: 500; }
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; white-space: nowrap; }

.page { max-width: 1040px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }

/* ---- buttons & inputs ---- */
button, input, select { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  font-weight: 550; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: border-color .12s, background .12s;
}
.btn:hover { border-color: #3a4352; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ffc85a; border-color: #ffc85a; }
.btn.danger { color: #ff8a8a; }
.btn.danger:hover { border-color: #7a3030; }
.btn.ghost { background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 30px; padding: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label, .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="number"], select {
  height: 40px; padding: 0 12px; width: 100%;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---- cards & rows ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card.pad { padding: 20px; }
.list { display: flex; flex-direction: column; gap: 12px; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.stream { display: grid; grid-template-columns: 148px 1fr auto; gap: 8px 20px; padding: 18px 20px; align-items: start; }
.stream.is-live { border-color: #4a2626; }
.state { display: flex; align-items: center; gap: 9px; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; padding-top: 3px; }
.lamp { width: 10px; height: 10px; border-radius: 50%; background: #3a4150; flex: none; }
.state.live { color: var(--live); }
.state.live .lamp { background: var(--live); box-shadow: 0 0 10px rgba(255, 77, 77, 0.8); }
.state.connecting, .state.reconnecting { color: var(--accent); }
.state.connecting .lamp, .state.reconnecting .lamp { background: var(--accent); animation: blink 1s steps(2) infinite; }
.state.error { color: #ff8a8a; }
.state.error .lamp { background: #7a3030; }
.state.stopped { color: var(--muted); }
@keyframes blink { 50% { opacity: .25; } }
.stream-title { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.stream-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 13px; margin-top: 4px; }
.stream-meta b { color: var(--text); font-weight: 550; }
.stream-error { margin-top: 8px; font-size: 13px; color: #ffb0a8; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 550; overflow-wrap: anywhere; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ready { color: var(--ok); }
.badge.failed { color: #ff8a8a; }
.badge.busy { color: var(--accent); }
.bar { height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }

.drop {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 28px 20px; text-align: center; margin-bottom: 20px;
  transition: border-color .12s, background .12s;
}
.drop.over { border-color: var(--accent); background: rgba(245, 184, 61, 0.06); }
.drop p { margin-bottom: 12px; }
.drop p:last-of-type { margin: 12px 0 0; }

/* ---- playlists ---- */
.split { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.pl-item { display: block; width: 100%; text-align: left; padding: 12px 16px; background: none; border: 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.pl-item:last-child { border-bottom: 0; }
.pl-item:hover { background: var(--surface-2); }
.pl-item.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.pl-item .title { font-weight: 550; overflow-wrap: anywhere; }
.item { cursor: grab; }
.item.dragging { opacity: .4; }
.item.over { box-shadow: inset 0 2px 0 var(--accent); }
.item .pos { width: 24px; color: var(--muted); font-size: 13px; text-align: right; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 24px 0 10px; }

/* ---- stream form ---- */
.seg { display: inline-flex; align-self: flex-start; padding: 3px; gap: 3px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 550; font-size: 14px; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.step { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; margin: 28px 0 14px; padding-top: 20px; border-top: 1px solid var(--border); }
.step:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
.step span { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); color: var(--accent); font-size: 12px; }
.time { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.time input { width: 84px; }
.empty.slim { padding: 18px 16px; font-size: 14px; }
.card.scroll { max-height: 220px; overflow: auto; }
.card.gap { margin-top: 10px; }
.label { display: block; margin-bottom: 8px; }
.section-title .label { margin: 0; }

/* ---- dialog ---- */
dialog {
  width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
dialog.wide { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 7, 10, 0.7); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.dlg-body { padding: 20px; max-height: 70vh; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.note { font-size: 13px; color: var(--accent); background: rgba(245, 184, 61, 0.08); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; }
.log { margin: 0; font: 12.5px/1.6 var(--mono); color: #c6ccd6; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .brand { margin-bottom: 24px; font-size: 16px; }
.login .btn { width: 100%; height: 42px; }
.form-error { color: #ff8a8a; font-size: 13px; min-height: 20px; margin-bottom: 8px; }

/* ---- toasts ---- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--ok); border-radius: 8px; padding: 10px 14px; font-size: 14px; max-width: 420px; overflow-wrap: anywhere; }
.toast.err { border-left-color: var(--live); }

@media (max-width: 760px) {
  .topbar { padding: 0 14px; gap: 12px; }
  .who .name { display: none; }
  .page { padding: 20px 14px 80px; }
  .stream { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
  .split { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
