:root {
  --bg: #f6f7f9; --card: #fff; --text: #1b1d21; --muted: #6b7280; --line: #e5e7eb;
  --primary: #d92d20; --primary-h: #b42318;
  --ok: #067647; --ok-bg: #ecfdf3; --warn: #b54708; --warn-bg: #fffaeb;
  --err: #b42318; --err-bg: #fef3f2; --info-bg: #f2f4f7; --v: #6941c6; --v-bg: #f4f3ff;
}
/* Giao diện: data-theme="light" | "dark" do người dùng chọn (nút ☀/☾ trên thanh trên); không có = theo máy */
:root { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111317; --card: #1a1d23; --text: #e6e7ea; --muted: #9096a1; --line: #2b2f37;
    --ok: #47cd89; --ok-bg: #0f2a1d; --warn: #fdb022; --warn-bg: #2d220c;
    --err: #f97066; --err-bg: #331513; --info-bg: #23272f; --v: #b692f6; --v-bg: #251d3a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317; --card: #1a1d23; --text: #e6e7ea; --muted: #9096a1; --line: #2b2f37;
  --ok: #47cd89; --ok-bg: #0f2a1d; --warn: #fdb022; --warn-bg: #2d220c;
  --err: #f97066; --err-bg: #331513; --info-bg: #23272f; --v: #b692f6; --v-bg: #251d3a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; }
code { font: 12px ui-monospace, Consolas, monospace; background: var(--info-bg); padding: 2px 6px; border-radius: 4px; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
h2 { margin: 0 0 4px; font-size: 18px; }
h3 { margin: 0 0 10px; font-size: 15px; }

.top { display: flex; align-items: center; gap: 20px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--primary); text-decoration: none; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { text-decoration: none; padding: 6px 12px; border-radius: 6px; color: var(--muted); }
.top nav a.on, .top nav a:hover { background: var(--info-bg); color: var(--text); }
.logout { margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row form, .actions form { margin: 0; display: inline; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.datenav { display: flex; gap: 6px; align-items: center; }
.datenav form { margin: 0; }
.dow { margin-left: 8px; }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 14px; border-radius: 7px; font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: wait; }
input[type=date], input[type=password] { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--text); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; background: var(--info-bg); }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.error { background: var(--err-bg); color: var(--err); }

.ch-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--err); }
.nowrap { white-space: nowrap; }
.copy { cursor: copy; }
.copy:hover { text-decoration: underline dotted; }

.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--info-bg); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn, .pill.partial, .pill.late { background: var(--warn-bg); color: var(--warn); }
.pill.error { background: var(--err-bg); color: var(--err); }
.pill.pending { background: var(--info-bg); color: var(--text); }
.pill.v { background: var(--v-bg); color: var(--v); margin-left: 4px; }

.table-wrap { overflow-x: auto; }
table.jobs { width: 100%; border-collapse: collapse; }
table.jobs th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.jobs td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.jobs tr:last-child td { border-bottom: 0; }
tr.st-skip td { opacity: .55; }
.title-cell { min-width: 320px; }
.title { font-weight: 500; }
pre.desc { white-space: pre-wrap; background: var(--info-bg); padding: 8px; border-radius: 6px; margin: 6px 0; font: 12px/1.5 ui-monospace, Consolas, monospace; }
.actions { text-align: right; }

.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs a { padding: 6px 14px; border-radius: 7px; text-decoration: none; color: var(--muted); }
.tabs a.on { background: var(--card); color: var(--text); border: 1px solid var(--line); }
textarea.code { width: 100%; min-height: 65vh; font: 13px/1.5 ui-monospace, Consolas, monospace; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); margin-bottom: 10px; tab-size: 2; }
.help summary { cursor: pointer; font-weight: 600; }
table.kv td { padding: 5px 10px 5px 0; vertical-align: top; }
table.kv td:first-child { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; color: var(--muted); }
pre.log { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font: 12px/1.6 ui-monospace, Consolas, monospace; white-space: pre-wrap; max-height: 80vh; overflow: auto; }

