/* =====================================================================
   BETACOM CLOUD LIVE – giao diện điều khiển
   Phong cách: theo BETA HRM (Inter, chữ gốc 14px, card trắng bo 14px nổi trên nền xám,
   sidebar + thanh trên là khối nổi). Màu: tông Facebook Live – xanh #1877F2 cho thao tác,
   đỏ LIVE #E41E3F cho "đang phát", xám của Facebook cho nền/chữ. Mọi màu qua biến (sáng/tối dùng chung).
   ===================================================================== */
:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Chỉ cho tên file, đường dẫn, log, gợi ý key – số liệu dùng Inter (chữ số đều nhau). */
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  --r-xl: 14px;
  --r-lg: 12px;
  --r: 10px;
  --r-sm: 8px;
  --side: 220px;
  --ease: cubic-bezier(.2, .8, .2, 1);

  --fb: #1877f2;
  --fb-2: #166fe5;
  --live: #e41e3f;
  --green: #31a24c;
  --blue: #1877f2;
  --violet: #7c5cfc;
  --cyan: #0b9fb5;
  --red: #e41e3f;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --panel-3: #e4e6eb;
  --panel-3h: #d8dadf;
  --hover: #f2f3f5;
  --line: #e9ebee;
  --line-2: #ced0d4;
  --text: #1c1e21;
  --text-2: #65676b;
  --muted: #8a8d91;
  --input: #ffffff;
  --fb-tint: #e7f3ff;
  --fb-text: #1877f2;
  --amber: #c98a00;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 3px rgba(0, 0, 0, .03);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, .18), 0 2px 4px rgba(0, 0, 0, .08);
  --tint: .1;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #18191a;
  --panel: #242526;
  --panel-2: #2b2c2e;
  --panel-3: #3a3b3c;
  --panel-3h: #4e4f50;
  --hover: #303133;
  --line: #333436;
  --line-2: #3e4042;
  --text: #e4e6eb;
  --text-2: #b0b3b8;
  --muted: #8a8d91;
  --input: #3a3b3c;
  --fb-tint: rgba(45, 136, 255, .18);
  --fb-text: #4599ff;
  --amber: #f7b928;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, .5), 0 2px 4px rgba(0, 0, 0, .3);
  --tint: .18;
}

