/* Bố cục: chế độ Quản lý (xem trước TV + bảng điều khiển) và chế độ TV toàn màn hình, chọn bằng #quan-ly / #man-hinh */
:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --ink: #13211e;
  --muted: #56675f;
  --line: #d8e2de;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #dff1ee;
  --warn: #9a3412;
  --good: #166534;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1513; --surface: #151f1c; --ink: #e6f0ed; --muted: #95a8a1; --line: #26342f;
    --accent: #2dd4bf; --accent-ink: #04201c; --accent-soft: #123430; --warn: #fdba74; --good: #86efac;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1513; --surface: #151f1c; --ink: #e6f0ed; --muted: #95a8a1; --line: #26342f;
  --accent: #2dd4bf; --accent-ink: #04201c; --accent-soft: #123430; --warn: #fdba74; --good: #86efac;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; }
body.is-tv { background: #000; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

.page { max-width: 1280px; margin: 0 auto; padding: 20px 16px 40px; display: grid; gap: 20px; }
header { display: grid; gap: 6px; }
header .top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
header h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; text-wrap: balance; }
header p { margin: 0; color: var(--muted); max-width: 75ch; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 600; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.ok::before { background: var(--good); }
.chip.bad::before { background: var(--warn); }

.layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1000px) { .layout { grid-template-columns: minmax(0, 1.5fr) minmax(360px, 1fr); } }

