:root {
  --bg: #0b1120;
  --card: #131c31;
  --card2: #18223b;
  --line: #24314f;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--primary); }
code {
  background: #0f1729; border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 5px; font-size: .85em; word-break: break-all;
}
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- login ---------- */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; width: 100%; max-width: 380px;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.3rem; }
label { display: block; margin: 12px 0; font-size: .86rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; margin-top: 5px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: #0f1729; color: var(--text);
  font-size: 1rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); }
label.check { display: flex; gap: 9px; align-items: flex-start; color: var(--text); }
label.check input { width: auto; margin-top: 3px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; flex-direction: column;
  background: #0d1526; border-bottom: 1px solid var(--line); padding: 10px 16px; gap: 8px;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 1.02rem; }
.dot {
  width: 11px; height: 11px; border-radius: 50%; background: var(--muted);
  box-shadow: 0 0 0 3px rgba(148,163,184,.15);
}
.dot.live { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.2); animation: pulse 1.6s infinite; }
.dot.error { background: var(--red); }
.dot.busy { background: var(--amber); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }
.phase { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.topbar nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-size: .88rem;
}
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.who { color: var(--muted); font-size: .85rem; }
.inline { display: inline; margin: 0; }

main, .tabpane { padding: 16px; max-width: 1250px; margin: 0 auto; }
.tabpane { display: none; }
.tabpane.active { display: block; }

.grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 1rem; letter-spacing: .02em; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  padding: 9px 15px; border-radius: 8px; cursor: pointer; font-size: .9rem;
  font-family: inherit;
}
button:hover:not(:disabled) { border-color: var(--primary); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
button.danger { background: transparent; border-color: var(--red); color: #fca5a5; }
button.ghost { background: transparent; }
button.full { width: 100%; margin-top: 6px; }
button.tiny { padding: 4px 9px; font-size: .78rem; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem;
  background: var(--card2); border: 1px solid var(--line); color: var(--muted);
}
.badge.ok { background: rgba(34,197,94,.15); border-color: var(--green); color: #86efac; }
.badge.bad { background: rgba(239,68,68,.15); border-color: var(--red); color: #fca5a5; }
.badge.warn { background: rgba(245,158,11,.15); border-color: var(--amber); color: #fcd34d; }
.channel { font-weight: 600; margin-left: 8px; }
.status-line { display: flex; align-items: center; flex-wrap: wrap; }

.alert { padding: 10px 13px; border-radius: 8px; margin: 10px 0; font-size: .87rem; }
.alert.error { background: rgba(239,68,68,.12); border: 1px solid var(--red); color: #fecaca; }
.alert.warn { background: rgba(245,158,11,.12); border: 1px solid var(--amber); color: #fde68a; }

.metrics { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 14px; }
.metric {
  display: flex; justify-content: space-between; gap: 10px; padding: 8px 11px;
  background: var(--card2); border-radius: 8px; font-size: .87rem;
}
.metric .k { color: var(--muted); }
.metric .v { font-weight: 600; text-align: right; word-break: break-word; }

.progress { margin-top: 14px; }
.progress-bar { height: 9px; background: #0f1729; border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--green)); transition: width .4s; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
td.name { white-space: normal; word-break: break-word; max-width: 380px; }

#playlist-list { padding-left: 0; list-style: none; margin: 10px 0 22px; }
#playlist-list li {
  display: flex; align-items: center; gap: 9px; padding: 8px 11px; background: var(--card2);
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 7px; font-size: .87rem;
}
#playlist-list .pos { color: var(--muted); min-width: 22px; }
#playlist-list .nm { flex: 1; word-break: break-word; }

.sticky-save {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 12px;
  background: linear-gradient(transparent, var(--bg) 35%); padding: 12px 0; flex-wrap: wrap;
}
.logview {
  background: #050a15; border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  max-height: 62vh; overflow: auto; font-size: .78rem; white-space: pre-wrap;
  word-break: break-word; font-family: ui-monospace, Menlo, Consolas, monospace;
}
progress { width: 100%; height: 12px; margin: 10px 0; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--primary); color: var(--text);
  padding: 11px 18px; border-radius: 10px; z-index: 50; font-size: .89rem;
  max-width: 90vw; box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
.toast.error { border-color: var(--red); }
.toast.ok { border-color: var(--green); }

@media (min-width: 700px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: row; align-items: center; justify-content: space-between; }
}
@media (min-width: 1000px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .span2 { grid-column: 1 / -1; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
}