* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #FFFFFF; --panel: #FFFFFF; --panel2: #EEF6F0; --line: #C9DCCF;
  --text: #262626; --muted: #6B6B6B; --accent: #189848; --accent-text: #0F7A37; --accent2: #0F7A37;
  --warn: #8A5A00; --danger: #B42318; --core: #0F7A37; --room: #8A5A00;
}
body { background: var(--bg); color: var(--text); font: 14px/1.55 Roboto, "Segoe UI", system-ui, sans-serif; }
a { color: var(--accent-text); }
header {
  display: flex; align-items: center; gap: 16px; padding: 10px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
header .logo { font-weight: 700; letter-spacing: .5px; font-size: 16px; }
header .logo span { color: var(--accent); }
header .brand-logo { height: 28px; width: auto; order: 3; margin-left: 8px; }
.room-box { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.room-box select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: 13px; }
.scope-pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); }
.scope-pill.room { color: var(--room); border-color: var(--room); }
.scope-pill.core { color: var(--core); border-color: var(--core); }
nav { display: flex; gap: 4px; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
nav button { background: none; border: none; color: var(--muted); padding: 12px 16px; cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; }
nav button.active { color: var(--text); border-bottom-color: var(--accent); }
main { max-width: 1040px; margin: 0 auto; padding: 22px 18px 80px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
h2 { font-size: 15px; margin-bottom: 12px; }
h3 { font-size: 13px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .5px; }
textarea, input[type=text], input[type=search], input[type=date], select {
  width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 9px 11px; font: inherit; margin-bottom: 8px;
}
textarea { min-height: 84px; resize: vertical; }
button.btn { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 9px 16px; font-weight: 600; cursor: pointer; }
button.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.btn.sm { padding: 5px 10px; font-size: 12px; font-weight: 500; }
button.btn:disabled { opacity: .5; cursor: default; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.answer { white-space: pre-wrap; background: var(--panel2); border-left: 3px solid var(--accent2); padding: 12px 14px; border-radius: 6px; margin: 8px 0; }
.answer.en { border-left-color: var(--muted); color: var(--muted); font-style: italic; }
.conf { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.conf.Cao { background: #E2F3E8; color: var(--accent2); }
.conf.TB { background: #FFF4D6; color: var(--warn); }
.conf.Thap { background: #FDE7E7; color: var(--danger); }
table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0; }
th, td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
th { background: var(--panel2); color: var(--muted); font-size: 12px; }
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--panel2); border: 1px solid var(--line); margin: 2px 3px 2px 0; }
.tag.hl-HetHieuLuc { color: var(--danger); border-color: var(--danger); }
.tag.hl-ConHieuLuc { color: var(--accent2); }
.tag.pending { color: var(--warn); border-color: var(--warn); }
.src { font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 8px; }
.src b { color: var(--text); }
.dropzone { border: 1.5px dashed var(--line); border-radius: 8px; padding: 22px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.drag { border-color: var(--accent); color: var(--text); }
.toast { position: fixed; bottom: 18px; right: 18px; background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--accent2); padding: 12px 16px; border-radius: 8px; max-width: 380px; z-index: 50; }
.toast.err { border-left-color: var(--danger); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
details { margin: 6px 0; } summary { cursor: pointer; color: var(--muted); }
.warnbar { background: #FFF4D6; color: var(--warn); padding: 8px 14px; text-align: center; font-size: 13px; }

/* ---- cloud version additions ---- */
.hdr-meta { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34ch; }
.howto { margin: 0 0 12px 18px; display: grid; gap: 5px; font-size: 13.5px; }
.howto code, .muted code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.mono { font-family: Consolas, "SF Mono", monospace; font-size: 11.5px; word-break: break-all; }
.scr { overflow-x: auto; }
.doc { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-top: 10px; background: var(--panel); }
.grid2 label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.grid2 label select, .grid2 label input { margin-bottom: 4px; }
.progress { height: 4px; background: var(--panel2); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.qprev { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); display: grid; gap: 8px; }
.issues { margin: 6px 0 10px 18px; color: var(--warn); font-size: 13px; }
.skips { margin: 6px 0 0 16px; font-size: 12px; color: var(--muted); }
.dropzone:focus-visible, .btn:focus-visible, nav button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .hide-sm, .hdr-meta { display: none; }
  .room-box { margin-left: 0; width: 100%; }
  .room-box select { flex: 1; min-width: 0; }
  nav { overflow-x: auto; padding: 0 8px; }
  nav button { white-space: nowrap; padding: 12px 10px; }
  main { padding: 14px 10px 60px; }
  .grid2 { grid-template-columns: 1fr; }
  #repTitle { width: 100% !important; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } .progress > div { transition: none; } }

/* ---- zero-token + vbpl additions ---- */
.badge { display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 4px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 11px; font-weight: 700; }
.free { font-size: 11px; font-weight: 600; color: var(--accent2); border: 1px solid var(--accent2); border-radius: 999px; padding: 2px 8px; margin-left: 6px; vertical-align: 2px; }
.cost { font-size: 11px; font-weight: 600; color: var(--warn); border: 1px solid var(--warn); border-radius: 999px; padding: 2px 8px; margin-left: 6px; }
details.card > summary { color: var(--text); }
.warn-card { border-color: var(--warn); }
.cached { font-size: 13px; color: var(--muted); background: var(--panel2); border: 1px dashed var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.nowrap { white-space: nowrap; }
.tag.hl-HetHieuLucMotPhan { color: var(--warn); border-color: var(--warn); }
.tag.hl-ChuaCoHieuLuc { color: var(--accent); border-color: var(--accent); }
a.tag { text-decoration: none; }

/* ---- trust badges + citation check ("Phiếu kiểm chứng") ---- */
.trust { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag.ok { color: var(--accent2); border-color: var(--accent2); }
.tag.bad { color: var(--danger); border-color: var(--danger); }
.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.ok { color: var(--accent2); border-color: var(--accent2); }
.chip.warn { color: var(--warn); border-color: var(--warn); }
.chip.bad { color: var(--danger); border-color: var(--danger); }
.checkbox { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.chk-top { display: grid; gap: 6px; margin-bottom: 10px; }
.chk-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.chk-headline, .chk-new { background: var(--panel2); border-left: 3px solid var(--warn); border-radius: 6px; padding: 8px 12px; margin: 8px 0; font-size: 13px; }
.chk-new { border-left-color: var(--accent); }
.chk-headline ul, .chk-new ul { margin: 4px 0 0 16px; }
.chk-list { display: grid; gap: 8px; margin-top: 10px; }
.chk-card { background: var(--panel2); border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: 10px 12px; }
.chk-card.sev-ok { border-left-color: var(--accent2); }
.chk-card.sev-warn { border-left-color: var(--warn); }
.chk-card.sev-bad { border-left-color: var(--danger); }
.chk-card.sev-missing { border-left-color: var(--muted); }
.chk-head { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.chk-head .sev { font-weight: 700; }
.chk-title { font-size: 12px; margin-top: 2px; }
.chk-arts { margin-top: 6px; font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chk-flags, .chk-am { margin: 6px 0 0 16px; font-size: 13px; }
.chk-flags .f-bad { color: var(--danger); }
.chk-flags .f-warn { color: var(--warn); }
.chk-flags .f-info, .chk-flags .f-missing { color: var(--muted); }
.chk-sub { font-size: 12px; color: var(--muted); margin-top: 8px; }
.chk-am li { margin-bottom: 4px; }
.chk-foot { font-size: 12px; margin-top: 10px; }

/* ---- mobile-first refinements (PWA) ---- */
html { -webkit-text-size-adjust: 100%; }
body { overflow-wrap: break-word; padding-bottom: env(safe-area-inset-bottom); }
header { padding-top: calc(10px + env(safe-area-inset-top)); padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); }
a, button, select, summary { touch-action: manipulation; }
.installbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--panel2); border-bottom: 1px solid var(--line); font-size: 13px; }
.installbar .row { flex-wrap: nowrap; }
@media (max-width: 720px) {
  input, select, textarea { font-size: 16px; }           /* below 16px iOS zooms the page on focus */
  textarea { min-height: 110px; }
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn.sm { min-height: 40px; padding: 8px 12px; font-size: 13px; }
  nav { position: sticky; top: 0; z-index: 9; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav button { min-height: 46px; padding: 12px 13px; }
  header { position: static; }
  #askBtn { width: 100%; }
  #tab-ask .row { flex-direction: column; align-items: stretch; }
  #tab-ask .row label { font-size: 13px; }
  .doc > .row:first-child { flex-direction: column; align-items: stretch; }
  .doc > .row:first-child > .row { flex-wrap: wrap; }
  .card { padding: 14px; border-radius: 10px; }
  table { font-size: 12.5px; }
  th, td { padding: 6px 7px; }
  .answer { font-size: 15px; line-height: 1.65; padding: 12px; }
  .toast { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: none; }
  .chk-card { padding: 10px; }
  .dropzone { padding: 26px 12px; }
  .qprev .row { flex-direction: column; align-items: stretch; }
  #repTitle { width: 100% !important; }
  .scope-pill { max-width: 100%; white-space: normal; }
}
@media (display-mode: standalone) {
  .hide-standalone { display: none !important; }
}

/* ---- mobile fixes found by the on-device audit (overflow in Thư viện, 33px selects, 23px link tags) ---- */
@media (max-width: 720px) {
  .room-box select, select, input[type=text], input[type=search], input[type=date], textarea { font-size: 16px; min-height: 44px; }
  #urlTarget, #libScope { width: 100% !important; max-width: 100%; min-width: 0; }
  #tab-library .row, #tab-scout .row { flex-wrap: wrap; }
  #tab-library .row > select, #tab-library .row > input[type=text], #tab-scout .row > input[type=text] { flex: 1 1 100%; min-width: 0; }
  #tab-library .row > .btn, #tab-scout .row > .btn { flex: 1 1 auto; }
  a.tag { display: inline-flex; align-items: center; min-height: 34px; padding: 4px 10px; }
  .tag { max-width: 100%; white-space: normal; }
  .doc { overflow-wrap: anywhere; }
  .doc .trust { gap: 6px; }
  .room-box { align-items: stretch; }
  .room-box select { flex: 1; min-width: 0; }
}

/* long URLs / identifiers may break anywhere inside these blocks; tables keep their natural column width and scroll sideways */
.answer, .doc, .chk-card, .toast, .src, .mono { overflow-wrap: anywhere; }
@media (max-width: 720px) { .scr > table { min-width: 540px; } .scr { -webkit-overflow-scrolling: touch; } }

/* bulk OCR approval */
.ocr-bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 10px; }
.ocr-all { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
.ocr-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.ocr-chk, #ocrAll { width: 18px; height: 18px; }
@media (max-width: 720px) { .ocr-actions { margin-left: 0; width: 100%; } .ocr-actions .btn { flex: 1 1 auto; } }

/* ---- 4-tab bar in the style of the ETEK finance app: equal-width pills, no sideways scrolling ---- */
nav { position: sticky; top: 0; z-index: 9; display: flex; gap: 6px; padding: 8px 12px; overflow: visible; background: var(--bg); border-bottom: 1px solid var(--line); }
nav button { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--muted); font-size: 13px; line-height: 1.2; white-space: normal; text-align: center; }
nav button.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
nav .badge { margin-left: 2px; padding: 0 5px; min-width: 16px; font-size: 10px; }
@media (max-width: 720px) { nav { padding: 8px; } nav button { font-size: 12.5px; padding: 8px 2px; } }
details.card > summary { cursor: pointer; min-height: 28px; }
input[type=search] { width: 100%; }
[hidden] { display: none !important; }   /* .installbar{display:flex} used to override the hidden attribute and leave an empty bar */
@media (max-width: 720px) { .scope-pill { border-radius: 10px; padding: 6px 10px; text-align: center; line-height: 1.25; } .room-box { flex-direction: column; } }

/* phone lookup: a document is one compact row (title · status · số hiệu); admin buttons open when the title is tapped */
@media (max-width: 720px) {
  .doc:not(.open) > .row:first-child > .row { display: none; }
  .doc > .row:first-child b { cursor: pointer; }
  .doc a:not(.tag) { display: inline-block; padding: 6px 0; }
  .doc.open { border-color: var(--accent); }
}

/* ETEK brand: logo top-right; on phones the logo shares the first row with the wordmark, the room selector gets its own row */
@media (max-width: 720px) {
  header .brand-logo { order: 1; margin-left: auto; height: 24px; }
  .room-box { order: 2; }
  header { border-bottom: 2px solid var(--accent); }
}
header { border-bottom: 2px solid var(--accent); }
.answer { border-left-color: var(--accent); }
.toast { box-shadow: 0 4px 14px rgba(0,0,0,.15); }
