/* Video Manager — finance-dashboard look (dark first, light switch): near-black canvas, borderless 16px cards,
   bold Inter-style headings, blue primary, green/red/orange status tints, hairline-separated tables. */
:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0a; --panel: #161616; --panel-2: #1f1f1f; --hover: #232323; --text: #f2f2f2; --muted: #a3a3a3;
  --line: rgba(129, 129, 129, .24); --input: #1f1f1f;
  --primary: #006cec; --primary-hover: #1a7dff; --accent: #4b97ff; --accent-weak: rgba(0, 108, 236, .16);
  --ok: #34c77e; --ok-bg: rgba(37, 183, 112, .16); --warn: #f5a03a; --warn-bg: rgba(236, 128, 0, .16);
  --err: #ff6b6b; --err-bg: rgba(225, 64, 64, .16); --run: #4b97ff; --run-bg: rgba(0, 108, 236, .18);
  --neutral-bg: rgba(160, 160, 160, .16); --chip: #002047; --chip-text: #cfe2ff; --shadow: none;
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7; --panel: #ffffff; --panel-2: #f2f3f5; --hover: #f5f7fa; --text: #111418; --muted: #5f6672;
  --line: #e7e9ee; --input: #ffffff;
  --primary: #006cec; --primary-hover: #005bd0; --accent: #0060d6; --accent-weak: #e8f1fe;
  --ok: #10804a; --ok-bg: #e4f6ed; --warn: #a65300; --warn-bg: #fff1df;
  --err: #c62828; --err-bg: #fdecec; --run: #0060d6; --run-bg: #e8f1fe;
  --neutral-bg: #eceef2; --chip: #e8f1fe; --chip-text: #0b4aa2; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.55 Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg);
  color: var(--text); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---- left menu: icon + label, collapsible to icons (html[data-nav="min"]); a slide-in drawer on phones ---- */
