:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #dfe3ea;
  --primary: #1f5eff;
  --ok: #157a3c;
  --ok-bg: #e7f6ec;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --warn: #9a6700;
  --warn-bg: #fff6db;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.topbar { background: #101828; color: #fff; padding: 14px 24px; }
.brand { font-weight: 700; font-size: 17px; }
.sub { color: #98a2b3; font-size: 13px; margin-top: 2px; }
.layout { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; padding: 16px; max-width: 1280px; margin: 0 auto; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-width: 0; }
h2 { font-size: 15px; margin: 0; }
select, input { font: inherit; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; width: 100%; }
.ocr-form { display: grid; gap: 8px; }
.ocr-form label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.ocr-form label.key input { border-color: #9db6ff; background: #f5f8ff; }
.recipe-info { margin-top: 12px; padding: 10px; border-radius: 6px; font-size: 13px; }
.recipe-info.has { background: var(--ok-bg); color: var(--ok); }
.recipe-info.none { background: var(--warn-bg); color: var(--warn); }
.muted { color: var(--muted); margin: 0 0 12px; line-height: 1.5; }
button.primary { background: var(--primary); color: #fff; border: 0; border-radius: 6px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; }
button.primary:disabled { opacity: .5; cursor: default; }
.status-line { margin: 12px 0 6px; font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef2f6; }
.badge.done { background: var(--ok-bg); color: var(--ok); }
.badge.error, .badge.need_recipe { background: var(--bad-bg); color: var(--bad); }
.badge.need_captcha { background: var(--warn-bg); color: var(--warn); }
.events { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.events .t { color: #98a2b3; font-variant-numeric: tabular-nums; margin-right: 6px; }
.result-head { margin: 14px 0 8px; padding: 10px 12px; border-radius: 6px; font-weight: 600; }
.result-head.valid { background: var(--ok-bg); color: var(--ok); }
.result-head.invalid, .result-head.error { background: var(--bad-bg); color: var(--bad); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.m-true { color: var(--ok); font-weight: 700; }
td.m-false { color: var(--bad); font-weight: 700; }
td.m-null { color: var(--muted); }
tr.row-false { background: var(--bad-bg); }
.summary { margin: 8px 0; color: var(--muted); }
details { margin-top: 12px; }
details img { max-width: 100%; border: 1px solid var(--border); border-radius: 6px; margin-top: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
button.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 9px 14px; font: inherit; cursor: pointer; }
button.secondary:disabled { opacity: .5; cursor: default; }
.rec { margin-top: 14px; border: 1px dashed #9db6ff; border-radius: 8px; padding: 12px; background: #f8faff; }
.rec h3 { margin: 0 0 8px; font-size: 14px; }
.rec h4 { margin: 14px 0 6px; font-size: 13px; }
.rec .note { color: var(--muted); font-size: 13px; margin: 0 0 8px; line-height: 1.5; }
.rec table td { white-space: normal; vertical-align: middle; }
.rec select, .rec input[type=text] { padding: 5px 7px; }
.rec code { font-size: 12px; background: #eef2f6; padding: 1px 4px; border-radius: 4px; word-break: break-all; }
.rec .warn { color: var(--bad); font-size: 13px; }
.rec .ok { color: var(--ok); font-weight: 600; }
.modal { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 10px; padding: 20px; width: 100%; max-width: 360px; display: grid; gap: 10px; }
.modal-box h3 { margin: 0; }
.modal-box img { justify-self: center; border: 1px solid var(--border); border-radius: 4px; min-height: 40px; }
/* ---- Bản QA ---- */
h3 { font-size: 14px; margin: 0 0 6px; }
.mt { margin-top: 18px; }
.mt-s { margin-top: 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 8px; line-height: 1.5; }
.light { font-weight: 400; opacity: .8; }
.config-warn { max-width: 1280px; margin: 16px auto 0; padding: 10px 14px; border-radius: 8px; background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.config-warn[hidden] { display: none; }
.upload { display: grid; gap: 6px; margin-top: 10px; }
.upload input[type=file] { background: #fafbfc; }
.upload button { justify-self: start; }
button.small { padding: 5px 10px; font-size: 13px; }
button.danger { color: var(--bad); border-color: #f3b8b2; }
.recipe-info[hidden] { display: none; }
.files { margin: 6px 0 4px; }
.files a { color: var(--primary); font-weight: 600; }
.warn { color: var(--bad); font-size: 13px; }
.need-recipe { margin-top: 14px; padding: 12px 14px; border-radius: 8px; background: var(--warn-bg); color: #5c4400; line-height: 1.55; }
.need-recipe p { margin: 6px 0; }
.need-recipe ol { margin: 6px 0 12px; padding-left: 20px; }
.need-recipe code { background: #fff; padding: 1px 5px; border-radius: 4px; }
.badge.running, .badge.recording { background: #e8efff; color: var(--primary); }
.files ul { margin: 4px 0 0; padding-left: 18px; }
.files li { margin: 2px 0; }
.files li.in-zip { margin-left: 18px; list-style: circle; }
.badge.xml, .badge.pdf, .badge.zip, .badge.any { background: #eef2f7; color: #334155; font-size: 11px; padding: 1px 6px; }
.tag { display: inline-block; background: #f3e8ff; color: #7c3aed; border-radius: 4px; font-size: 11px; padding: 0 5px; font-weight: 600; }
.checklist { list-style: none; padding: 0; margin: 4px 0 8px; }
.checklist li { margin: 3px 0; }
label.inline { display: inline-flex; gap: 6px; align-items: center; }
/* ---- Captcha trượt + iframe ---- */
.modal-box:has(#captchaSlider:not([hidden])) { max-width: 420px; }
.captcha-part { display: grid; gap: 10px; }
.captcha-part[hidden] { display: none; }
.slider-stage { position: relative; justify-self: center; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.modal-box .slider-stage img { display: block; border: 0; border-radius: 0; min-height: 0; }
.slider-stage #sliderBg { width: 100%; height: 100%; }
.slider-piece { position: absolute; left: 0; pointer-events: none; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .6)); }
.slider-piece[hidden], .slider-guide[hidden] { display: none; }
.slider-guide { position: absolute; top: 0; bottom: 0; left: 0; border: 2px solid #facc15; background: rgba(250, 204, 21, .2); pointer-events: none; }
#sliderRange { justify-self: center; padding: 0; border: 0; }
.tag.frame { background: #e0f2fe; color: #0369a1; }

.token-box { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.token-box label { font-size: 13px; color: #d0d5dd; }
.token-box input { flex: 1; max-width: 420px; padding: 6px 10px; border-radius: 6px; border: 1px solid #475467; background: #1d2939; color: #fff; }

/* ---------- Web mode ---------- */
.who { font-size: 13px; }
.stream-card { width: calc(100% - 32px); max-width: 1248px; margin: 16px auto 0; }
.stream-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stream-head h2 { margin: 0; }
#streamCanvas { display: block; width: 100%; height: auto; margin-top: 8px;
  border: 1px solid var(--border); background: var(--bg); cursor: default; touch-action: none; }
#streamCanvas:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.stream-text { display: flex; gap: 8px; margin-top: 8px; }
.stream-text button { width: auto; }
.stream-text input { flex: 1; min-width: 0; }
.badge.draft { background: var(--warn-bg); color: var(--warn); }
.badge.bundled { background: var(--ok-bg); color: var(--ok); }
#tokenGateInput { width: 100%; box-sizing: border-box; }
.token-box[hidden], .stream-card[hidden], label[hidden] { display: none; }
/* Menu thay cho popup <select> của trang trên stream */
.stream-select { position: fixed; z-index: 1000; display: flex; flex-direction: column; max-height: 320px; max-width: 480px;
  overflow-y: auto; background: var(--card, #fff); border: 1px solid #cbd5e1; border-radius: 6px; padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
.stream-select button { width: auto; text-align: left; background: transparent; color: inherit; border: 0; border-radius: 4px;
  padding: 6px 10px; font: inherit; cursor: pointer; }
.stream-select button:hover, .stream-select button:focus { background: #e0e7ff; outline: none; }
.stream-select button.cur { font-weight: 600; }
.stream-select button:disabled { opacity: .45; cursor: default; }
