/* DIABETES_UI_V2 */
/* Design direction: "wayfinding sign" — one screen, one next action.
   Systems: spacing 4/8/12/16/24/32/48/64 · type 32/24/20/18 (learner) · radius 8 · one accent
   · elevation only on the fixed action bar · motion 150ms on press · system Thai font (0 KB). */
:root {
  --bg: #ffffff;
  --ink: #17201b;
  --muted: #4a564f;        /* 7.9:1 on white */
  --line: #dde3df;         /* bg darkened ~12%, green-tinted */
  --soft: #f3f6f4;         /* quiet surface for option tiles */
  --accent: #1b6b4a;       /* 6.6:1 on white — the only accent */
  --accent-press: #145238;
  --accent-soft: #e7f1ec;
  --ok: #17663f;
  --err: #a3121c;
  --err-soft: #fdecec;
  --warn: #7a5600;
  --warn-soft: #fff6dc;
  --focus: #f2b705;
  --r: 8px;
  --bar-h: 88px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Thai", "Noto Sans Thai UI", "Leelawadee UI", "Thonburi", system-ui, sans-serif;
  font-size: 20px;
  line-height: 1.65;
  letter-spacing: 0;
  overflow-wrap: break-word;
}
body.has-bar { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); }
.wrap { max-width: 40rem; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); text-underline-offset: 3px; }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Type scale — four sizes on learner pages */
h1 { font-size: 32px; line-height: 1.25; font-weight: 700; margin: 24px 0 8px; }
h2 { font-size: 24px; line-height: 1.3; font-weight: 700; margin: 32px 0 8px; }
p { margin: 0 0 16px; }
.lead { color: var(--muted); margin: 0 0 24px; }
.meta { font-size: 18px; color: var(--muted); }

