:root {
  --bg: #f3f6f6;
  --card: #ffffff;
  --ink: #17282a;
  --muted: #5d7275;
  --line: #dbe4e5;
  --pri: #0e6e6b;
  --pri-2: #0a5452;
  --pri-soft: #e3f2f1;
  --ok: #1f8a4c;
  --ok-soft: #e4f5ea;
  --bad: #c0392b;
  --bad-soft: #fbe9e7;
  --na: #6b7a99;
  --na-soft: #eceff6;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 40, 42, .06), 0 4px 14px rgba(16, 40, 42, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 15px; line-height: 1.45; min-height: 100vh; }
a { color: var(--pri); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
small, .muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; background: var(--pri); color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.brand { display: flex; gap: 10px; align-items: center; color: #fff; text-decoration: none; }
.brand b { display: block; font-size: 1rem; }
.brand small { display: block; color: #cde9e7; font-size: .75rem; }
.logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #fff; color: var(--pri); font-weight: 800; }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a { color: #e2f3f2; text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-weight: 500; }
nav a.active, nav a:hover { background: rgba(255,255,255,.16); color: #fff; }
.who { font-size: .85rem; color: #d6eeec; white-space: nowrap; }
.who button { margin-left: 8px; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px 0; }
  .brand small { display: none; }
  .who { margin-left: auto; }
  nav { order: 3; flex-basis: 100%; margin: 0 -12px; padding: 0 8px 6px; }
}

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- elements ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card > h2:first-child { margin-top: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #c7d4d5; border-radius: 9px; padding: 9px 11px; width: 100%; min-height: 42px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pri); outline-offset: -1px; border-color: var(--pri); }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 9px; border: 1px solid transparent;
  padding: 9px 14px; min-height: 42px; background: var(--pri); color: #fff; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--pri-2); }
button:disabled { opacity: .55; cursor: wait; }
.btn-ghost { background: #fff; color: var(--pri); border-color: #bcd6d5; }
.btn-ghost:hover { background: var(--pri-soft); }
.btn-danger { background: #fff; color: var(--bad); border-color: #efc2bc; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.topbar .btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }

.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--na-soft); color: var(--na); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.pri { background: var(--pri-soft); color: var(--pri); }
.crit { color: var(--bad); font-weight: 700; }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .v { font-size: 1.6rem; font-weight: 700; }
.stat .l { font-size: .82rem; color: var(--muted); }

/* ---------- list of rounds ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.item:hover { border-color: var(--pri); }
.item .t { font-weight: 600; }
.item .s { font-size: .85rem; color: var(--muted); }
.pct { font-size: 1.25rem; font-weight: 700; text-align: right; }
.pct.ok { color: var(--ok); }
.pct.bad { color: var(--bad); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* ---------- checklist form ---------- */
.sec-title { background: var(--pri-soft); color: var(--pri-2); font-weight: 700; padding: 10px 14px; border-radius: 10px; margin: 18px 0 8px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.sec-title small { color: var(--pri); font-weight: 600; }
.crit-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.crit-item.is-D { border-left: 5px solid var(--ok); }
.crit-item.is-K { border-left: 5px solid var(--bad); background: #fffafa; }
.crit-item.is-N { border-left: 5px solid var(--na); }
.crit-head { display: flex; gap: 10px; }
.crit-no { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--na-soft); font-weight: 700; font-size: .9rem; }
.crit-item.critical .crit-no { background: var(--bad-soft); color: var(--bad); }
.crit-text { flex: 1; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.seg button { background: #fff; color: var(--ink); border: 1.5px solid #c7d4d5; min-height: 44px; font-weight: 600; }
.seg button[data-v="D"].on { background: var(--ok); border-color: var(--ok); color: #fff; }
.seg button[data-v="K"].on { background: var(--bad); border-color: var(--bad); color: #fff; }
.seg button[data-v="N"].on { background: var(--na); border-color: var(--na); color: #fff; }
.crit-extra { margin-top: 10px; display: grid; gap: 8px; }
.kd-box { border: 1px dashed #e2a59d; background: var(--bad-soft); border-radius: 10px; padding: 10px; display: grid; gap: 8px; }
.kd-box b { color: var(--bad); font-size: .85rem; }

.scorebar {
  position: sticky; bottom: 0; z-index: 10; margin: 16px -16px -16px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.97); border-top: 1px solid var(--line); backdrop-filter: blur(6px);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.scorebar .sc { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; font-size: .9rem; align-items: center; }
.scorebar .big { font-size: 1.3rem; font-weight: 800; }

.sig-wrap { border: 1.5px dashed #b8c9ca; border-radius: 10px; background: #fff; position: relative; touch-action: none; }
.sig-wrap canvas { width: 100%; height: 150px; display: block; }
.sig-wrap img { width: 100%; height: 150px; object-fit: contain; display: block; }
.sig-tools { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: .8rem; color: var(--muted); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #e7eeee; border: 1px solid var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photo button { position: absolute; top: 4px; right: 4px; min-height: 26px; padding: 2px 8px; font-size: .8rem; background: rgba(0,0,0,.6); }
.photo .pending { position: absolute; bottom: 4px; left: 4px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: #f6f9f9; font-weight: 600; color: var(--muted); white-space: nowrap; position: sticky; top: 0; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f3faf9; }
.overdue td:first-child { box-shadow: inset 4px 0 0 var(--bad); }

.bar { height: 10px; background: #edf1f1; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--bad); border-radius: 99px; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }

/* ---------- toast & modal ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #18302f; color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100% - 32px); }
.toast.err { background: var(--bad); }
.modal { position: fixed; inset: 0; background: rgba(10, 30, 30, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 18px; }
.modal-card.wide { width: min(1000px, 100%); }
.lightbox img { max-width: 100%; max-height: 80vh; display: block; margin: 0 auto; border-radius: 8px; }

.auth { max-width: 400px; margin: 8vh auto; }
.auth .logo { width: 52px; height: 52px; font-size: 1.6rem; background: var(--pri); color: #fff; margin-bottom: 10px; }

/* ---------- printable documents ---------- */
.doc { background: #fff; color: #000; font-family: "Times New Roman", Times, serif; font-size: 13pt; line-height: 1.35; padding: 24px 28px; border: 1px solid var(--line); border-radius: 6px; }
.doc .dh { display: flex; justify-content: space-between; align-items: flex-start; }
.doc .code { border: 1px solid #000; padding: 3px 8px; font-size: 11pt; }
.doc h1 { font-size: 14pt; text-align: center; margin: 6px 0 12px; }
.doc h2 { font-size: 13pt; margin: 14px 0 6px; }
.doc p { margin: 3px 0; }
.doc table { width: 100%; border-collapse: collapse; font-size: 12pt; }
.doc th, .doc td { border: 1px solid #000; padding: 4px 6px; vertical-align: top; }
.doc th { text-align: center; }
.doc td.c { text-align: center; }
.doc tr.sec td { font-weight: 700; background: #f0f0f0; }
.doc .signs { display: grid; grid-template-columns: 1fr 1fr; text-align: center; margin-top: 18px; gap: 20px; }
.doc .signs img { height: 80px; max-width: 100%; object-fit: contain; }
.doc .signs .sp { height: 80px; }
.doc .note { font-size: 11pt; margin-top: 14px; }
.doc .photos-print { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.doc .photos-print img { width: 100%; height: 150px; object-fit: cover; }

@media print {
  @page { size: A4; margin: 15mm 14mm; }
  body { background: #fff; }
  .topbar, .no-print, .scorebar, .toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; border-radius: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  tr, .signs { break-inside: avoid; }
}

@media print {
  body.printing-modal #app { display: none !important; }
  body.printing-modal .modal { position: static; background: none; padding: 0; display: block; }
  body.printing-modal .modal-card { width: auto; max-height: none; overflow: visible; padding: 0; }
  body:not(.printing-modal) .modal { display: none !important; }
}

@media (max-width: 600px) {
  main { padding: 12px; }
  .scorebar { margin: 12px -12px -12px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); gap: 8px; }
  .scorebar .sc { flex-basis: 100%; gap: 4px 10px; font-size: .82rem; }
  .scorebar .big { font-size: 1.1rem; }
  .scorebar button { flex: 1; min-height: 40px; }
  .card { padding: 13px; }
}

/* ---------- ô ngày dd/mm/yyyy ---------- */
.dfield { position: relative; display: flex; gap: 4px; align-items: stretch; width: 100%; }
.dfield .dtext { flex: 1; min-width: 0; }
.dfield .dpick { position: absolute; left: 0; bottom: 0; width: 100%; height: 0; min-height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.dfield .dbtn, .dfield .dstep { flex: none; min-height: 42px; padding: 0 10px; background: #fff; color: var(--pri); border: 1px solid #c7d4d5; font-weight: 700; }
.dfield .dbtn:hover, .dfield .dstep:hover { background: var(--pri-soft); }
input.invalid { border-color: var(--bad); outline-color: var(--bad); }

/* Hình thức đi buồng: 3 cột đều trên điện thoại */
@media (max-width: 600px) {
  #ht { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #ht label { display: flex; align-items: center; justify-content: center; padding: 8px 4px !important; font-size: .82rem !important; white-space: normal; text-align: center; border-radius: 10px; min-height: 42px; }
  #ht label input { margin-right: 4px !important; flex: none; }
}