/* ---------------------------------------------------------------- nền tảng */
* { box-sizing: border-box; }
html { font-size: 14px; height: 100%; }
body {
  margin: 0; height: 100%; font-family: var(--font); font-size: 12.25px; line-height: 1.5;
  color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
::selection { background: color-mix(in srgb, var(--fb) 25%, transparent); }
h1, h2, h3 { color: var(--text); }
.num, .tnum { font-variant-numeric: tabular-nums; }
.num { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 11.5px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 11.5px; }
.xs { font-size: 10.5px; }
.hidden { display: none !important; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 260px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 6px; }
.gap-lg { gap: 14px; }
.mt { margin-top: 10px; }
.mt-lg { margin-top: 18px; }
svg.i { flex: none; display: block; }
.i.spin, .btn.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Màu nhấn: đặt --k, khối con (ic-box, biểu đồ…) tự lấy. */
.tone-red { --k: var(--live); }
.tone-green { --k: var(--green); }
.tone-amber { --k: var(--amber); }
.tone-blue { --k: var(--fb); }
.tone-violet { --k: var(--violet); }
.tone-cyan { --k: var(--cyan); }
.tone-grey { --k: var(--muted); }
.ic-box {
  width: 32px; height: 32px; border-radius: var(--r-sm); display: grid; place-items: center; flex: none;
  color: var(--k, var(--text-2)); background: color-mix(in srgb, var(--k, var(--muted)) 12%, transparent);
}
.ic-box.lg { width: 40px; height: 40px; border-radius: var(--r); }

/* ---------------------------------------------------------------- màn hình khởi động */
.boot-screen { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.boot-logo { width: 52px; height: 52px; border-radius: 12px; background: url('/logo.png') center/contain no-repeat; animation: breathe 1.6s var(--ease) infinite; }
@keyframes breathe { 50% { opacity: .5; } }
.boot-text { font-size: 12.25px; }

/* ---------------------------------------------------------------- khung (sidebar + thanh trên là khối nổi, chỉ vùng nội dung cuộn) */
.app { display: flex; gap: 12px; padding: 12px; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--side); flex: none; display: flex; flex-direction: column; height: 100%; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow);
  transition: width .2s var(--ease);
}
.app.nav-compact .sidebar { width: 64px; }
.brand { flex: none; display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; }
.brand-logo { width: 36px; height: 36px; display: grid; place-items: center; flex: none; }
.brand-logo-img { width: 36px; height: 36px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 800; font-size: 17.5px; line-height: 1.1; letter-spacing: .2px; color: var(--fb); }
.brand-sub { font-size: 10.5px; color: var(--muted); letter-spacing: 2px; font-weight: 600; margin-top: 2px; }
.brand-collapse-btn {
  width: 24px; height: 24px; margin-left: auto; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  background: transparent; border: none; color: var(--muted);
}
.brand-collapse-btn:hover { background: var(--hover); color: var(--text); }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px 8px; overflow-y: auto; }
.nav-label { font-size: 10.5px; font-weight: 500; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); padding: 12px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 8px; padding: 2px 10px 2px 2px; border-radius: var(--r-sm); text-decoration: none;
  color: var(--text); font-weight: 500; font-size: 12.25px; transition: background .15s, color .15s;
}
.nav a > svg { width: 32px; height: 32px; padding: 7px; color: var(--text-2); flex: none; }
.nav a:hover { background: var(--hover); }
.nav a.active { color: #fff; font-weight: 600; background: var(--fb); border-radius: 999px; box-shadow: 0 4px 12px -2px color-mix(in srgb, var(--fb) 45%, transparent); }
.nav a.active > svg { color: #fff; }
.nav .count {
  margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 600; font-variant-numeric: tabular-nums; background: var(--panel-3); color: var(--text-2);
}
.nav .count.live { background: var(--live); color: #fff; }
.nav a.active .count { background: rgba(255, 255, 255, .25); color: #fff; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.side-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; font-size: 11.5px; background: var(--panel-2); border-radius: var(--r); }
.side-card-ic { width: 30px; height: 30px; border-radius: var(--r-sm); display: grid; place-items: center; flex: none; background: var(--panel); color: var(--text-2); box-shadow: var(--shadow); }
.side-card.ok .side-card-ic { color: var(--green); }
.side-card.bad .side-card-ic { color: var(--red); }
.side-card.warn .side-card-ic { color: var(--amber); }
.side-card .t { font-weight: 600; font-size: 11.5px; }
.side-card .s { color: var(--muted); font-size: 10.5px; margin-top: 1px; display: flex; align-items: center; gap: 5px; }
.side-actions { display: flex; align-items: center; justify-content: space-between; padding: 0 2px; }
.side-collapse-btn { display: flex; align-items: center; gap: 8px; background: none; border: none; color: var(--text-2); font-size: 11.5px; font-weight: 500; cursor: pointer; padding: 4px 6px; border-radius: var(--r-sm); }
.side-collapse-btn:hover { background: var(--hover); color: var(--text); }

.app.nav-compact .brand { padding: 16px 0 10px; justify-content: center; }
.app.nav-compact .brand-text,
.app.nav-compact .nav-label,
.app.nav-compact .nav a span,
.app.nav-compact .nav .count,
.app.nav-compact .side-card .grow,
.app.nav-compact .side-collapse-btn span { display: none !important; }
.app.nav-compact .brand-collapse-btn { transform: rotate(180deg); margin-left: 0; }
.app.nav-compact .nav a { justify-content: center; padding: 2px 0; }
.app.nav-compact .side-card { justify-content: center; padding: 8px 0; }
.app.nav-compact .side-actions { flex-direction: column; gap: 4px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; overflow: hidden; }
.topbar {
  flex: none; height: 72px; display: flex; align-items: center; gap: 12px; padding: 0 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow);
}
.page-ic { width: 36px; height: 36px; border-radius: var(--r-sm); display: grid; place-items: center; flex: none; color: var(--fb); background: var(--fb-tint); }
.topbar h1 { font-size: 15.75px; margin: 0; font-weight: 600; line-height: 1.25; }
.topbar .sub { color: var(--text-2); font-size: 10.5px; margin-top: 2px; }
.topbar h1, .topbar .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .mode, .topbar .conn { white-space: nowrap; flex: none; }
.menu-btn {
  width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none;
  background: transparent; border: none; color: var(--text-2); cursor: pointer;
}
.menu-btn:hover { background: var(--hover); color: var(--text); }
.clock { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 500; font-size: 12.25px; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-2); }
.mode {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 999px;
  font-weight: 600; font-size: 10.5px; letter-spacing: .3px;
}
.mode.test { color: var(--fb-text); background: var(--fb-tint); }
.mode.real { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent); }
.banners { flex: none; display: flex; flex-direction: column; gap: 8px; }
.banners:empty { display: none; }
.view { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 12px; padding-bottom: 4px; animation: fadeIn .18s var(--ease); }
@keyframes fadeIn { from { opacity: 0; } }

/* ---------------------------------------------------------------- chấm trạng thái */
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; }
.dot.ok, .dot-ok { background: var(--green); }
.dot.bad, .dot-bad { background: var(--red); }
.dot.warn { background: var(--amber); }
.dot-live { width: 9px; height: 9px; border-radius: 50%; background: var(--live); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 20%, transparent); }