/* Icons: one hand-drawn set, 24-grid, 2px round strokes, currentColor, sized in em */
.i { width: 1em; height: 1em; flex: 0 0 auto; vertical-align: -0.15em; fill: none; stroke: currentColor;
     stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Top line: site name + sign-out, quiet */
.topbar { border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.brand-sub { font-weight: 400; color: var(--muted); }
@media (max-width: 480px) { .brand-sub { display: block; line-height: 1.3; } .brand { line-height: 1.3; } }
.brand { color: var(--ink); text-decoration: none; font-size: 18px; font-weight: 700; }
.logout { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 18px; }
.who { color: var(--muted); }
.btn-link { white-space: nowrap; font: inherit; background: none; border: 0; padding: 12px 4px; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; min-height: 48px; }

/* Progress: four segments, the learner's position in the fixed path */
.progress { margin: 12px 0 0; }
.progress-track { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.progress-track span { height: 8px; border-radius: 4px; background: var(--line); }
.progress-track span.on { background: var(--accent); }
.progress-label { font-size: 18px; color: var(--muted); margin: 8px 0 0; }

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 56px; padding: 12px 16px; margin: 0;
  font: inherit; font-weight: 700; text-decoration: none; text-align: center;
  color: #fff; background: var(--accent); border: 2px solid var(--accent); border-radius: var(--r);
  cursor: pointer; transition: background-color 150ms ease-out;
}
.btn:hover { background: var(--accent-press); border-color: var(--accent-press); }
.btn-secondary { color: var(--accent); background: #fff; }
.btn-secondary:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn[disabled] { background: var(--line); border-color: var(--line); color: var(--muted); cursor: not-allowed; }
.stack > * + * { margin-top: 12px; }

/* Fixed action bar: the only floating thing, so the only shadow */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(23, 32, 27, .08);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.actionbar-inner { max-width: 40rem; margin: 0 auto; display: flex; gap: 12px; align-items: center; }
.actionbar .btn { min-height: 64px; flex: 1; white-space: nowrap; }
.actionbar .btn-secondary { flex: 0 0 auto; width: auto; padding: 12px 20px; }
.actionbar .count { flex: 0 0 auto; font-size: 18px; color: var(--muted); text-align: center; line-height: 1.3; }
.actionbar .count b { display: block; font-size: 24px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* Lists separated by rules, not boxes */
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.list > li { border-bottom: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 16px 0; min-height: 64px; color: var(--ink); text-decoration: none; }
a.row:hover .row-title { text-decoration: underline; text-underline-offset: 3px; }
.row .num { flex: 0 0 32px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.row-title { flex: 1; min-width: 0; }
.row .state { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; font-size: 18px; color: var(--muted); }
.row .state.done { color: var(--ok); }
.row .state.now { color: var(--accent); font-weight: 700; }
.row.locked { color: var(--muted); }
.list > li.list-end { margin-top: 24px; border-top: 1px solid var(--line); }
.row .num .i { font-size: 24px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 32px 0 0; font-size: 18px; color: var(--muted); }
.divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* Notices: colour plus icon plus words */
.note { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; margin: 16px 0; border-radius: var(--r); border-left: 4px solid; font-size: 18px; }
.note .i { font-size: 24px; margin-top: 2px; }
.note-info { background: var(--accent-soft); border-color: var(--accent); }
.note-success { background: var(--accent-soft); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.note-error { background: var(--err-soft); border-color: var(--err); color: var(--err); font-weight: 700; }
.note-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); font-weight: 700; }

/* Forms */
label, .label { display: block; font-weight: 700; margin: 24px 0 8px; }
.help { font-size: 18px; color: var(--muted); margin: 8px 0 0; }
input[type=text], input[type=tel], input[type=number], input[type=url], select, textarea {
  width: 100%; font: inherit; padding: 12px 16px; min-height: 56px;
  border: 2px solid #b9c4bd; border-radius: var(--r); background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid var(--focus); outline-offset: 1px; }
input[aria-invalid=true] { border-color: var(--err); }
textarea { min-height: 120px; }
.field-error { display: flex; gap: 8px; align-items: center; color: var(--err); font-weight: 700; font-size: 18px; margin: 8px 0 0; }

/* Lesson pages: one idea per page, no box */
.lesson-page { padding: 24px 0 8px; }
.lesson-page figure { margin: 0 0 16px; }
.lesson-page figure img { width: 144px; height: 144px; display: block; }
.lesson-page h2 { margin-top: 0; }
.lesson-page ul { padding-left: 24px; margin: 0 0 16px; }
.lesson-page li + li { margin-top: 8px; }
.eyebrow { font-size: 18px; color: var(--muted); margin: 24px 0 0; }

/* Lite YouTube */
.video { margin: 24px 0 0; }
.video-frame { position: relative; width: 100%; aspect-ratio: 16/9; border-radius: var(--r); overflow: hidden; background: var(--soft); }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video figcaption { margin-top: 8px; }

/* Questions */
.q { margin: 24px 0 0; padding: 0 0 24px; border: 0; border-bottom: 1px solid var(--line); min-width: 0; }
.q legend { padding: 0; font-weight: 700; margin-bottom: 12px; width: 100%; }
.q legend .qn { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
.q.unanswered legend { color: var(--err); }
.q.unanswered legend::after { content: " · ยังไม่ได้ตอบ"; font-size: 18px; }
.opt { position: relative; display: block; margin: 8px 0 0; font-weight: 400; }
.opt input { position: absolute; opacity: 0; top: 0; left: 0; width: 1px; height: 1px; }
.opt span { display: flex; gap: 12px; align-items: center; min-height: 56px; padding: 12px 16px; border: 2px solid var(--line); border-radius: var(--r); background: var(--soft); cursor: pointer; }
.opt span::before { content: ""; flex: 0 0 22px; height: 22px; border-radius: 50%; border: 2px solid #8a968f; background: #fff; }
.opt input:checked + span { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.opt input:checked + span::before { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 0 5px, #fff 6px); }
.opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Quiz feedback */
.fb-item { padding: 24px 0; border-bottom: 1px solid var(--line); }
.fb-item .qtext { font-weight: 700; margin-bottom: 8px; }
.verdict { display: flex; gap: 8px; align-items: flex-start; font-weight: 700; margin: 8px 0 0; }
.verdict .i { font-size: 24px; margin-top: 2px; }
.verdict.ok { color: var(--ok); }
.verdict.no { color: var(--err); }
.why { margin: 8px 0 0 32px; color: var(--ink); }
.yours { color: var(--muted); font-size: 18px; margin: 0; }

/* Likert: five tiles */
.likert { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.likert .opt { margin: 0; min-width: 0; }
.likert .opt span { justify-content: center; padding: 8px 0; font-variant-numeric: tabular-nums; }
.likert .opt span::before { display: none; }
.likert-ends { display: flex; justify-content: space-between; gap: 8px; font-size: 18px; color: var(--muted); margin-top: 8px; }

.foot { color: var(--muted); font-size: 18px; padding: 48px 16px 24px; }

/* ---------- Staff pages (admin): denser, same tokens ---------- */
body.admin { font-size: 16px; line-height: 1.6; }
body.admin .wrap { max-width: 1100px; }
body.admin h1 { font-size: 28px; }
body.admin h2 { font-size: 20px; margin-top: 0; }
body.admin label { font-size: 16px; margin: 16px 0 4px; }
body.admin input, body.admin select, body.admin textarea { min-height: 44px; padding: 8px 12px; }
body.admin .btn { display: inline-flex; width: auto; min-height: 44px; padding: 8px 16px; }
body.admin .note { font-size: 16px; }
body.admin .foot, body.admin .meta, body.admin .help { font-size: 14px; }
.adminnav { display: flex; gap: 4px; flex-wrap: wrap; padding-bottom: 8px; }
.adminnav a { padding: 8px 12px; border-radius: var(--r); text-decoration: none; color: var(--ink); }
.adminnav a:hover { background: var(--soft); }
.card { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin: 16px 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }
th { background: var(--soft); font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.inline { display: inline; }
.btn-sm { font: inherit; font-size: 14px; padding: 4px 10px; min-height: 32px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.btn-sm:hover { background: var(--soft); }
.btn-danger { color: var(--err); border-color: #e3b5b8; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; }
.kpi b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; }
.small { font-size: 14px; }
.muted { color: var(--muted); }

@media (max-width: 600px) {
  .grid2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
.mt-24 { margin-top: 24px; }

/* Admin: completion bar (one accent, value always also printed as text) */
.bar-col { min-width: 140px; white-space: nowrap; }
.bar { display: inline-block; vertical-align: middle; width: 96px; height: 8px; margin-right: 8px; border-radius: 4px; background: var(--soft); border: 1px solid var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* e-Manual */
.manual-cover { padding: 24px 0 32px; border-bottom: 4px solid var(--accent); }
.manual-cover .eyebrow { margin-top: 16px; }
.manual-cover h1 { margin-top: 8px; }
.manual-mark { display: inline-flex; color: var(--accent); }
.manual-mark .i { width: 48px; height: 48px; }
.mt-48 { margin-top: 48px; }
.steps .row { align-items: flex-start; }
.faq { margin: 0; }
.faq dt { font-weight: 700; margin-top: 24px; }
.faq dd { margin: 4px 0 0; color: var(--muted); }
.plain { padding-left: 24px; }
.plain li + li { margin-top: 8px; }
@media print {
  .topbar .logout, .actionbar, .foot { display: none !important; }
  body.has-bar { padding-bottom: 0; }
  .manual-cover { break-after: avoid; }
}