/* Trang đăng nhập luôn nền sáng cho hợp logo (bỏ qua dark mode) */
body.login-page {
  --bg: #f6f7f9; --card: #fff; --text: #1b1d21; --muted: #6b7280; --line: #e5e7eb;
  --err: #b42318; --err-bg: #fef3f2; --ok: #067647; --ok-bg: #ecfdf3; --warn: #b54708; --warn-bg: #fffaeb; --info-bg: #f2f4f7;
  color-scheme: light;
  background: linear-gradient(180deg, #fff 0%, #eef2f7 100%);
}
.login-page .card.login { box-shadow: 0 8px 24px rgba(16, 24, 40, .08); }
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-wrap { width: 100%; max-width: 340px; display: grid; gap: 16px; justify-items: center; }
.login-logo { display: block; max-width: 200px; max-height: 80px; height: auto; }
.private-note { margin: 0; font-size: 12px; line-height: 1.5; color: var(--muted); text-align: center; }
.card.login { width: 100%; max-width: 340px; display: grid; gap: 12px; }
.card.login h1 { margin: 0; font-size: 20px; color: var(--primary); }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px; }
  .title-cell { min-width: 240px; }
}

/* ── Form sửa kênh ───────────────────────────────────────── */
.grid { display: grid; gap: 10px 14px; margin-bottom: 10px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g5 { grid-template-columns: repeat(5, 1fr); }
.g6 { grid-template-columns: repeat(6, 1fr); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin: 2px 0; }
label.check.inline, label.inline { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; margin: 0 10px 0 0; font-weight: 400; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  font: 13px/1.4 inherit; font-family: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--bg); color: var(--text); width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
textarea { resize: vertical; font-family: inherit; }
.mono, .keep-space { font-family: ui-monospace, Consolas, monospace !important; }
input.full { width: 100%; }
input.search { width: 240px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 4px; margin: 0 0 10px; min-width: 0; }
fieldset legend { font-size: 12px; color: var(--muted); padding: 0 4px; font-weight: 600; }
fieldset > label.check { display: inline-flex; margin-right: 12px; }
fieldset.vertical { border-style: dashed; border-color: var(--v); }

.live-card { border: 1px solid var(--line); border-radius: 10px; padding: 0 14px; margin-bottom: 10px; background: var(--card); }
.live-card[open] { padding-bottom: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.live-card > summary { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; cursor: pointer; list-style: none; }
.live-card > summary::-webkit-details-marker { display: none; }
.live-card > summary::before { content: '▸'; color: var(--muted); margin-right: 4px; }
.live-card[open] > summary::before { content: '▾'; }
.live-card[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.live-sum { display: flex; gap: 8px; align-items: center; flex: 1; flex-wrap: wrap; }
.live-tools { display: flex; gap: 4px; }
.savebar { position: sticky; bottom: 0; z-index: 4; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; box-shadow: 0 -2px 10px rgba(0,0,0,.06); }
.savebar input[type=date] { width: auto; }
.chlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.chitem { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; }
.chitem:hover { border-color: var(--primary); }
.toolbar h2, .toolbar h3 { margin: 0; }
.toolbar { align-items: center; }

/* ── RTMP keys ───────────────────────────────────────────── */
table.keys code.key { font-size: 13px; }
table.keys code.small { font-size: 11px; }

@media (max-width: 900px) {
  .g4, .g5, .g6 { grid-template-columns: repeat(2, 1fr); }
  .g2, .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .g4, .g5, .g6 { grid-template-columns: 1fr; }
  .live-tools .btn { padding: 3px 7px; }
}

form.inline, .meta form { display: inline; margin: 0; }
.pill.overdue { background: var(--warn-bg); color: var(--warn); }
.pill.off { background: var(--err-bg); color: var(--err); }
.cachebar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 16px; }
.cachebar form { margin: 0; }
.live-card select { font-family: inherit; }

.cron-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0; }
code.url { word-break: break-all; }
pre.crontab { background: var(--info-bg); padding: 8px 10px; border-radius: 6px; font: 12px/1.6 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all; margin: 6px 0 0; }
.pill.stopped { background: var(--info-bg); color: var(--text); }
h3.sub { margin: 16px 0 8px; font-size: 14px; }

.legal-links { margin: 4px 0 0; text-align: center; }
.legal-links a { color: var(--muted); }

/* Mô tả live cao bằng cột Tags / Stream key / Playlist / Thumbnail */
textarea.desc-main { height: 368px; min-height: 120px; }

/* thanh quota OAuth client */
.quota { width: 120px; height: 6px; background: var(--info-bg); border-radius: 3px; overflow: hidden; margin-bottom: 2px; }
.quota span { display: block; height: 100%; background: var(--ok); }
.quota span.hot { background: var(--err); }
dialog.xfer { width: min(460px, calc(100vw - 32px)); color: var(--text); padding: 18px; margin: auto; }
dialog.xfer::backdrop { background: rgba(0, 0, 0, .45); }
dialog.xfer form { display: grid; gap: 12px; }
dialog.xfer h3 { margin: 0; }
dialog.xfer select, dialog.xfer input[name=new_key] { width: 100%; }
.ch-title { display: flex; align-items: center; gap: 8px; }
.ch-order { display: inline-flex; gap: 2px; margin: 0; }
.ch-order .btn { padding: 2px 8px; line-height: 1.3; }
.ch-order .btn:disabled { opacity: .35; cursor: default; }
section.channel { scroll-margin-top: 64px; }
.ver { margin-left: -12px; font: 11px ui-monospace, Consolas, monospace; color: var(--muted); background: var(--info-bg); padding: 1px 6px; border-radius: 99px; white-space: nowrap; cursor: help; }
/* Tổng quan: lưới ô */
.ov-sum { display: grid; gap: 6px; font-size: 13px; }
.ov-ch h3 { margin: 0 0 10px; }
.ov-ch h3 a { text-decoration: none; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
@media (max-width: 480px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } .tile { min-height: 72px; padding: 6px 8px; } }
.tile { display: block; text-decoration: none; color: var(--text); border: 1px solid var(--line); border-left: 5px solid var(--muted);
  border-radius: 8px; padding: 8px 10px; background: var(--card); min-height: 84px; }
a.tile:hover { border-color: var(--muted); }
.t-top { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); letter-spacing: .03em; }
.t-kind { font-weight: 700; }
.t-label { font-weight: 600; margin: 2px 0; }
.t-st { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.t-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.c-ok { border-left-color: var(--ok); } .tile.c-ok .t-st { color: var(--ok); }
.tile.c-live { border-left-color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, var(--card)); } .tile.c-live .t-st { color: var(--primary); font-weight: 600; }
.tile.c-warn { border-left-color: var(--warn); } .tile.c-warn .t-st { color: var(--warn); }
.tile.c-err { border-left-color: var(--err); background: var(--err-bg); } .tile.c-err .t-st { color: var(--err); font-weight: 600; }
.tile.c-done { border-left-color: var(--v); } .tile.c-done .t-st { color: var(--v); }
.tile.c-wait { border-left-color: var(--muted); }
.tile.c-skip { opacity: .45; border-left-style: dashed; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; background: var(--muted); }
.dot.c-ok { background: var(--ok); } .dot.c-live { background: var(--primary); } .dot.c-warn { background: var(--warn); }
.dot.c-err { background: var(--err); } .dot.c-done { background: var(--v); } .dot.c-skip { opacity: .4; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
/* thanh chuyển nhanh tới kênh (trang Lịch live) */
.ch-nav { position: sticky; top: 49px; z-index: 4; display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; margin-bottom: 12px;
  background: var(--bg); border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.ch-nav a { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none; color: var(--muted);
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); font-size: 13px; }
.ch-nav a:hover { color: var(--text); border-color: var(--muted); }
.ch-nav a.on { color: var(--text); border-color: var(--primary); font-weight: 600; }
.nb { font-size: 11px; line-height: 1; padding: 2px 6px; border-radius: 99px; color: #fff; }
.nb.err { background: var(--err); } .nb.warn { background: var(--warn); }
section.channel { scroll-margin-top: calc(var(--navh, 64px) + 8px); }
.theme-btn { margin-left: auto; }
.remember { font-size: 13px; color: var(--muted); }
/* Tiêu đề tự rút gọn: Anchor · Ngày · [Mẫu mỗi đài | Prefix mã] · Suffix · Tối đa */
.title-row { display: grid; grid-template-columns: 1.3fr 1.1fr 2.4fr 1.3fr 70px; gap: 10px; align-items: end; margin-bottom: 10px; }
.title-row.up { grid-template-columns: 1.3fr 1.1fr 2.4fr 1.3fr; }
.tpl-pair { display: grid; grid-template-columns: 1fr 76px; gap: 6px 4px; }
.tpl-pair-label { grid-column: 1 / -1; font-size: 13px; }
@media (max-width: 900px) { .title-row, .title-row.up { grid-template-columns: 1fr 1fr; } .tpl-pair { grid-column: 1 / -1; } }
.t-rtmp { font-size: 11px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-rtmp.h-good { color: var(--ok); } .t-rtmp.h-ok { color: var(--warn); } .t-rtmp.h-bad { color: var(--err); font-weight: 600; } .t-rtmp.h-none { color: var(--muted); }
.t-next { font-size: 11px; margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--line); color: var(--muted); }
.t-next.n-ok { color: var(--ok); } .t-next.n-err { color: var(--err); font-weight: 600; } .t-next.n-skip { opacity: .7; }
.extra-meta { margin-top: 4px; gap: 6px; align-items: center; }
.extra-clients { margin-top: 10px; } .extra-clients .check.inline { margin-right: 16px; }
