:root {
  --bg: #0f1216;
  --bg-elev: #161b22;
  --bg-elev-2: #1c232c;
  --border: #262f3a;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --accent: #4f9cf9;
  --accent-soft: rgba(79, 156, 249, .14);
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --bg-elev: #ffffff; --bg-elev-2: #f0f3f6;
    --border: #d8dee4; --text: #1f2328; --text-dim: #636c76;
    --accent-soft: rgba(79, 156, 249, .10);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 18px 60px; }

header.top { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
header.top h1 { font-size: 20px; margin: 0; letter-spacing: .3px; }
header.top .sub { color: var(--text-dim); font-size: 13px; }
header.top .spacer { flex: 1; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { color: var(--text-dim); font-size: 12px; }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .value small { font-size: 12px; font-weight: 400; color: var(--text-dim); margin-left: 4px; }

.panel { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
input[type=search], select, button {
  background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 11px; font-size: 13px; font-family: inherit;
}
input[type=search] { min-width: 220px; flex: 1; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 13px; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip .n { opacity: .65; margin-left: 5px; }

.sub-url { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.sub-url code {
  flex: 1; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; font-size: 12px; overflow-x: auto; white-space: nowrap; color: var(--text-dim);
}

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--text-dim);
  padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer;
}
thead th.sorted { color: var(--accent); }
tbody td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--bg-elev-2); }
tbody td.num { font-variant-numeric: tabular-nums; color: var(--text-dim); }

.logo { width: 42px; height: 26px; object-fit: contain; background: var(--bg-elev-2); border-radius: 4px; }
.name { font-weight: 500; }
.name .backup { color: var(--text-dim); font-weight: 400; font-size: 12px; margin-left: 6px; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border); color: var(--text-dim); }
.badge.hd { color: var(--ok); border-color: rgba(63,185,80,.4); }
.badge.sd { color: var(--warn); border-color: rgba(210,153,34,.4); }

.bar { height: 5px; width: 64px; background: var(--bg-elev-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.good > i { background: var(--ok); }
.bar.mid > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }

.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 4px 9px; font-size: 12px; }

.empty, .loading { text-align: center; color: var(--text-dim); padding: 40px 0; }

footer { color: var(--text-dim); font-size: 12px; text-align: center; margin-top: 28px; line-height: 1.8; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal.open { display: flex; }
.modal .box { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); width: min(920px, 100%); max-height: 90vh; overflow: auto; }
.modal .box header { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.modal .box header h3 { margin: 0; font-size: 15px; flex: 1; }
.modal .box .body { padding: 14px; }
video { width: 100%; background: #000; border-radius: 8px; aspect-ratio: 16/9; }
.stream-list { margin-top: 12px; font-size: 12px; }
.stream-list div { display: flex; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); align-items: center; }
.stream-list code { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); padding: 9px 16px; border-radius: 999px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

@media (max-width: 720px) {
  .hide-sm { display: none; }
  .wrap { padding: 16px 12px 40px; }
}

/* ---------------------------------------------------------- 管理后台 */
.wrap.wide { max-width: 1480px; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid transparent; border-bottom: 2px solid transparent;
  color: var(--text-dim); border-radius: 8px 8px 0 0; padding: 8px 14px;
}
.tab:hover { color: var(--text); border-color: transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--accent-soft); }
.tabpage.hidden { display: none; }

.panel h3 { margin: 0 0 10px; font-size: 14px; color: var(--text-dim); font-weight: 600; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

.tile .value.sm { font-size: 14px; font-weight: 500; }
.controls .spacer { flex: 1; }

.progress-box { margin-top: 12px; }
.progress { height: 8px; background: var(--bg-elev-2); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.progress-meta { display: flex; gap: 16px; margin-top: 6px; font-size: 12px; color: var(--text-dim); }

.logs {
  margin: 12px 0 0; padding: 10px 12px; max-height: 320px; overflow: auto;
  background: #0b0e12; color: #c9d4e0; border: 1px solid var(--border); border-radius: 8px;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap;
  word-break: break-all;
}
.logs.sm { max-height: 200px; }
.logs .warn { color: var(--warn); }
.logs .err { color: var(--bad); }
.hidden { display: none; }

table.compact td, table.compact th { padding: 5px 8px; font-size: 12px; }

#sourcesTable input[type=text], #sourcesTable input[type=number], #sourcesTable select {
  width: 100%; background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 7px; font-size: 12px;
}
#sourcesTable td { padding: 6px; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 12px 0; color: var(--text-dim); font-size: 13px; }

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 12px; }
.settings fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0; }
.settings legend { color: var(--text-dim); font-size: 12px; padding: 0 6px; }
.field { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.field label { flex: 1; font-size: 13px; }
.field .hint { color: var(--text-dim); font-size: 11px; }
.field input, .field select {
  width: 130px; background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 13px;
}
.field input.wide { width: 100%; }
.field.full { display: block; }
.field.full input { width: 100%; margin-top: 4px; }

.state-ok { color: var(--ok); }
.state-bad { color: var(--bad); }

.box.narrow { width: min(520px, 100%); }
