:root {
  --primary: #1933F3; --primary-dark: #1226BF; --primary-soft: #EEF0FE;
  --bg: #F5F6FA; --card: #FFFFFF; --text: #101828; --muted: #667085; --line: #E4E7EC; --line-strong: #D0D5DD;
  --ok: #067647; --ok-soft: #ECFDF3; --warn: #B54708; --warn-soft: #FFFAEB; --err: #B42318; --err-soft: #FEF3F2; --info-soft: #EFF4FF;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: 'Be Vietnam Pro', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; } h4 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); text-underline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: 0; background: #fff; padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid rgba(25,51,243,.45); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .strong { font-weight: 600; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* Khung trang */
.topbar { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.topbar-in { max-width: 1320px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand img { width: 26px; height: 26px; }
.topbar-title { min-width: 0; flex: 1 1 200px; }
.topbar-title b { display: block; font-weight: 600; line-height: 1.3; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 16px 56px; }
.wrap.narrow { max-width: 780px; }
.page-head { margin-bottom: 20px; }
.env-tag { font-size: .75rem; color: var(--warn); background: var(--warn-soft); border: 1px solid #FEDF89; padding: 1px 8px; border-radius: 99px; }

/* Thành phần */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { background: #F9FAFB; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--err); border-color: #FDA29B; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: .875rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid.stat { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.stat-tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-tile b { display: block; font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 10px; font-size: .8125rem; font-weight: 500; border-radius: 99px; background: #F2F4F7; color: #344054; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); } .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.err { background: var(--err-soft); color: var(--err); } .chip.info { background: var(--primary-soft); color: var(--primary-dark); }
.code-tag { display: inline-block; font-weight: 700; color: var(--primary-dark); background: var(--primary-soft); border-radius: 6px; padding: 2px 8px; font-size: .875rem; }
.progress { height: 8px; background: #EAECF0; border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.progress.done i { background: var(--ok); }
.alert { padding: 12px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--info-soft); margin-bottom: 14px; }
.alert.warn { background: var(--warn-soft); border-color: #FEDF89; } .alert.err { background: var(--err-soft); border-color: #FECDCA; } .alert.ok { background: var(--ok-soft); border-color: #ABEFC6; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 48px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } * { scroll-behavior: auto !important; } }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--primary); border-color: var(--primary); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.field-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field-row label { font-weight: 500; font-size: .9375rem; }
.input, select.input, textarea.input { font: inherit; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--text); min-height: 40px; max-width: 100%; width: 100%; }
.input:focus { border-color: var(--primary); outline: 3px solid rgba(25,51,243,.18); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table.data { border-collapse: collapse; width: 100%; font-size: .9375rem; }
table.data th { text-align: left; font-weight: 600; background: #F9FAFB; font-size: .8125rem; color: #475467; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }

/* Trang trường */
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 28px 0 12px; }
.section-title h2 { margin: 0; }
.form-card { display: flex; flex-direction: column; gap: 8px; }
.form-card h3 { margin: 0; }
.form-card .meta { font-size: .875rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; margin-top: auto; display: grid; gap: 4px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.qr { width: 120px; height: 120px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; }
.survey-card { display: flex; gap: 16px; flex-wrap: wrap; }
.survey-card > div:first-child { flex: 1 1 220px; }
.school-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.school-list a { display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; text-decoration: none; color: var(--text); }
.school-list a:hover { border-color: var(--primary); }

/* Màn kê khai */
.dossier { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; max-width: 1320px; margin: 0 auto; padding: 16px 16px 0; align-items: start; }
.side { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.side details { border-radius: 8px; }
.side summary { list-style: none; padding: 8px 10px; cursor: pointer; border-radius: 8px; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-weight: 600; }
.side summary::-webkit-details-marker { display: none; }
.side summary:hover { background: #F9FAFB; }
.side summary .sub { grid-column: 1 / -1; font-weight: 400; font-size: .8125rem; color: var(--muted); line-height: 1.35; }
.side a.sec { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 7px 10px 7px 16px; text-decoration: none; color: var(--text); font-size: .875rem; line-height: 1.35; border-radius: 6px; }
.side a.sec:hover { background: #F9FAFB; }
.side a.sec[aria-current="true"] { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.side a.sec.locked { color: var(--muted); }
.mini { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.mini.ok { color: var(--ok); }
.mobile-nav { display: none; margin-bottom: 12px; }
.overview { display: grid; grid-template-columns: minmax(180px, 1.3fr) repeat(3, minmax(100px, 1fr)) auto; gap: 16px; align-items: center; margin-bottom: 14px; padding: 14px 16px; }
.overview .num { font-size: 1.15rem; font-weight: 600; display: block; line-height: 1.2; }
.sec-head { margin-bottom: 14px; display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; }
.sec-head h2 { margin-bottom: 4px; }
.sec-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .875rem; color: var(--muted); }
.actionbar { position: sticky; bottom: 0; background: rgba(255,255,255,.97); border-top: 1px solid var(--line); margin: 20px -1px 0; padding: 10px 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; z-index: 20; border-radius: var(--radius) var(--radius) 0 0; }
.actionbar .grow { flex: 1 1 120px; min-width: 0; }
.actionbar .btn { min-height: 34px; padding: 4px 12px; font-size: .9rem; }
.print-only-sign { display: none; }
.print-sheet .print-only-sign { display: grid; }
.save-state { font-size: .875rem; color: var(--muted); }
.save-state.err { color: var(--err); font-weight: 500; } .save-state.ok { color: var(--ok); } .save-state.warn { color: var(--warn); }
.issue-list { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow: auto; }
.issue-list button { all: unset; display: block; width: 100%; padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: .9rem; box-sizing: border-box; }
.issue-list button:hover, .issue-list button:focus-visible { background: var(--primary-soft); }
.issue-list b { color: var(--primary-dark); font-weight: 600; }

/* Biểu mẫu */
.form-note { background: #F9FAFB; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: .9rem; color: #344054; margin-bottom: 14px; }
.form-h { margin: 22px 0 10px; font-size: 1rem; font-weight: 600; }
.form-h .num { color: var(--primary-dark); margin-right: 6px; }
.fgroup { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 8px 18px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.fgroup:first-child { padding-top: 0; }
.fgroup > .g-label { font-weight: 600; font-size: .9375rem; line-height: 1.4; }
.badge-mode { display: inline-block; font-size: .72rem; font-weight: 500; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 5px; margin-left: 4px; vertical-align: 1px; white-space: nowrap; }
.line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 8px; }
.line:last-child { margin-bottom: 0; }
.line .lit { line-height: 1.5; }
.line.is-bullet .lit:first-child::before { content: "• "; color: var(--muted); }
.ctl { display: inline-flex; flex-direction: column; gap: 2px; min-width: 0; max-width: 100%; }
.ctl.full { flex: 1 1 100%; width: 100%; display: flex; }
.ctl input[type="text"], .ctl input[type="email"], .ctl input[type="tel"], .ctl input[type="time"], .ctl input[type="date"], .ctl select, .ctl textarea { font: inherit; padding: 6px 9px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; color: var(--text); min-height: 38px; max-width: 100%; }
.ctl textarea { width: 100%; min-height: 72px; resize: vertical; }
.ctl input.num { width: 112px; }
.ctl input.txt { width: 240px; }
.ctl.full input.txt { width: 100%; }
.ctl input:focus, .ctl textarea:focus, .ctl select:focus { border-color: var(--primary); outline: 3px solid rgba(25,51,243,.18); }
.ctl input:disabled, .ctl textarea:disabled, .ctl select:disabled { background: #F2F4F7; color: #475467; }
.ctl.is-missing input, .ctl.is-missing textarea { border-color: #F79009; background: #FFFCF5; }
.ctl.is-invalid input, .ctl.is-invalid textarea { border-color: var(--err); background: var(--err-soft); }
table.ft .badge-mode { display: none; }
.req { color: var(--err); font-weight: 600; margin-left: 2px; }
.err-msg { color: var(--err); font-size: .8125rem; line-height: 1.3; }
.num-unit { display: inline-flex; gap: 4px; }
.opts { display: flex; flex-wrap: wrap; gap: 4px 10px; flex: 1 1 auto; align-items: center; border: 0; padding: 0; margin: 0; min-width: 0; }
.opts.col { flex-direction: column; align-items: flex-start; }
.opts.is-missing { outline: 1px dashed #F79009; outline-offset: 3px; border-radius: 4px; }
.opts legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.opt { display: inline-flex; align-items: flex-start; gap: 7px; padding: 4px 2px; cursor: pointer; line-height: 1.4; min-height: 32px; max-width: 100%; }
.opt input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.opt-wrap { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 100%; }
.form-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 16px; }
table.ft { border-collapse: collapse; width: 100%; font-size: .9375rem; min-width: 640px; }
table.ft th { background: #F9FAFB; text-align: left; font-size: .8125rem; color: #475467; font-weight: 600; vertical-align: bottom; }
table.ft th, table.ft td { border-bottom: 1px solid var(--line); padding: 8px 10px; vertical-align: top; }
table.ft td .ctl input.num { width: 92px; }
table.ft td .ctl input.txt { width: 170px; }
table.ft tr.sub td { background: var(--primary-soft); font-weight: 600; color: var(--primary-dark); font-size: .875rem; }
table.ft tr.extra-row { background: #FCFCFD; }
table.ft td.mx { text-align: center; }
table.ft td.mx .opt { justify-content: center; }
table.ft td.mx .mx-label { display: none; }
.q-block { padding: 14px 0; border-bottom: 1px solid var(--line); }
.q-title { font-weight: 600; margin-bottom: 8px; }
.q-no { color: var(--primary-dark); margin-right: 4px; }
.shared-val { background: #F9FAFB; border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; min-height: 38px; }
.rq-note { border-left: 4px solid #F79009; }
.ro-val { font-weight: 500; border-bottom: 1px dotted #98A2B3; padding: 0 4px; min-width: 40px; display: inline-block; white-space: pre-wrap; }
.ro-opt { display: inline-block; margin-right: 12px; }
.ro-opt.on { font-weight: 600; }

/* Khảo sát */
.survey-head { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.step-info { display: flex; justify-content: space-between; gap: 12px; font-size: .875rem; color: var(--muted); margin-bottom: 6px; }
.survey-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* Hộp thoại */
dialog.modal { border: 0; border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: 86vh; box-shadow: 0 20px 50px rgba(16,24,40,.25); color: var(--text); }
dialog.modal::backdrop { background: rgba(16,24,40,.45); }
.modal-body { padding: 20px; overflow: auto; max-height: calc(86vh - 72px); }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#toasts { position: fixed; top: 12px; right: 12px; display: grid; gap: 8px; z-index: 60; width: min(360px, calc(100vw - 24px)); }
.toast { background: #101828; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: .9375rem; box-shadow: var(--shadow); }
.toast.err { background: var(--err); } .toast.ok { background: var(--ok); }

/* Thống kê */
.bar-row { display: grid; grid-template-columns: minmax(120px, 2fr) minmax(100px, 3fr) auto; gap: 10px; align-items: center; padding: 4px 0; font-size: .9375rem; }
.bar { height: 10px; background: #EAECF0; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--primary); }
.denom { font-size: .8125rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.open-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; }
.open-list li { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .9375rem; }

/* Hướng dẫn */
.guide h2 { margin-top: 28px; } .guide h3 { margin-top: 22px; }
.guide img { max-width: 100%; border: 1px solid var(--line); border-radius: 6px; margin: 8px 0; }
.guide .table-wrap { margin-bottom: 16px; }
.guide .toc { columns: 2; margin: 0; padding-left: 18px; font-size: .9375rem; }

/* Bản in */
.print-sheet { background: #fff; max-width: 1000px; margin: 16px auto; padding: 32px; border: 1px solid var(--line); }
.print-head { text-align: center; margin-bottom: 18px; }
.print-form { margin-top: 28px; }
.print-form + .print-form { break-before: page; }
.print-form table.ft { min-width: 0; font-size: .85rem; }
.print-form table.ft th, .print-form table.ft td { border: 1px solid #98A2B3; padding: 4px 6px; }
.sign { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; text-align: center; margin: 20px 0 80px; break-inside: avoid; }
.draft-mark { color: var(--err); font-weight: 700; border: 2px solid var(--err); display: inline-block; padding: 2px 12px; border-radius: 4px; }

@media (max-width: 960px) {
  .dossier { grid-template-columns: minmax(0, 1fr); padding-top: 12px; }
  .side { display: none; }
  .side.open { display: block; position: static; max-height: none; margin-bottom: 12px; }
  .mobile-nav { display: flex; gap: 8px; }
  .mobile-nav select { flex: 1; min-width: 0; }
  .overview { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .overview .ov-progress, .overview .ov-actions { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  h1 { font-size: 1.35rem; }
  .topbar { position: static; }
  .topbar-in { padding: 8px 12px; gap: 6px 10px; }
  .topbar-title { flex-basis: 60%; }
  .card { padding: 16px; }
  .wrap { padding: 16px 16px 40px; }
  .fgroup { grid-template-columns: minmax(0, 1fr); }
  .ctl input.txt, table.ft td .ctl input.txt { width: 100%; }
  .ctl:has(input.txt) { flex: 1 1 100%; }
  /* Bảng nhập liệu: mỗi hàng thành một nhóm dễ đọc, vẫn giữ nhãn cột */
  .form-table-wrap { overflow: visible; border: 0; }
  table.ft { min-width: 0; display: block; }
  table.ft thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table.ft tbody, table.ft tr, table.ft td { display: block; width: 100%; }
  table.ft tr { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; padding: 8px 10px; background: #fff; }
  table.ft tr.sub { padding: 0; border: 0; }
  table.ft tr.sub td { border-radius: 8px; padding: 8px 10px; }
  table.ft td { border: 0; padding: 6px 0; }
  table.ft td[data-label]::before { content: attr(data-label); display: block; font-size: .8125rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
  table.ft td.row-head { font-weight: 600; }
  table.ft td.row-head::before { display: none !important; }
  table.ft td.mx { display: inline-block; width: auto; margin-right: 8px; padding: 0; text-align: left; }
  table.ft td.mx::before { display: none !important; }
  table.ft td.mx .mx-label { display: inline; }
  .actionbar { margin: 16px -16px 0; border-radius: 0; padding: 8px 12px; }
  .actionbar { gap: 6px; }
  .actionbar .btn { flex: 1 1 auto; padding: 4px 6px; font-size: .85rem; white-space: nowrap; }
  .actionbar .btn.primary { flex: 1 1 100%; white-space: normal; }
  .actionbar .grow { flex: 1 1 100%; order: -1; font-size: .8rem; }
  .actionbar .grow:has(.save-state:empty) { display: none; }
  .bar-row { grid-template-columns: minmax(0, 1fr) auto; }
  .bar-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .guide .toc { columns: 1; }
  .print-sheet { padding: 16px; }
  .sign { gap: 8px; }
}
/* Không để thanh thao tác che nội dung khi bàn phím điện thoại mở */
@media (max-height: 520px) { .actionbar { position: static; } .topbar { position: static; } }

@media print {
  @page { margin: 14mm 12mm; }
  body { background: #fff; font-size: 12px; }
  .topbar, .no-print, #toasts, .skip-link { display: none !important; }
  .print-sheet { border: 0; margin: 0; max-width: none; padding: 0; }
  table.ft { display: table !important; }
  table.ft thead { display: table-header-group !important; position: static !important; width: auto !important; height: auto !important; clip-path: none !important; }
  table.ft tr { display: table-row !important; break-inside: avoid; }
  table.ft td, table.ft th { display: table-cell !important; }
  .print-form table.ft td[data-label]::before { display: none !important; }
  a { color: inherit; text-decoration: none; }
}
