/* Giao diện đơn giản: menu dọc, nội dung dạng danh sách từng dòng, một màu nhấn. */
:root {
  --page: #f4f6f7; --surface: #ffffff; --ink: #1b2430; --muted: #66717f; --line: #e3e7eb; --line-soft: #eef1f3;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #e6f2f1;
  --ok: #15803d; --ok-soft: #e8f5ec; --warn: #b45309; --warn-soft: #fdf3e3; --bad: #c62828; --bad-soft: #fdecec;
  --r: 10px;
  /* tương thích với tên biến cũ */
  --pri: var(--accent); --text: var(--ink); --card: var(--surface); --radius: var(--r);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--page); color: var(--ink); }
.hidden { display: none !important; }
h1, h2, h3 { line-height: 1.25; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- nút & ô nhập ---------- */
button, .btn {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; border-radius: 8px; padding: 8px 14px; white-space: nowrap;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
button.ghost:hover { background: var(--page); filter: none; }
button.danger { color: var(--bad); }
button.ghost.danger:hover { background: var(--bad-soft); }
button.sm { padding: 5px 10px; font-size: 13px; }
a.btn.ghost-link { background: var(--surface); color: var(--ink); border-color: var(--line); text-decoration: none; justify-content: flex-start; }
a.btn.ghost-link:hover { background: var(--page); filter: none; }
input, select { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; width: 100%; background: var(--surface); color: var(--ink); }
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { background: var(--page); color: var(--muted); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
label > input, label > select { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
label.check input { width: auto; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 13px; }
.err { color: var(--bad); min-height: 1em; }
.empty { color: var(--muted); padding: 28px 16px; text-align: center; }
code { background: var(--page); padding: 1px 5px; border-radius: 4px; }

/* ---------- đăng nhập ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { background: var(--surface); padding: 32px; border-radius: 14px; width: 100%; max-width: 380px; border: 1px solid var(--line); }
.login h1 { font-size: 24px; margin: 0 0 4px; }
.login p.muted { margin: 0 0 12px; }
.login button { width: 100%; justify-content: center; margin-top: 18px; padding: 11px; font-size: 15px; }

/* ---------- khung: menu dọc + nội dung ---------- */
#app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
.brand-mark { width: 22px; height: 16px; border: 3px solid var(--accent); border-radius: 4px; position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; left: 4px; right: 4px; bottom: -8px; height: 3px; background: var(--accent); border-radius: 2px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav button { background: transparent; color: var(--ink); border: 0; font-weight: 500; font-size: 15px; padding: 10px 12px; justify-content: flex-start; gap: 12px; border-radius: 8px; }
.side nav button:hover { background: var(--page); filter: none; }
.side nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.side nav svg, .top svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.main-wrap { min-width: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 6; }
.top .sp { flex: 1; }
.branch-filter { width: auto; min-width: 200px; font-weight: 600; }
.bell { position: relative; background: transparent; color: var(--ink); border: 1px solid var(--line); padding: 7px 9px; }
.bell:hover { background: var(--page); filter: none; }
.bell-count { position: absolute; top: -6px; right: -6px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 6px; min-width: 20px; text-align: center; }
.user-btn { background: transparent; color: var(--ink); border: 1px solid var(--line); font-weight: 600; }
.user-btn:hover { background: var(--page); filter: none; }
main { padding: 24px 28px 48px; max-width: 1240px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; font-size: 22px; }
.toolbar .btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .btns select { width: auto; }

/* ---------- ô tổng quan: 1 hàng số gọn ---------- */
.stats { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 20px; overflow: hidden; flex-wrap: wrap; }
.stat { flex: 1 1 150px; padding: 14px 18px; border-right: 1px solid var(--line-soft); display: flex; flex-direction: column; }
.stat:last-child { border-right: 0; }
.stat b { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat b small { font-size: 15px; color: var(--muted); font-weight: 600; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.ok b { color: var(--ok); } .stat.run b { color: var(--warn); } .stat.bad b { color: var(--bad); }

/* ---------- chi nhánh / phòng máy ---------- */
.branch { margin-bottom: 28px; }
.branch-h { font-size: 18px; margin: 0 0 12px; }
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 16px; overflow: hidden; }
.group-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.group-h h3 { margin: 0; font-size: 16px; }
.group-h .sp { flex: 1; }
.group-h select { width: auto; max-width: 260px; padding: 6px 8px; font-size: 13px; }
.group-h label { display: flex; align-items: center; gap: 8px; }
.pill { font-size: 13px; color: var(--muted); }
.pill.ok { color: var(--ok); font-weight: 600; }
.pill + .pill::before { content: "|"; color: var(--line); margin-right: 10px; }

/* danh sách màn hình: mỗi màn hình 1 dòng */
.list-head, .card { display: grid; grid-template-columns: minmax(180px, 1.1fr) minmax(220px, 1.5fr) 210px 250px; gap: 16px; align-items: center; padding: 12px 16px; }
.list-head { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; border-bottom: 1px solid var(--line-soft); padding-top: 8px; padding-bottom: 8px; }
.card { border-bottom: 1px solid var(--line-soft); }
.card:last-child { border-bottom: 0; }
.card:hover { background: #fafbfc; }
.c-name { display: flex; gap: 10px; align-items: flex-start; min-width: 0; }
.c-name b { font-size: 15px; }
.c-name .small, .c-play .small { overflow: hidden; text-overflow: ellipsis; }
.c-play { min-width: 0; }
.c-play .now { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-play .off-text { color: var(--bad); font-weight: 600; }
.c-act { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); flex: none; margin-top: 6px; display: inline-block; }
.dot.on { background: var(--ok); }
.sync { font-size: 13px; padding: 4px 10px; border-radius: 6px; background: var(--page); color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.sync.ok { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.sync.run { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.sync.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.sync .bar { height: 4px; background: #f6dfb8; }
.sync .bar i { background: var(--warn); }
.card .err { font-size: 13px; }
.upd { font-size: 12px; color: var(--accent); margin-top: 4px; }
.upd.warn { color: var(--warn); }

/* ---------- thư viện: mỗi tệp 1 dòng ---------- */
.drop { border: 2px dashed var(--line); border-radius: var(--r); padding: 18px; text-align: center; color: var(--muted); margin-bottom: 16px; background: var(--surface); }
.drop.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.upl { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.bar { flex: 1; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.mgrid { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.mcard { display: grid; grid-template-columns: 96px 1fr auto; gap: 16px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.mcard:last-child { border-bottom: 0; }
.mcard:hover { background: #fafbfc; }
.mcard .actions { margin: 0; justify-content: flex-end; }
.m-info { min-width: 0; }
.mname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.th { position: relative; aspect-ratio: 16/9; background: #1b2430; border-radius: 6px; overflow: hidden; }
.th img, .th video { width: 100%; height: 100%; object-fit: cover; display: block; }
.th .badge { position: absolute; left: 4px; bottom: 4px; background: #000a; color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 4px; }
/* lưới chọn ảnh trong hộp thoại */
#pick.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; border: 0; background: transparent; }
#pick .mcard { display: flex; flex-direction: column; gap: 4px; align-items: stretch; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
#pick .mcard.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); background: var(--accent-soft); }

/* ---------- danh sách phát ---------- */
.split { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.pl-list { background: var(--surface); border-radius: var(--r); border: 1px solid var(--line); overflow: hidden; }
.pl-item { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.pl-item:last-child { border-bottom: 0; }
.pl-item:hover { background: #fafbfc; }
.pl-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.pl-edit { background: var(--surface); border-radius: var(--r); border: 1px solid var(--line); padding: 18px; }
.items { display: flex; flex-direction: column; margin: 14px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.it { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); }
.it:last-child { border-bottom: 0; }
.it .num { width: 22px; text-align: center; color: var(--muted); font-weight: 700; }
.it .th { width: 88px; flex: none; }
.it-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.it .dur { margin: 0; width: 130px; }
.it .dur input { padding: 6px 8px; }
.it-act { display: flex; gap: 4px; }
.items .empty { padding: 18px; }

/* ---------- chung ---------- */
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; align-items: center; }
.actions.right { justify-content: flex-end; }
.actions .sp { flex: 1; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--page); border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.tag.admin { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.tag.fail { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 10px; font-size: 16px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 170px; margin-top: 0; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; background: #fafbfc; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .dot { margin-top: 0; }
.scroll { max-height: 60vh; overflow: auto; }
.note { background: var(--warn-soft); color: #7c3d06; border-radius: 8px; padding: 10px 12px; font-size: 14px; }

/* hướng màn hình */
.rot { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rot-opt { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0; cursor: pointer; color: var(--ink); font-size: 14px; }
.rot-opt input { width: auto; }
.rot-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.rot-ic { width: 30px; height: 19px; border: 2px solid currentColor; border-radius: 3px; position: relative; flex: none; }
.rot-ic::after { content: ""; position: absolute; width: 6px; height: 6px; background: var(--accent); border-radius: 50%; top: 2px; left: 2px; }
.rot-ic.r90, .rot-ic.r270 { width: 19px; height: 30px; }
.rot-ic.r90::after { left: auto; right: 2px; }
.rot-ic.r180::after { top: auto; left: auto; bottom: 2px; right: 2px; }
.rot-ic.r270::after { top: auto; bottom: 2px; }

/* phát ngay */
.pub-media { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.pub-m { width: 140px; display: flex; flex-direction: column; gap: 4px; }
.pub-m span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pub-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }
.pub-room { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; flex-wrap: wrap; }
.pub-room:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pub-room .muted { margin-left: auto; }
.pub-more { margin-top: 8px; font-size: 14px; }
.pub-more summary { cursor: pointer; color: var(--accent); }

/* thống kê */
.chart { width: 100%; height: auto; max-height: 240px; display: block; }
.chart .bar-fill { fill: var(--accent); }
.chart .bar-val { font-size: 11px; fill: var(--ink); font-weight: 600; }
.chart .bar-lbl { font-size: 11px; fill: var(--muted); }
.chart .axis { stroke: var(--line); }
.split2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.upbar { display: inline-block; width: 90px; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.upbar i { display: block; height: 100%; background: var(--ok); }
.upbar.run i { background: var(--warn); } .upbar.bad i { background: var(--bad); }
.qr2fa { width: 200px; height: 200px; background: #fff; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }

/* thông báo */
.notif-panel { position: fixed; top: 60px; right: 16px; width: min(420px, calc(100vw - 24px)); max-height: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(27, 36, 48, .14); z-index: 15; }
.np-h { display: flex; align-items: center; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); flex-wrap: wrap; }
.np-h .sp { flex: 1; }
.np-tip { padding: 8px 14px; margin: 0; background: var(--warn-soft); }
.np-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.np-item.unread { background: #f3f8f8; }
.np-item.lv-critical.unread { background: var(--bad-soft); }
.np-ic { font-size: 16px; }

/* hộp thoại + báo nhanh */
.modal { position: fixed; inset: 0; background: rgba(27, 36, 48, .45); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 14px; padding: 22px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; }
.modal-box.wide { max-width: 880px; }
.modal-box h3 { margin: 0 0 6px; font-size: 18px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(16px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; transition: transform .2s, opacity .2s; z-index: 30; max-width: 90vw; opacity: 0; visibility: hidden; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
.toast.err { background: var(--bad); }

body:not(.is-admin) .admin-only { display: none !important; }
body:not(.is-manager) .manager-only { display: none !important; }

/* ---------- màn hình nhỏ: menu chuyển xuống dưới, dòng xếp chồng ---------- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; padding: 4px; border-right: 0; border-top: 1px solid var(--line); z-index: 10; }
  .brand { display: none; }
  .side nav { flex-direction: row; justify-content: space-around; }
  .side nav button { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; }
  .top { padding: 10px 14px; }
  .branch-filter { min-width: 0; max-width: 55vw; }
  main { padding: 16px 14px 90px; }
  .list-head { display: none; }
  .card { grid-template-columns: 1fr; gap: 8px; }
  .c-act { justify-content: flex-start; }
  .mcard { grid-template-columns: 80px 1fr; }
  .mcard .actions { grid-column: 1 / -1; justify-content: flex-start; }
  .split, .split2 { grid-template-columns: 1fr; }
  .it { flex-wrap: wrap; }
  .rot { grid-template-columns: 1fr; }
  .stat { flex-basis: 45%; border-bottom: 1px solid var(--line-soft); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ghép nối: ô mã + nút quét QR */
.pair-code { display: flex; gap: 10px; align-items: end; }
.pair-code label { flex: 1; margin-bottom: 0; }
.pair-code input { font-size: 22px; letter-spacing: 4px; }
.scan-btn { height: 46px; }
.scan-box { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; text-align: center; }
.scan-box video { width: 100%; max-height: 300px; border-radius: 6px; background: #000; object-fit: cover; }
#pairInfo .note { display: block; margin-top: 8px; }

/* ---- Trang Quản trị: chia mục ---- */
.subnav { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.subnav button { background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 14px; font-weight: 600; font-size: 14px; margin-bottom: -1px; }
.subnav button:hover { color: var(--ink); filter: none; }
.subnav button.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-h { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tbl td.acts { text-align: right; white-space: nowrap; }
.tbl td.acts button + button { margin-left: 6px; }
.nowrap { white-space: nowrap; }
.st { display: inline-block; font-weight: 600; font-size: 13px; }
.st.ok { color: var(--accent); }
.st.off { color: var(--muted); }
.links { display: grid; gap: 10px; }
.links > div { display: flex; flex-direction: column; gap: 2px; }
.links code, .links a { font-size: 14px; word-break: break-all; }
.roles { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 16px 0 0; font-size: 13px; }
.roles dt { font-weight: 600; }
.roles dd { margin: 0; color: var(--muted); }
@media (max-width: 760px) {
  .subnav { flex-wrap: nowrap; overflow-x: auto; }
  .subnav button { white-space: nowrap; }
  .roles { grid-template-columns: 1fr; }
  .roles dd { margin-bottom: 6px; }
}
.warn-s { display: block; color: var(--warn); font-size: 12px; font-weight: 600; margin-top: 2px; }

/* ---- Giờ bật / tắt màn hình ---- */
.pw { margin-top: 4px; }
.pw.off { color: var(--warn); font-weight: 600; }
.sch-t { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.sch-t input[type=time] { width: 120px; }
.sch-t.dim { opacity: .45; pointer-events: none; }
input[type=time] { font: inherit; }

/* ---- Lịch chiến dịch theo khung giờ ---- */
.dp { display: grid; gap: 8px; margin-bottom: 8px; }
.dp-row { display: grid; grid-template-columns: 120px auto 120px 1fr auto; gap: 8px; align-items: center; }
.dp-row input[type=time] { width: 100%; }
.slot { display: inline-block; background: var(--accent-soft, #e6f2f1); color: var(--accent); border-radius: 6px; padding: 0 6px; font-weight: 600; }
@media (max-width: 760px) { .dp-row { grid-template-columns: 1fr auto 1fr; } .dp-row select { grid-column: 1 / -1; } }

/* ---- Chiến dịch toàn thời gian ---- */
.pin-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 16px; background: #fff7ed; border-bottom: 1px solid #fed7aa; font-size: 14px; }
.pin-s { color: #c2410c; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.pin-opt { align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }

/* ---- Ngày chạy chiến dịch ---- */
.camp { display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 1px 8px; }
.camp.run { background: #dcfce7; color: #166534; }
.camp.wait { background: #e0f2fe; color: #075985; }
.camp.done { background: #f1f5f9; color: #64748b; }