/* ---------------------------------------------------------------- nút (kiểu Facebook: chính = xanh, phụ = xám) */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: var(--r-sm); border: none; background: var(--panel-3); color: var(--text);
  font-weight: 600; font-size: 12.25px; cursor: pointer; white-space: nowrap; text-decoration: none; user-select: none;
  transition: background .15s, color .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: var(--panel-3h); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 11.5px; }
.btn.lg { height: 38px; padding: 0 16px; font-size: 13px; }
.btn.icon { width: 32px; padding: 0; }
.btn.icon.sm { width: 28px; }
.btn.primary { background: var(--fb); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--fb-2); }
.btn.danger { color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent); }
.btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--red) 17%, transparent); }
.btn.success { color: var(--green); background: color-mix(in srgb, var(--green) 11%, transparent); }
.btn.success:hover:not(:disabled) { background: color-mix(in srgb, var(--green) 18%, transparent); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn.busy { pointer-events: none; }

/* ---------------------------------------------------------------- card */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow); min-width: 0; overflow: hidden; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); min-height: 52px; }
.card-h h2, .card-h h3 { margin: 0; font-size: 13px; font-weight: 600; }
.card-h .sub { color: var(--muted); font-size: 10.5px; }
.card-h .h-ic { color: var(--text-2); display: grid; place-items: center; }
.card-b { padding: 14px 16px; }
.card-b.flush { padding: 0; }
.card-f { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.card-tabs { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.link-more {
  display: inline-flex; align-items: center; gap: 3px; height: 24px; padding: 0 10px; border-radius: 999px;
  color: var(--fb-text); text-decoration: none; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.link-more:hover { background: var(--fb-tint); }

/* ---------------------------------------------------------------- nhãn trạng thái (badge bo tròn, nền nhạt) */
.pill {
  --pc: var(--muted);
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; white-space: nowrap; color: var(--pc);
  background: color-mix(in srgb, var(--pc) calc(var(--tint) * 100%), transparent);
}
.pill.sm { height: 20px; padding: 0 8px; }
.pill .dot { width: 6px; height: 6px; background: currentColor; }
.pill.st-READY { --pc: var(--fb-text); }
.pill.st-SCHEDULED { --pc: var(--violet); }
.pill.st-STARTING, .pill.st-STOPPING, .pill.v-NEEDS_NORMALIZE { --pc: var(--amber); }
.pill.st-COMPLETED, .pill.v-READY { --pc: var(--green); }
.pill.st-FAILED, .pill.v-INVALID { --pc: var(--red); }
.pill.k-TEST { --pc: var(--cyan); }
.pill.k-REAL { --pc: var(--fb-text); }
/* Đang phát = huy hiệu LIVE của Facebook: nền đỏ đặc, chữ trắng. */
.pill.st-STREAMING { color: #fff; background: var(--live); letter-spacing: .2px; }
.pill.st-STREAMING .dot { background: #fff; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; border: none;
  background: var(--panel-3); color: var(--text); font-weight: 600; font-size: 11.5px; cursor: pointer; transition: background .15s, color .15s;
}
.chip:hover { background: var(--panel-3h); }
.chip.active { background: var(--fb-tint); color: var(--fb-text); }
.chip .n { font-size: 10.5px; padding: 0 6px; border-radius: 999px; background: var(--panel); color: var(--text-2); min-width: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.chip.active .n { color: var(--fb-text); }

.tag { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text-2); font-size: 10.5px; font-weight: 500; white-space: nowrap; }
.tag svg { opacity: .7; }

.av {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; font-size: 11.5px; color: #fff; background: hsl(var(--h) 55% 47%);
}
.av.sm { width: 30px; height: 30px; font-size: 10.5px; }
.av.lg { width: 42px; height: 42px; font-size: 13px; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who > div, .dest > div { min-width: 0; }
.who .n1, .dest .n1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .n2, .dest .n2 { color: var(--muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- tiến độ */
.bar { height: 6px; border-radius: 6px; background: var(--panel-3); overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--fb); transition: width .9s linear; }
.bar.lg { height: 8px; }
.bar.green > i { background: var(--green); }
.bar.amber > i { background: var(--amber); }
.bar.indeterminate > i { width: 35% !important; animation: indet 1.4s var(--ease) infinite; background: var(--amber); }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
.prog-cell { min-width: 170px; display: flex; flex-direction: column; gap: 6px; }
.prog-cell .pt { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--text-2); }

/* ---------------------------------------------------------------- bảng */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; }
table.t th {
  text-align: left; font-size: 11.5px; color: var(--text-2); font-weight: 500; padding: 0 14px; height: 40px; white-space: nowrap;
  border-bottom: 1px solid var(--line); background: var(--panel-2); position: sticky; top: 0;
}
table.t td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t th:first-child, table.t td:first-child { padding-left: 16px; }
table.t th:last-child, table.t td:last-child { padding-right: 16px; }
table.t tbody tr { transition: background .12s; }
table.t tbody tr:hover { background: var(--hover); }
table.t tbody tr:last-child td { border-bottom: none; }
.cell-id { font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.err-text { color: var(--red); font-size: 11.5px; }
.warn-text { color: var(--amber); }

/* 4 tín hiệu (components.js): s-ok = nhân sự đã xác nhận, s-send = FFmpeg đang gửi, s-conn/s-unk = đang kết nối/UNKNOWN, s-off = chưa chạy/đã dừng. */
.s-ok { --sc: var(--green); }
.s-send { --sc: var(--fb); }
.s-conn, .s-unk { --sc: var(--amber); }
.s-off { --sc: var(--muted); }
.signals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.sig { display: flex; align-items: center; gap: 9px; padding: 9px 11px; min-width: 0; border-radius: var(--r); background: var(--panel-2); border: 1px solid var(--line); }
.sig .si, .mini-sigs > span {
  display: grid; place-items: center; flex: none; color: var(--sc, var(--muted));
  background: color-mix(in srgb, var(--sc, var(--muted)) 13%, transparent);
}
.sig .si { width: 26px; height: 26px; border-radius: 50%; }
.sig > div:last-child { min-width: 0; }
.sig .sl { font-size: 10.5px; font-weight: 500; color: var(--muted); }
.sig .sv { font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sig.s-unk .sv { color: var(--amber); }
.mini-sigs { display: inline-flex; gap: 4px; }
.mini-sigs > span { width: 22px; height: 22px; border-radius: 50%; }

/* ---------------------------------------------------------------- thông báo, hộp */
.banner {
  --bc: var(--fb);
  display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-radius: var(--r-lg); font-size: 11.5px; color: var(--text-2);
  background: color-mix(in srgb, var(--bc) 9%, var(--panel)); border: 1px solid color-mix(in srgb, var(--bc) 25%, transparent);
}
.banner > svg { color: var(--bc); margin-top: 1px; }
.banner .b-t { font-weight: 600; font-size: 12.25px; color: var(--text); }
.banner.warn { --bc: var(--amber); }
.banner.err { --bc: var(--red); }
.box { border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--r); padding: 12px 14px; }
.box.warn { border-color: color-mix(in srgb, var(--amber) 30%, transparent); background: color-mix(in srgb, var(--amber) 8%, var(--panel)); }
.box.err { border-color: color-mix(in srgb, var(--red) 28%, transparent); background: color-mix(in srgb, var(--red) 6%, var(--panel)); }
.box.ok { border-color: color-mix(in srgb, var(--green) 28%, transparent); }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px 14px; font-size: 12.25px; }
.kv > .k { color: var(--muted); font-weight: 500; font-size: 11.5px; }
.kv > .v { min-width: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- form */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 11.5px; font-weight: 600; color: var(--text); }
.hint { font-size: 10.5px; color: var(--muted); }
.input {
  height: 36px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--input);
  width: 100%; outline: none; font-size: 12.25px; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 9px 12px; resize: vertical; }
.input::placeholder { color: var(--muted); }
.input:focus { border-color: var(--fb); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fb) 18%, transparent); }
.input:disabled { opacity: .6; }
.input.mono { font-family: var(--mono); font-size: 11.5px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 36px; height: 34px; width: 280px; border-radius: 999px; background: var(--panel-2); }
.search .input:focus { background: var(--input); }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-size: 12.25px; }
.check:hover { border-color: var(--line-2); }
.check input { width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--fb); flex: none; }
.check.on { border-color: color-mix(in srgb, var(--green) 40%, transparent); background: color-mix(in srgb, var(--green) 5%, var(--panel)); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.hidden { display: none; }
.form-grid .full { grid-column: 1 / -1; }
.input-group { display: flex; align-items: center; gap: 6px; }
.input-group .input { flex: 1; min-width: 0; }

/* ---------------------------------------------------------------- hộp thoại */
dialog.modal, dialog.drawer { color: var(--text); background: var(--panel); box-shadow: var(--shadow-lg); padding: 0; display: flex; flex-direction: column; }
dialog.modal { border: none; border-radius: var(--r-lg); overflow: hidden; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.modal.wide { width: min(1020px, calc(100vw - 32px)); }
dialog.modal.mid { width: min(720px, calc(100vw - 32px)); }
dialog.modal:not([open]), dialog.drawer:not([open]) { display: none; }
dialog.modal[open] { animation: pop .2s var(--ease); }
dialog::backdrop { background: rgba(0, 0, 0, .45); animation: fade .2s; }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
@keyframes fade { from { opacity: 0; } }
.m-h, .d-h { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.d-h { align-items: center; }
.m-ic { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; background: color-mix(in srgb, var(--tone, var(--fb)) 12%, transparent); color: var(--tone, var(--fb)); }
.m-h h3, .d-h h3 { margin: 0; font-size: 15.75px; font-weight: 700; }
.m-h .sub { color: var(--text-2); font-size: 11.5px; margin-top: 2px; }
.m-b { padding: 16px 20px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.m-f, .d-f { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.d-f { gap: 10px; justify-content: flex-start; }
dialog.drawer { margin: 12px 12px 12px auto; height: calc(100vh - 24px); max-height: calc(100vh - 24px); width: min(620px, calc(100vw - 24px)); border: none; border-radius: var(--r-xl); }
dialog.drawer[open] { animation: slideIn .22s var(--ease); }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } }
.d-b { padding: 16px 20px; overflow: auto; flex: 1; }

/* chi tiết phiên */
.tabs { display: inline-flex; gap: 4px; padding: 4px; align-self: flex-start; border-radius: var(--r); background: var(--panel-3); }
.tabs > button {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: 7px; border: none;
  background: none; color: var(--text-2); font-weight: 600; font-size: 11.5px; cursor: pointer;
}
.tabs > button:hover { color: var(--text); }
.tabs > button.on { color: var(--text); background: var(--panel); box-shadow: var(--shadow); }
.tabs .n { font-size: 10.5px; padding: 0 6px; border-radius: 999px; background: var(--panel-3); color: var(--text-2); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat { padding: 12px 14px; border-radius: var(--r); background: var(--panel-2); border: 1px solid var(--line); min-width: 0; }
.stat .sl { font-size: 10.5px; font-weight: 500; color: var(--muted); }
.stat .sv { font-size: 17.5px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Cột giờ rộng theo chuỗi dài nhất (subgrid ⇒ mọi hàng chung cột, chấm tròn không đè lên giờ). */
.timeline { display: grid; grid-template-columns: max-content 14px minmax(0, 1fr); column-gap: 12px; }
.tl { --lc: var(--fb); grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; align-items: start; padding: 7px 0; }
.tl.warn { --lc: var(--amber); }
.tl.error { --lc: var(--red); }
.tl .tt { font-size: 10.5px; color: var(--muted); white-space: nowrap; padding-top: 2px; font-variant-numeric: tabular-nums; }
.tl .td { position: relative; height: 100%; }
.tl .td::before { content: ""; position: absolute; left: 3px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--lc); }
.tl:not(:last-child) .td::after { content: ""; position: absolute; left: 6.5px; top: 17px; bottom: -17px; width: 1px; background: var(--line-2); }
.tl .tm { font-size: 12.25px; overflow-wrap: anywhere; }
.tl.warn .tm { color: var(--amber); }
.tl.error .tm { color: var(--red); }

/* tạo phiên */
.step { display: flex; flex-direction: column; gap: 12px; padding-bottom: 18px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: none; padding-bottom: 0; }
.step-h { display: flex; align-items: center; gap: 10px; }
.step-t { font-weight: 600; font-size: 13px; }
.step-n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 11.5px; background: var(--panel-3); color: var(--text-2); flex: none; }
.step-n.done { background: var(--green); color: #fff; }
.step-n.cur { background: var(--fb); color: #fff; }
.picks { display: flex; flex-direction: column; gap: 8px; }
.pick {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px 12px; text-align: left; cursor: pointer; color: var(--text);
  border-radius: var(--r); border: 1px solid var(--line-2); background: var(--panel); transition: border-color .15s, background .15s;
}
.pick:hover { background: var(--hover); }
.pick.on { border-color: var(--fb); background: var(--fb-tint); }
.pick .radio { width: 18px; height: 18px; border-radius: 50%; flex: none; border: 2px solid var(--line-2); background: var(--panel); }
.pick.on .radio { border: 5px solid var(--fb); }
.p-main { flex: 1; min-width: 0; }
.p-t { font-weight: 600; font-size: 12.25px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-t.mono { font-size: 11.5px; }
.p-s { font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: var(--r); background: var(--panel-3); }
.seg > button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; border-radius: 7px; border: none;
  background: none; color: var(--text-2); font-weight: 600; font-size: 12.25px; cursor: pointer;
}
.seg > button:hover { color: var(--text); }
.seg > button.on { color: var(--fb-text); background: var(--panel); box-shadow: var(--shadow); }
.seg > button:disabled { opacity: .45; cursor: not-allowed; }
ul.issues { margin: 0; padding-left: 18px; color: var(--amber); font-size: 11.5px; display: flex; flex-direction: column; gap: 3px; }

/* ---------------------------------------------------------------- toast */
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; min-width: 280px; max-width: 440px; padding: 12px 14px;
  border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--shadow-lg); font-size: 12.25px; animation: toastIn .22s var(--ease);
}
.toast.out { animation: toastOut .2s var(--ease) forwards; }
.toast .t-ic { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.toast.ok .t-ic { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.toast.error .t-ic { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.toast.warn .t-ic { background: color-mix(in srgb, var(--amber) 14%, transparent); color: var(--amber); }
.toast.info .t-ic { background: var(--fb-tint); color: var(--fb-text); }
.toast .t-t { font-weight: 600; }
.toast .t-m { color: var(--text-2); overflow-wrap: anywhere; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(16px); } }

/* ---------------------------------------------------------------- TỔNG QUAN */
.ov { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 12px; align-items: start; }
.ov > .kpis, .ov > .pipe-card, .ov > .ov-bot { grid-column: 1 / -1; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.kpi-l { font-size: 10.5px; font-weight: 500; color: var(--text-2); }
.kpi-b { display: flex; align-items: center; gap: 10px; }
.kpi-b .ic-box { width: 36px; height: 36px; }
.kpi-v { font-size: 21px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi-u { font-size: 12.25px; font-weight: 500; color: var(--muted); }
.kpi-f { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; min-height: 16px; }
.kpi-d { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.kpi-g { width: 84px; height: 28px; flex: none; color: var(--k); }
.kpi-g:empty { display: none; }
.kpi.is-bad .kpi-v { color: var(--red); }

.live-card { align-self: stretch; display: flex; flex-direction: column; }
.live-card .empty { flex: 1; }
.dest { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dest-ic { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; color: var(--k); background: color-mix(in srgb, var(--k) 13%, transparent); }

.perf-card .live-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--text-2); }
.perf-item { padding: 12px 14px; border-radius: var(--r-lg); background: var(--panel-2); display: flex; flex-direction: column; gap: 4px; }
.perf-item .ic-box { width: 28px; height: 28px; border-radius: 50%; }
.perf-h { display: flex; align-items: center; gap: 9px; }
.perf-l { font-size: 12.25px; font-weight: 600; }
.perf-v { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.perf-sub { font-size: 10.5px; color: var(--muted); }
.chart { display: grid; grid-template-columns: 28px minmax(0, 1fr); grid-template-rows: 72px auto; column-gap: 6px; margin-top: 4px; color: var(--k); }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; font-size: 9.5px; color: var(--muted); line-height: 1; font-variant-numeric: tabular-nums; }
.chart-u { grid-column: 2; font-size: 9.5px; color: var(--muted); text-align: right; margin-top: 3px; }
.chart-svg { width: 100%; height: 72px; display: block; overflow: visible; }
.chart-svg .grid line { stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-svg .area { stroke: none; }
.chart-svg .ln { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.kpi-g .chart-svg { height: 28px; }
.kpi-g .chart-svg .grid { display: none; }

.pipeline { display: flex; align-items: center; gap: 10px; padding: 16px; overflow-x: auto; }
.pl-step { flex: 1; min-width: 180px; display: flex; align-items: center; gap: 11px; }
.pl-step .ic-box { border-radius: 50%; }
.pl-txt { min-width: 0; flex: 1; }
.pl-t { font-weight: 600; font-size: 12.25px; }
.pl-s { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-st { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--panel-3); color: var(--muted); }
.pl-step[data-st="ok"] .pl-st { background: var(--green); color: #fff; }
.pl-step[data-st="wait"] .pl-st, .pl-step[data-st="unk"] .pl-st { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.pl-step[data-st="idle"] .ic-box { color: var(--muted); background: var(--panel-3); }
.pl-arrow { color: var(--line-2); flex: none; }
.pl-dash { width: 8px; height: 2px; border-radius: 2px; background: currentColor; }

.ov-bot { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.act-list { display: flex; flex-direction: column; }
.act-row {
  display: grid; grid-template-columns: 8px 86px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 9px 16px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .12s;
}
.act-row:last-child { border-bottom: none; }
.act-row:hover { background: var(--hover); }
.act-dot, .act-pill { --ac: var(--muted); }
.act-dot.live, .act-pill.live { --ac: var(--live); }
.act-dot.ok, .act-pill.ok { --ac: var(--green); }
.act-dot.info, .act-pill.info { --ac: var(--fb-text); }
.act-dot.bad, .act-pill.bad { --ac: var(--red); }
.act-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ac); }
.act-pill { justify-self: start; height: 20px; padding: 0 8px; border-radius: 999px; display: inline-flex; align-items: center; font-size: 10.5px; font-weight: 600; color: var(--ac); background: color-mix(in srgb, var(--ac) calc(var(--tint) * 100%), transparent); white-space: nowrap; }
.act-pill.live { color: #fff; background: var(--live); }
.act-main { min-width: 0; }
.act-t { font-weight: 600; font-size: 12.25px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-s { font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-time { font-size: 10.5px; color: var(--muted); }

/* ---------------------------------------------------------------- seller */
.grid { display: grid; gap: 12px; }
.grid.sellers { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.sys { grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); align-items: start; }
.seller-card { display: flex; flex-direction: column; }
.seller-card .sc-h { display: flex; gap: 12px; align-items: flex-start; padding: 16px 16px 10px; }
.seller-card .sc-b { padding: 0 16px 14px; display: flex; flex-direction: column; gap: 8px; font-size: 12.25px; }
.seller-card .sc-r { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; align-items: center; }
.seller-card .sc-r > span:first-child { color: var(--muted); font-size: 11.5px; font-weight: 500; }
.seller-card .sc-f { margin-top: auto; padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 6px; flex-wrap: wrap; }
.add-card {
  border: 1.5px dashed var(--line-2); border-radius: var(--r-xl); min-height: 220px; display: grid; place-content: center; justify-items: center;
  gap: 8px; color: var(--text-2); cursor: pointer; background: transparent; transition: color .15s, border-color .15s, background .15s;
}
.add-card:hover { color: var(--fb-text); border-color: var(--fb); background: var(--fb-tint); }
.add-card .e-ic { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-3); }

/* ---------------------------------------------------------------- video */
.split { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 12px; align-items: start; }
.side-list { display: flex; flex-direction: column; padding: 6px; gap: 2px; }
.side-list button { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: none; background: none; border-radius: var(--r-sm); text-align: left; cursor: pointer; color: var(--text); min-width: 0; }
.side-list button:hover { background: var(--hover); }
.side-list button.on { background: var(--fb-tint); }
.side-list button.on .sl-t { color: var(--fb-text); }
.side-list .sl-t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.25px; }
.side-list .sl-s { font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list { display: flex; flex-direction: column; }
.video-row { display: flex; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.video-row:last-child { border-bottom: none; }
.video-thumb { width: 42px; height: 42px; border-radius: var(--r); display: grid; place-items: center; flex: none; background: var(--panel-3); color: var(--text-2); }
.video-thumb.ready { background: color-mix(in srgb, var(--green) 12%, transparent); color: var(--green); }
.video-thumb.norm { background: color-mix(in srgb, var(--amber) 13%, transparent); color: var(--amber); }
.video-thumb.bad { background: color-mix(in srgb, var(--red) 11%, transparent); color: var(--red); }
.vr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.vr-t { font-weight: 600; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.vr-actions { display: flex; flex-direction: column; align-items: stretch; gap: 6px; flex: none; }
.specs { display: flex; gap: 5px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- trạng thái trống, linh tinh */
.empty { padding: 36px 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; color: var(--muted); }
.empty.sm { padding: 24px 20px; }
.empty .e-ic { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-3); color: var(--text-2); margin-bottom: 4px; }
.empty .e-t { color: var(--text); font-weight: 600; font-size: 13px; }
.empty .e-s { max-width: 420px; font-size: 11.5px; }
.howto { margin: 0; padding-left: 20px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; }
.howto b { color: var(--text); }
.copyline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.copyline code {
  font-family: var(--mono); font-size: 11.5px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text-2);
  padding: 5px 10px; border-radius: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
pre.code {
  margin: 0; background: var(--panel-2); color: var(--text-2); padding: 14px 16px; border-radius: var(--r); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.55; max-height: 380px; overflow: auto; white-space: pre-wrap; word-break: break-all;
}
.li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); min-width: 0; }
.li:last-child { border-bottom: none; }
.li-main { min-width: 0; flex: 1; }
.li-t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.25px; }
.li-s { color: var(--muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }

/* ---------------------------------------------------------------- màn hình cài đặt CSDL */
.setup { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 48px 20px 80px; gap: 16px; }
.setup-head { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.setup-head .brand-logo, .setup-head .brand-logo-img { width: 52px; height: 52px; }
.setup-head h1 { margin: 0; font-size: 21px; }
.setup-head p { margin: 0; color: var(--text-2); max-width: 580px; font-size: 12.25px; }
.setup-card { width: min(780px, 100%); }
.stepper { display: flex; gap: 10px; width: min(780px, 100%); }
.stepper .sp { flex: 1; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-weight: 600; font-size: 12.25px; }
.stepper .sp.cur { color: var(--text); border-color: var(--fb); }
.stepper .sp.done { color: var(--text-2); }
.stepper .sp.done .step-n { background: var(--green); color: #fff; }
.stepper .sp.cur .step-n { background: var(--fb); color: #fff; }

/* ---------------------------------------------------------------- màn hình hẹp */
@media (max-width: 1440px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1240px) {
  .ov { grid-template-columns: minmax(0, 1fr); }
  .ov-bot { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1100px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .grid.sys { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .app { padding: 0; gap: 0; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: auto; width: 260px; border-radius: 0; transform: translateX(-102%); transition: transform .25s var(--ease); box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; }
  .main { gap: 10px; }
  .topbar { height: 60px; border-radius: 0; border-width: 0 0 1px; padding: 0 12px; }
  .banners, .view { padding: 0 12px; }
  .view { padding-bottom: 24px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar .clock, .topbar .hide-sm, .card-h .hide-sm, .page-ic { display: none; }
  .search .input { width: 100%; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .signals, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .stepper { flex-direction: column; }
  .kv { grid-template-columns: minmax(0, 1fr); }
}