:root { --side-w: 224px; }
html[data-nav="min"] { --side-w: 56px; }
.side { position: fixed; top: 60px; bottom: 0; left: 0; width: var(--side-w); z-index: 4; background: var(--bg);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 10px 8px; overflow-y: auto; overflow-x: hidden; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side a, .side-toggle { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 9px; border-radius: 10px; color: var(--muted);
  font-weight: 600; font-size: 14px; white-space: nowrap; background: none; border: 0; cursor: pointer; width: 100%; text-align: left; }
.side a:hover, .side-toggle:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.side a.on { color: var(--accent); background: var(--accent-weak); }
.side .ico { display: grid; place-items: center; width: 22px; height: 22px; flex: none; }
.side-toggle { margin-top: 8px; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; height: 44px; }
.side-toggle svg { transition: transform .15s; }
html[data-nav="min"] .side .lbl { display: none; }
html[data-nav="min"] .side-toggle svg { transform: rotate(180deg); }
.nav-scrim { display: none; }
body.has-rail main { margin-left: var(--side-w); }

/* ---- top header ---- */
header { background: var(--bg); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header .in { padding: 0 24px; display: flex; align-items: center; gap: 28px; height: 60px; }
header .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; color: var(--text);
  letter-spacing: -.01em; white-space: nowrap; flex: 1; }
header .brand:hover { text-decoration: none; }
.brand-mark { display: block; width: 28px; height: 28px; flex: none; }
.auth-brand .brand-mark { width: 34px; height: 34px; }
.hdr-right { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.hdr-right .me { font-size: 13px; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.hdr-theme { display: grid; place-items: center; padding: 6px; background: transparent; border: 0; color: var(--muted); cursor: pointer; }
.hdr-theme:hover { color: var(--text); }
.theme-toggle svg { width: 20px; height: 20px; }
.nav-open, .nav-burger { display: none; }

main { max-width: 1340px; margin: 0 auto; padding: 32px 24px 72px; }
h1 { font-size: 30px; line-height: 1.25; font-weight: 800; letter-spacing: -.015em; margin: 0 0 22px; }
h2 { font-size: 19px; line-height: 1.3; font-weight: 700; margin: 0 0 14px; }
h3 { font-size: 16px; font-weight: 700; margin: 18px 0 10px; }
p { margin: 0 0 12px; }
ul { padding-left: 20px; }
li { margin-bottom: 6px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
code { font: 13px/1.4 Consolas, "Cascadia Mono", monospace; background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }

/* ---- cards, stats ---- */
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid:not(:has(> .stat)) { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card { background: var(--panel); border-radius: 16px; padding: 22px 24px; box-shadow: var(--shadow); min-width: 0; }
[data-theme="light"] .card { border: 1px solid var(--line); }
.card + .grid, .card + .card { margin-top: 20px; }
#progress > .card { margin-bottom: 20px; }
.grid > .card, .lib > .card, .detail > .card { margin-top: 0; }
.stat { position: relative; overflow: hidden; }
.stat .n { font-size: 34px; line-height: 1.1; font-weight: 800; letter-spacing: -.02em; margin-bottom: 6px; }
.stat .l { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat::before { content: ""; position: absolute; left: 0; top: 22px; bottom: 22px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.grid > .stat:nth-child(2)::before { background: #ec8000; }
.grid > .stat:nth-child(3)::before { background: #25b770; }
.grid > .stat:nth-child(4)::before { background: #a970ff; }
.section { margin-top: 28px; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
tr:last-child > td { border-bottom: 0; }
tbody tr:hover > td, table > tr:hover > td { background: var(--hover); }
td:first-child, th:first-child { padding-left: 4px; }
table table { margin: 6px 0; }
table table td, table table th { padding: 5px 8px; }
/* "Việc đang chạy": ~10 dòng rồi cuộn trong khung; tiêu đề cột (nếu có) dính trên cùng */
.jobs-scroll { max-height: 520px; overflow-y: auto; overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.jobs-scroll th { position: sticky; top: 0; background: var(--panel); z-index: 1; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- badges (status tints) ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 5px; font-size: 12px; font-weight: 600; line-height: 18px;
  white-space: nowrap; vertical-align: 1px; background: var(--neutral-bg); color: var(--muted); }
.b-done, .b-ready { background: var(--ok-bg); color: var(--ok); }
.b-needs_review, .b-awaiting_approval, .b-awaiting_auth { background: var(--warn-bg); color: var(--warn); }
.b-failed { background: var(--err-bg); color: var(--err); }
.b-running { background: var(--run-bg); color: var(--run); }
.b-queued, .b-cancelled { background: var(--neutral-bg); color: var(--muted); }

/* ---- buttons, forms ---- */
form.inline { display: inline; }
button, .btn { font: inherit; font-weight: 600; font-size: 14px; border: 1px solid transparent; background: var(--panel-2);
  color: var(--text); padding: 8px 16px; border-radius: 8px; cursor: pointer; line-height: 1.4; transition: background .12s, border-color .12s; }
button:hover, .btn:hover { background: var(--hover); border-color: var(--line); text-decoration: none; }
[data-theme="light"] button, [data-theme="light"] .btn { border-color: var(--line); background: #fff; }
[data-theme="light"] button:hover, [data-theme="light"] .btn:hover { background: var(--panel-2); }
button.primary, .btn.primary, [data-theme="light"] button.primary, [data-theme="light"] .btn.primary {
  background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.outline, [data-theme="light"] button.outline { background: transparent; border-color: var(--primary); color: var(--accent); }
button.outline:hover { background: var(--accent-weak); }
button:disabled { opacity: .55; cursor: default; }
a.btn { text-decoration: none; display: inline-block; }
button.small, .btn.small { padding: 4px 11px; font-size: 13px; }
td button, td .btn { margin: 2px 0; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--input); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--accent-weak); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }
textarea { min-height: 96px; }
label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 180px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details > summary:hover { text-decoration: underline; }
details[open] > summary { margin-bottom: 8px; }

/* ---- messages ---- */
.msg { background: var(--accent-weak); border-left: 3px solid var(--primary); padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; }
.msg.err { background: var(--err-bg); border-left-color: var(--err); color: var(--text); }
.msg ul { margin: 8px 0 0; }
.err { color: var(--err); }
.save-note { margin-left: 8px; }

/* ---- library ---- */
.lib { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.lib .card { padding: 0; overflow: hidden; transition: transform .12s, box-shadow .12s; }
.lib .card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.lib img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--panel-2); }
.lib .body { padding: 14px 16px 16px; }
.lib .t { font-weight: 700; margin-bottom: 8px; line-height: 1.35; }
.lib .body .badge { margin: 0 4px 6px 0; }
.detail { display: grid; gap: 20px; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
video, .detail img { width: 100%; border-radius: 12px; background: #000; }
video { max-height: 70vh; object-fit: contain; }
.pub { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 10px; }
.issues li { margin-bottom: 6px; }
pre.desc { white-space: pre-wrap; font: inherit; margin: 0; }

/* ---- login / setup ---- */
.center { max-width: 400px; margin: 12vh auto; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.center button.primary { width: 100%; padding: 11px 16px; }

/* ---- progress ---- */
.bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: linear-gradient(90deg, var(--primary), #4b97ff); border-radius: 99px; }
.pbar progress { width: 160px; height: 8px; vertical-align: middle; margin-right: 8px; accent-color: var(--primary); }
progress { -webkit-appearance: none; appearance: none; border: 0; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--panel-2); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 99px; }

/* Channels page: an automatic mode that is ON gets a coloured row */
details.auto-row { margin-top: 6px; padding: 6px 10px; border-radius: 10px; border: 1px solid transparent; }
details.auto-row.on { background: var(--ok-bg); border-color: var(--ok); }
tr.chan-auto > td { background: var(--ok-bg); }            /* both automatic modes on: whole channel box */
tr.chan-auto details.auto-row.on { background: transparent; }
/* Collapsible channel rows: header line (double-click / chevron / Enter) opens the settings row below it.
   Without JS (no .chan-js on <html>) every settings row stays visible. */
tr[data-chan-head] { cursor: pointer; user-select: none; -webkit-user-select: none; }
tr[data-chan-head]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tr[data-chan-head]:hover > td { background: var(--hover); }
tr[data-chan-head] a { user-select: text; -webkit-user-select: text; }
.chan-chev { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1;
  padding: 4px 8px 4px 2px; margin: 0; vertical-align: middle; }
.chan-chev:hover { color: var(--accent); }
.chan-js tr[data-chan-body]:not(.open) { display: none; }
.chan-bar { margin: 6px 0; }

/* ---- responsive ---- */
@media (max-width: 1100px) {
  header .in { gap: 18px; }
  .hdr-right .me { display: none; }
}
@media (max-width: 860px) {
  .detail { grid-template-columns: 1fr; }
  body.has-rail main { margin-left: 0; }
  header .in { padding: 0 14px; gap: 12px; height: 56px; }
  .nav-burger { display: grid; gap: 4px; width: 36px; height: 36px; place-content: center; cursor: pointer; border-radius: 8px; margin: 0; }
  .nav-burger span { display: block; width: 20px; height: 2px; border-radius: 2px; background: var(--text); }
  header .brand { font-size: 18px; }
  .side { top: 56px; width: 260px; transform: translateX(-100%); transition: transform .18s; z-index: 7; box-shadow: 4px 0 24px rgba(0, 0, 0, .35); }
  html[data-nav="min"] .side .lbl { display: inline; }
  .side-toggle { display: none; }
  .nav-open:checked ~ .side { transform: none; }
  .nav-open:checked ~ .nav-scrim { display: block; position: fixed; inset: 56px 0 0 0; z-index: 6; background: rgba(0, 0, 0, .45); }
  main { padding: 22px 14px 56px; }
  h1 { font-size: 25px; margin-bottom: 16px; }
  .card { padding: 18px 16px; border-radius: 14px; }
  .grid, .grid:not(:has(> .stat)) { gap: 12px; grid-template-columns: 1fr; }
  .grid:has(> .stat) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h2 { font-size: 17px; }
  .stat .n { font-size: 28px; }
  .card table, .card > div > table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .row > * { min-width: 100%; }
  [style*="min-width:260px"] { min-width: 160px !important; }
}
.center h1 { font-size: 22px; margin: 6px 0 12px; }
[data-theme="light"] .theme-toggle, .theme-toggle { background: none; border: 0; }
.center { width: calc(100% - 28px); }
.center form p { margin-top: 20px; }
@media (max-width: 860px) { td select, td input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) { min-width: 120px; } }