/* ---------- Bảng TV (dùng chung cho xem trước và chế độ TV) ---------- */
.tv {
  --tv-bg: #0a1c19; --tv-panel: #11302b; --tv-ink: #f1faf7; --tv-dim: #84a9a0; --tv-ready: #fbbf24; --tv-ready-ink: #1d1400; --tv-flash: #fff3c4;
  --u: 6px; width: 100%; /* --u = 1% be ngang bang, app.js tinh (trinh duyet cu tren box khong hieu cqw) */
  background: var(--tv-bg); color: var(--tv-ink);
  border-radius: 14px; border: 1px solid var(--line); overflow: hidden;
  display: grid; grid-template-rows: auto 1fr;
}
.tv[data-theme="sang"] { --tv-bg: #f7f9f8; --tv-panel: #e1ebe8; --tv-ink: #12231f; --tv-dim: #5b7068; --tv-ready: #0f766e; --tv-ready-ink: #ffffff; --tv-flash: #14b8a6; }
.tv[data-theme="cam"] { --tv-bg: #1c1210; --tv-panel: #2c1d18; --tv-ink: #fff3ee; --tv-dim: #c7a496; --tv-ready: #f97316; --tv-ready-ink: #1f0d03; --tv-flash: #fdba74; }
.tv-head { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--u) * 2.2) calc(var(--u) * 3); background: var(--tv-panel); font-size: calc(var(--u) * 2.4); font-weight: 700; }
.tv-head span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-head span:last-child { color: var(--tv-dim); font-weight: 500; white-space: nowrap; }
.tv-body { display: grid; grid-template-columns: 1fr 2.1fr; min-height: 0; }
.tv-col { padding: calc(var(--u) * 2.4) calc(var(--u) * 3); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tv-col + .tv-col { border-left: calc(var(--u) * 0.25) solid var(--tv-panel); }
.tv-title { margin: 0; font-size: calc(var(--u) * 2); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--tv-dim); }
.tv-title.ready { color: var(--tv-ready); }
.prep-grid { display: grid; grid-template-columns: repeat(2, 1fr); grid-gap: calc(var(--u) * 1.2); gap: calc(var(--u) * 1.2); align-content: start; }
.prep-num { background: var(--tv-panel); border-radius: calc(var(--u) * 1); text-align: center; font-size: calc(var(--u) * 4); font-weight: 700; padding: calc(var(--u) * 0.8) 0; font-variant-numeric: tabular-nums; }
.prep-more { grid-column: 1 / -1; text-align: center; color: var(--tv-dim); font-size: calc(var(--u) * 2); }
.ready-main { background: var(--tv-ready); color: var(--tv-ready-ink); border-radius: calc(var(--u) * 1.6); text-align: center; padding: calc(var(--u) * 1.2) 0 calc(var(--u) * 1.6); }
.ready-main .lbl { font-size: calc(var(--u) * 2); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.ready-main .num { font-size: calc(var(--u) * 15); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.ready-main.flash { animation: flash 0.7s ease-in-out 4; }
@keyframes flash { 50% { background: var(--tv-flash); transform: scale(1.015); } }
@media (prefers-reduced-motion: reduce) { .ready-main.flash { animation: none; } }
.ready-grid { display: grid; grid-template-columns: repeat(4, 1fr); grid-gap: calc(var(--u) * 1.2); gap: calc(var(--u) * 1.2); margin-top: calc(var(--u) * 1.6); }
.ready-num { border: calc(var(--u) * 0.3) solid var(--tv-ready); color: var(--tv-ready); border-radius: calc(var(--u) * 1); text-align: center; font-size: calc(var(--u) * 4.2); font-weight: 700; padding: calc(var(--u) * 0.6) 0; font-variant-numeric: tabular-nums; }
.tv-empty { color: var(--tv-dim); font-size: calc(var(--u) * 2.4); margin: auto 0; text-align: center; }

/* ---------- Chế độ quản lý ---------- */
.tv-wrap { display: grid; gap: 10px; }
.tv-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tv-bar h2 { margin: 0; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; display: grid; }
.sec { padding: 16px; display: grid; gap: 12px; }
.sec + .sec { border-top: 1px solid var(--line); }
.sec h2 { margin: 0; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sec h2 .count { font-variant-numeric: tabular-nums; color: var(--ink); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { min-height: 40px; padding: 0 14px; border-radius: 10px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); font-weight: 600; display: inline-flex; align-items: center; text-decoration: none; }
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.item.screen { grid-template-columns: minmax(0, 1fr) auto; }
.item .n { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.item .it { color: var(--muted); font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.item .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.empty { color: var(--muted); font-size: 14px; margin: 0; }
.field { display: flex; gap: 8px; }
.field input[type="text"], .field input[type="number"], .field select { min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); min-width: 0; flex: 1; }
.opt { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.opt input[type="checkbox"], .opt input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); }
.opt select { min-height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); padding: 0 8px; }
.themes { display: flex; gap: 14px; flex-wrap: wrap; }
.note { margin: 0; font-size: 13px; color: var(--muted); }
.note.warn { color: var(--warn); }
.note.good { color: var(--good); }
.steps { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; display: grid; gap: 4px; }

.tv-head .b-brand { display: flex; align-items: center; min-width: 0; overflow: hidden; margin-right: calc(var(--u) * 2); }
.tv-head .b-store { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tv-ink); font-weight: 700; }
.b-logo { height: calc(var(--u) * 5); max-width: calc(var(--u) * 16); object-fit: contain; margin: calc(var(--u) * -1) 0; }
.lab { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.lab input[type="text"], .lab select { min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 15px; width: 100%; min-width: 0; }
.lab input[type="file"] { color: var(--ink); min-width: 0; }
summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.more { display: grid; gap: 10px; padding-top: 10px; }

/* ---------- Chế độ TV ---------- */
#tvMode { height: 100%; position: relative; background: #000; color: #f1faf7; }
.tv-stage { height: 100%; display: flex; align-items: center; justify-content: center; background: #000; }
.tv-stage .tv { flex: none; border-radius: 0; border: 0; }
.pair { height: 100%; display: grid; place-content: center; text-align: center; grid-gap: 16px; gap: 16px; padding: 24px; background: #0a1c19; }
.pair h1 { margin: 0; font-size: 3.4vmin; font-size: clamp(20px, 3.4vmin, 40px); font-weight: 700; color: #84a9a0; }
.pair .code { font-size: 20vmin; font-size: clamp(56px, 20vmin, 220px); font-weight: 800; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; line-height: 1; }
.pair p { margin: 0 auto; font-size: 2.4vmin; font-size: clamp(14px, 2.4vmin, 26px); color: #cfe3dd; max-width: 40ch; }
.tv-typing { position: fixed; left: 12px; bottom: 12px; max-width: 70vw; padding: 10px 18px; border-radius: 12px; background: rgba(0, 0, 0, 0.88); border: 2px solid #84a9a0; font-size: 4.5vmin; font-size: clamp(18px, 4.5vmin, 48px); font-weight: 800; font-variant-numeric: tabular-nums; z-index: 5; }
.tv-typing[hidden] { display: none; }
.tv-ctl { position: fixed; right: 12px; bottom: 12px; display: flex; opacity: 0.75; }
.tv-ctl > * { margin-left: 8px; }
.tv-ctl:hover, .tv-ctl:focus-within { opacity: 1; }
.tv-ctl .btn { background: rgba(0, 0, 0, 0.7); color: #f1faf7; border-color: #3a5a53; }
.tv-ctl .btn:hover { background: #11302b; }
.card{max-width:380px;margin:40px auto;padding:20px;display:grid;gap:12px;background:var(--surface);border:1px solid var(--line);border-radius:14px}
.card h1{margin:0;font-size:22px}
.field input[type=password],.card input{min-height:44px;padding:0 12px;border-radius:10px;border:1px solid var(--line);background:var(--bg);min-width:0;width:100%}
.tv-col > * + * { margin-top: calc(var(--u) * 1.6); }
.b-logo { margin-right: calc(var(--u) * 1.6); }
