:root {
  --navy: #0F2247; --navy-2: #1D3B6D; --gold: #E9973B; --gold-soft: #FFF5E6;
  --ink: #172033; --muted: #5B6578; --line: #DDE3EC; --canvas: #F3F6FA; --paper: #FFFFFF;
  --ok: #1FA85F; --bad: #D64545; --warn: #D99A00; --info: #2F7FEA;
  --r-xs: 4px; --r-sm: 6px; --r-md: 10px; --r-lg: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--canvas); color: var(--ink); font: 15px/1.45 'Be Vietnam Pro', system-ui, sans-serif; }
body { min-height: 100dvh; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; color: var(--navy); }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
a { color: var(--navy-2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; background: var(--navy); color: #fff; }
.topbar img { width: 28px; height: 28px; }
.topbar .title { font-weight: 700; letter-spacing: .3px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { background: none; border: 0; color: #fff; font-size: 22px; padding: 4px 8px 4px 0; cursor: pointer; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head p { margin: 4px 0 0; }

.section { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; margin-bottom: 12px; }
.section > h2 { margin-bottom: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--paper); color: var(--navy); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.btn.navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { color: var(--bad); border-color: #F2C9C9; }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--navy); margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.field small.err { color: var(--bad); }
input[type=text], input[type=number], input:not([type]), textarea, select { width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; padding: 10px 12px; outline: none; }
textarea { min-height: 84px; resize: vertical; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 14px; letter-spacing: .5px; }
input:focus, textarea:focus, select:focus { border-color: var(--navy-2); box-shadow: 0 0 0 3px #DDE6F2; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }

.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer; background: #fff; }
.choice input { margin-top: 3px; accent-color: var(--navy); }
.choice b { display: block; color: var(--navy); }
.choice.on { border-color: var(--navy-2); background: #F6F9FD; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--navy); font-size: 13px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.warn { background: #FFF3D6; color: #8A6100; }
.badge.bad { background: #FDE8E8; color: var(--bad); }
.badge.ok { background: #E3F6EC; color: #137A44; }
.badge.info { background: #E4EEFC; color: #1F5FB8; }

.list { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer; text-align: left; width: 100%; }
.row .main { flex: 1; min-width: 0; }
.row .main b { display: block; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .score { font-size: 18px; font-weight: 700; color: var(--navy); white-space: nowrap; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty img { width: 56px; opacity: .9; margin-bottom: 8px; }

.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: #fff; border-top: 1px solid var(--line); padding: 10px 16px calc(10px + var(--safe-b)); }
.actionbar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; }
.actionbar .btn { flex: 1; }

.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(84px + var(--safe-b)); display: grid; justify-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { max-width: calc(100% - 32px); background: var(--navy); color: #fff; padding: 10px 14px; border-radius: var(--r-md); font-size: 14px; box-shadow: 0 6px 24px rgba(15,34,71,.25); }
.toast.bad { background: var(--bad); }

.sheet-bg { position: fixed; inset: 0; background: rgba(15,34,71,.35); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: #fff; border-radius: var(--r-lg) var(--r-lg) 0 0; padding: 16px 16px calc(16px + var(--safe-b)); }
.sheet h2 { margin-bottom: 4px; }
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; margin: 14px 0; }
.opt { height: 52px; border-radius: var(--r-sm); border: 1px solid var(--line); background: #fff; font-size: 18px; font-weight: 700; color: var(--navy); cursor: pointer; }
.opt.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.opt.blank { font-size: 13px; font-weight: 600; }

/* Màn quét */
.scan { position: fixed; inset: 0; background: #000; z-index: 40; color: #fff; }
.scan video, .scan canvas.ov { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan .bar { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px; background: linear-gradient(rgba(0,0,0,.6), transparent); }
.scan .bar .t { flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border-radius: 999px; border: 0; background: rgba(255,255,255,.16); color: #fff; font-size: 20px; cursor: pointer; display: grid; place-items: center; }
.icon-btn.on { background: var(--gold); color: var(--navy); }
.scan .bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(18px + var(--safe-b)); background: linear-gradient(transparent, rgba(0,0,0,.7)); display: grid; gap: 12px; justify-items: center; }
.scan .status { font-weight: 600; text-align: center; min-height: 22px; text-shadow: 0 1px 2px rgba(0,0,0,.6); padding: 4px 12px; border-radius: 999px; }
.scan .status.warn { background: rgba(233,151,59,.92); color: var(--navy); text-shadow: none; }
.scan .controls { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 420px; }
.shutter { width: 74px; height: 74px; border-radius: 999px; border: 4px solid #fff; background: rgba(255,255,255,.25); cursor: pointer; }
.shutter:active { background: var(--gold); }
.scan .card { position: absolute; left: 12px; right: 12px; bottom: calc(150px + var(--safe-b)); max-width: 480px; margin: 0 auto; background: #fff; color: var(--ink); border-radius: var(--r-md); padding: 12px 14px; display: flex; gap: 12px; align-items: center; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.scan .card .main { flex: 1; min-width: 0; }
.scan .card .main b { color: var(--navy); }
.scan .card .score { font-size: 22px; font-weight: 700; color: var(--navy); }
.scan .busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.35); font-weight: 700; }

/* Xem lại bài */
.review-img { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.review-img canvas { display: block; width: 100%; height: auto; touch-action: manipulation; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; }
.kv b { color: var(--navy); }
.parts { display: grid; gap: 6px; }
.part-line { display: flex; justify-content: space-between; gap: 8px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-right: 4px; vertical-align: -1px; }
