/* สแกนก่อนเชื่อ – senior-friendly, WCAG 2.2 AA theme
   - body text ≥ 18px (20px default), touch targets ≥ 48px (primary 56px)
   - colour is never the only signal (icons + words)
   - high-contrast mode and 3 text sizes */

:root {
  --fs: 20px;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #14171c;
  --muted: #4a5260;
  --border: #c9ced6;
  --primary: #0b4f9c;
  --primary-ink: #ffffff;
  --focus: #ffbf00;
  --red: #b3141b;
  --red-bg: #fdecec;
  --yellow: #8a5a00;
  --yellow-bg: #fff4d6;
  --green: #1d6b34;
  --green-bg: #e7f6ec;
  --grey: #444b55;
  --grey-bg: #eceef1;
  --sos: #c4161c;
  --sos-ink: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}
:root[data-size='large'] { --fs: 23px; }
:root[data-size='xlarge'] { --fs: 26px; }
:root[data-contrast='high'] {
  --bg: #000;
  --surface: #000;
  --text: #fff;
  --muted: #e6e6e6;
  --border: #fff;
  --primary: #ffe600;
  --primary-ink: #000;
  --red: #ff6b6b;
  --red-bg: #000;
  --yellow: #ffe600;
  --yellow-bg: #000;
  --green: #5dff8f;
  --green-bg: #000;
  --grey: #fff;
  --grey-bg: #000;
  --sos: #ffe600;
  --sos-ink: #000;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-size: var(--fs); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', 'Thonburi', Tahoma, system-ui, sans-serif;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
:root[data-contrast='high'] a { color: #7fd6ff; }
h1, h2, h3 { line-height: 1.3; margin: 0.4em 0; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.08rem; }
p { margin: 0.4em 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: 12px; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 8px 16px; background: var(--surface); border-bottom: 2px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: 8px; min-height: 48px; }
.brand svg { width: 36px; height: 36px; }
.topbar .tools { display: flex; gap: 6px; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; min-width: 48px; padding: 10px 18px;
  border-radius: var(--radius); border: 2px solid var(--primary);
  background: var(--primary); color: var(--primary-ink);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; text-align: center;
}
.btn.secondary { background: var(--surface); color: var(--primary); }
.btn.small { min-height: 48px; padding: 6px 12px; font-size: 0.9rem; }
.btn.block { display: flex; width: 100%; }
.btn.danger { background: var(--sos); border-color: var(--sos); color: var(--sos-ink); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.icon-btn { min-height: 48px; min-width: 48px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }

.card { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); }
.grid { display: grid; gap: 12px; }
.big-choice {
  display: flex; align-items: center; gap: 16px; min-height: 84px; padding: 14px 18px;
  border-radius: var(--radius); border: 2px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 700; font-size: 1.1rem; text-decoration: none; text-align: left; cursor: pointer; width: 100%;
}
.big-choice .ico { font-size: 2rem; width: 48px; text-align: center; flex: none; }
.big-choice small { display: block; font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.big-choice[aria-pressed='true'], .big-choice.selected { border-color: var(--primary); outline: 3px solid var(--primary); }

label { font-weight: 700; display: block; margin: 12px 0 6px; }
input[type='text'], input[type='url'], input[type='tel'], input[type='datetime-local'], select, textarea {
  width: 100%; min-height: 56px; padding: 12px 14px; font: inherit;
  border: 2px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
}
textarea { min-height: 170px; resize: vertical; }
input[type='file'] { font: inherit; min-height: 56px; width: 100%; }
input[type='checkbox'] { width: 32px; height: 32px; flex: none; accent-color: var(--primary); }
.check { display: flex; gap: 14px; align-items: flex-start; padding: 10px 0; min-height: 48px; }

.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.tabs a { flex: none; }
.tabs a[aria-current='page'] { background: var(--primary); color: var(--primary-ink); }

/* ---------- result ---------- */
.verdict { border-width: 4px; padding: 10px 14px; margin-top: 4px; }
.verdict.red { border-color: var(--red); background: var(--red-bg); }
.verdict.yellow { border-color: var(--yellow); background: var(--yellow-bg); }
.verdict.green { border-color: var(--green); background: var(--green-bg); }
.verdict.grey { border-color: var(--grey); background: var(--grey-bg); }
.verdict .head { display: flex; align-items: center; gap: 12px; }
.verdict .light { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.7rem; flex: none; color: #fff; font-weight: 900; }
.verdict.red .light { background: var(--red); }
.verdict.yellow .light { background: var(--yellow); }
.verdict.green .light { background: var(--green); }
.verdict.grey .light { background: var(--grey); }
:root[data-contrast='high'] .verdict .light { color: #000; }
.verdict .is-safe { font-size: 1.2rem; font-weight: 800; margin: 0; }
.verdict p { margin: 4px 0; }
.act { display: flex; gap: 8px; align-items: center; min-height: 48px; font-weight: 700; padding: 4px 0; }
.actions .btn { min-height: 52px; }
.qa { margin-top: 4px; }
.qa h2 { font-size: 1rem; margin: 8px 0 2px; }
.qa ul { margin: 0; padding-left: 1.2em; }
.actions { display: grid; gap: 8px; margin-top: 10px; }
.notice { border-left: 6px solid var(--yellow); padding: 8px 12px; background: var(--yellow-bg); border-radius: 8px; font-weight: 700; }
details { border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); margin: 10px 0; }
details > summary { min-height: 56px; padding: 12px 16px; cursor: pointer; font-weight: 700; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details > summary::after { content: '＋'; font-size: 1.2rem; }
details[open] > summary::after { content: '－'; }
details > .inner { padding: 0 16px 14px; }
.meter { height: 18px; border-radius: 9px; background: var(--grey-bg); border: 1px solid var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--primary); }
.axis { display: grid; gap: 4px; margin: 8px 0 14px; }
.bars { display: grid; grid-template-columns: 7.5em 1fr 3em; gap: 6px 8px; align-items: center; font-size: 0.9rem; }
.signal { padding: 8px 0; border-bottom: 1px solid var(--border); }
.signal:last-child { border-bottom: 0; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; border: 2px solid currentColor; font-size: 0.8rem; font-weight: 700; }
.sev-critical { color: var(--red); }
.sev-warning { color: var(--yellow); }
.sev-info { color: var(--grey); }

/* ---------- sticky emergency + nav ---------- */
.sos-bar { position: fixed; left: 0; right: 0; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 30; padding: 6px 12px; pointer-events: none; }
.sos-bar a { pointer-events: auto; max-width: 720px; margin: 0 auto; min-height: 60px; font-size: 1.12rem; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); }
nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 2px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
nav.bottom ul { list-style: none; margin: 0 auto; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); max-width: 720px; }
nav.bottom li.sos a { background: var(--sos); color: var(--sos-ink); border-radius: 14px 14px 0 0; margin: -10px 2px 0; min-height: 74px; font-size: 0.85rem; }
nav.bottom li.sos a[aria-current='page'] { box-shadow: inset 0 -4px 0 var(--sos-ink); color: var(--sos-ink); }
nav.bottom a { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 64px; text-decoration: none; color: var(--text); font-size: 0.75rem; font-weight: 700; text-align: center; line-height: 1.2; }
nav.bottom a .ico { font-size: 1.4rem; line-height: 1; }
nav.bottom a[aria-current='page'] { color: var(--primary); box-shadow: inset 0 4px 0 var(--primary); }

.spinner { width: 48px; height: 48px; border: 6px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } * { scroll-behavior: auto !important; } }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }
.error { border: 3px solid var(--red); background: var(--red-bg); padding: 12px; border-radius: 12px; font-weight: 700; }
.hl { background: #ffe58a; color: #000; border-radius: 4px; padding: 0 2px; }
.contact-list { display: grid; gap: 8px; }
.two-axis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two-axis > div { border: 2px dashed var(--border); border-radius: 12px; padding: 10px; }
@media (max-width: 380px) { .two-axis { grid-template-columns: 1fr; } .bars { grid-template-columns: 6em 1fr 2.6em; } }

/* ---- AI methodology panels / badges */
.method { margin-top: 12px; }
.method-list { padding-left: 0; list-style: none; }
.method-item { margin: 10px 0; }
.badge { display: inline-block; font-size: .8em; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.badge.owner_doc { color: var(--green); }
.badge.proposed { color: var(--yellow); }
.tablewrap { overflow-x: auto; }
.method-table { border-collapse: collapse; width: 100%; font-size: .9em; }
.method-table th, .method-table td { border-bottom: 1px solid var(--border); padding: 8px; vertical-align: top; text-align: left; }
.method-table ul { margin: 0; padding-left: 18px; }
.ai-card h2 { margin: 0 0 6px; font-size: 1.05em; }
.ai-card .row { margin: 6px 0; }
.method-cat summary .grow { flex: 1; }
.method-cat, .method, .method-list { overflow-wrap: anywhere; }
#app .card p { overflow-wrap: anywhere; }
