/* Clew: calm, formal and readable. Navy for the brand, a terracotta "thread" as the only warm accent. */
:root {
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #f8f9fb; --ink: #172033; --muted: #5b6474; --line: #e1e5ec;
  --brand: #1d3557; --brand-hover: #16294a; --brand-soft: #eaf0f7; --brand-ink: #ffffff; --link: #1f4f8f;
  --thread: #c0583f; --strand: #c9d6e8;
  --warn: #85520a; --warn-soft: #fdf4e3; --danger: #b3261e; --danger-soft: #fdecea; --ok: #1e7a3c;
  --shadow: 0 1px 2px rgba(23, 32, 51, .06), 0 2px 8px rgba(23, 32, 51, .04);
  --radius: 14px;
  --wordmark: var(--brand); --accent-ink: var(--brand); color-scheme: light;
}
/* Dark: follows the device unless the viewer picked a theme with the switch (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171d26; --surface-2: #1c2330; --ink: #e6e9ef; --muted: #9aa4b2; --line: #283140;
    --brand: #2b4a72; --brand-hover: #345a8a; --brand-soft: #1c2a3d; --brand-ink: #ffffff; --link: #8fb3e8;
    --thread: #e08a6f; --strand: #9fb6d6;
    --warn: #f3c06b; --warn-soft: #33270f; --danger: #ff8a80; --danger-soft: #3d1f1d; --ok: #7fd49a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --wordmark: var(--ink); --accent-ink: var(--link); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171d26; --surface-2: #1c2330; --ink: #e6e9ef; --muted: #9aa4b2; --line: #283140;
  --brand: #2b4a72; --brand-hover: #345a8a; --brand-soft: #1c2a3d; --brand-ink: #ffffff; --link: #8fb3e8;
  --thread: #e08a6f; --strand: #9fb6d6;
  --warn: #f3c06b; --warn-soft: #33270f; --danger: #ff8a80; --danger-soft: #3d1f1d; --ok: #7fd49a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --wordmark: var(--ink); --accent-ink: var(--link); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.65 "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", "Thonburi", system-ui, sans-serif; }
svg { flex: none; }

/* ---- top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px max(16px, calc((100vw - 880px) / 2)); background: var(--surface);
  border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 34px; height: 34px; }
.mark .ball { fill: var(--brand); }
.mark .strand { fill: none; stroke: var(--strand); stroke-width: 1.3; stroke-linecap: round; }
.mark .tail { fill: none; stroke: var(--thread); stroke-width: 2.2; stroke-linecap: round; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.wordmark { font-size: 21px; font-weight: 700; letter-spacing: .02em; color: var(--wordmark); }
.tagline { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 6px; }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 500;
  padding: 7px 12px; min-height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost svg, .infobar svg, .btn-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 560px) { .btn-ghost span { display: none; } .btn-ghost { padding: 7px 10px; } }

/* theme button: shows the theme it switches to (moon in light mode, sun in dark mode) */
.theme-btn .sun, .theme-btn[data-dark="true"] .moon { display: none; }
.theme-btn[data-dark="true"] .sun { display: block; }

.infobar { display: flex; align-items: flex-start; gap: 8px; max-width: 880px; margin: 0 auto;
  padding: 10px 16px 0; color: var(--muted); font-size: 13px; }
.infobar svg { width: 16px; height: 16px; margin-top: 2px; }
.infobar p { margin: 0; }

/* ---- conversation */
main { max-width: 880px; margin: 0 auto; padding: 8px 16px 170px; }
.msg { display: flex; gap: 10px; margin: 16px 0; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; flex: none; margin-top: 2px; }
.avatar .mark { width: 24px; height: 24px; }
.bubble { min-width: 0; max-width: 100%; white-space: pre-line; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); overflow-wrap: anywhere; }
.bot .bubble { border-top-left-radius: 4px; flex: 1; }
.user .bubble { max-width: min(85%, 640px); background: var(--brand); color: var(--brand-ink); border: none;
  border-top-right-radius: 4px; box-shadow: none; }
.typing { color: var(--muted); font-size: 14px; display: inline-flex; gap: 4px; align-items: center; }
.typing::after { content: ""; width: 18px; height: 6px; background:
  radial-gradient(circle, currentColor 2px, transparent 2.5px) 0 0 / 6px 6px repeat-x; animation: dots 1.2s infinite steps(4); }
@keyframes dots { 0% { width: 0 } 100% { width: 24px } }

.bubble p { margin: 8px 0; }
.intro { white-space: normal; }
.intro p:first-child { margin-top: 0; }
.intro p:last-child { margin-bottom: 0; font-weight: 500; }
.intro-list { margin: 0; padding: 0; list-style: none; }
.intro-list li { position: relative; padding: 3px 0 3px 22px; }
.intro-list li::before { content: ""; position: absolute; left: 4px; top: 13px; width: 8px; height: 8px; border-radius: 50%;
  border: 2px solid var(--thread); }
.intro-limit { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 14.5px; }
.short { font-size: 17px; font-weight: 600; line-height: 1.55; }
.notice { font-size: 13.5px; color: var(--warn); background: var(--warn-soft); padding: 8px 12px; border-radius: 10px; margin-bottom: 10px; }
.urgent { background: var(--danger-soft); color: var(--danger); padding: 10px 14px; border-radius: 10px; font-weight: 600;
  margin-bottom: 12px; border-left: 4px solid var(--danger); }
.urgent-details { margin: 6px 0 0; padding-left: 20px; font-weight: 400; font-size: 14.5px; color: var(--ink); }
.urgent-details li { margin: 3px 0; }
.urgent-details li:last-child { color: var(--muted); font-size: 13px; }
h4 { margin: 20px 0 8px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 14px; font-weight: 600;
  letter-spacing: .02em; color: var(--accent-ink); }

/* answer choices */
.options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; white-space: normal; }
.options button, .btn-outline { font: inherit; font-size: 15px; cursor: pointer; border-radius: 999px; border: 1px solid var(--accent-ink);
  background: var(--surface); color: var(--accent-ink); padding: 7px 16px; min-height: 40px; }
.options button:hover, .btn-outline:hover { background: var(--brand-soft); }
.options button.ghost { border-color: var(--line); color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, a:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* agency / link buttons */
.linkbtn { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; font-weight: 600; font-size: 14.5px;
  border: 1px solid var(--line); color: var(--link); background: var(--surface-2); border-radius: 10px;
  padding: 7px 12px; margin: 4px 6px 4px 0; }
.linkbtn:hover { border-color: var(--link); }
.linkbtn.mandatory { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.linkbtn.nolink { border-style: dashed; color: var(--muted); }
.prepare { font-size: 13px; color: var(--muted); }

.factsline { font-size: 14px; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 8px 12px; margin: 12px 0; }
.factsline button, .facts button { font: inherit; font-size: 13px; padding: 2px 10px; min-height: 28px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--link); cursor: pointer; }
.facts { list-style: none; padding: 0; margin: 8px 0 0; font-size: 14px; }
.facts li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }

ol.steps { list-style: none; counter-reset: step; padding: 0; margin: 0; }
ol.steps li { counter-increment: step; position: relative; padding: 2px 0 12px 38px; }
ol.steps li::before { content: counter(step); position: absolute; left: 0; top: 2px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-soft); color: var(--accent-ink); font-size: 13px; font-weight: 700; display: grid; place-items: center; }

ul.evidence { list-style: none; padding: 0; margin: 0; }
ul.evidence li { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14.5px; }
ul.evidence > li > b + .tag { margin-left: 8px; }
.tag.ok { background: var(--brand-soft); color: var(--ok); }
ul.evidence label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
ul.evidence input[type=checkbox] { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--brand); flex: none; }
.f9 { margin-top: 12px; }

details { margin-top: 14px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--surface-2); }
summary { cursor: pointer; font-weight: 600; font-size: 14.5px; }
.cite { font-size: 13px; color: var(--muted); margin: -2px 0 10px; }
.cite a { color: var(--link); }
.tag { font-size: 11.5px; padding: 1px 7px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); margin-left: 4px; white-space: nowrap; }
.warnings { padding-left: 20px; }
.warnings li { font-size: 14px; color: var(--warn); }
.disclaimer-line { font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; margin-top: 14px; }
details.f6 { background: transparent; border-style: dashed; font-size: 12px; color: var(--muted); }
details.f6 summary { font-weight: 500; font-size: 12px; }
details.f6.fail { color: var(--danger); }

/* ---- composer */
.composer-wrap { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; padding: 12px 16px 10px;
  background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer { max-width: 848px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 4px 18px rgba(23, 32, 51, .08); }
.composer:focus-within { border-color: var(--link); }
textarea { flex: 1; font: inherit; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink);
  padding: 7px 0; max-height: 180px; }
.btn-send { width: 42px; height: 42px; border-radius: 12px; border: 0; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; cursor: pointer; }
.btn-send:hover { background: var(--brand-hover); }
.composer-hint { max-width: 848px; margin: 6px auto 0; font-size: 12px; color: var(--muted); text-align: center; }
@media (max-width: 560px) { .composer-hint { display: none; } main { padding-bottom: 130px; } }

/* ---- invite gate */
.gate { border: 0; border-radius: 18px; padding: 0; width: min(420px, calc(100vw - 32px)); background: var(--surface);
  color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.gate::backdrop { background: rgba(15, 20, 27, .55); backdrop-filter: blur(2px); }
.gate form { padding: 28px 24px 24px; display: flex; flex-direction: column; gap: 8px; }
.gate .mark.big { width: 44px; height: 44px; }
.gate h2 { margin: 6px 0 0; font-size: 20px; }
.gate p { margin: 0 0 8px; color: var(--muted); font-size: 14.5px; }
.gate label { font-size: 13.5px; font-weight: 600; }
.gate input { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.gate-error { color: var(--danger) !important; min-height: 1.2em; margin: 0 !important; font-size: 13.5px !important; }
.btn-primary { font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; border: 0; background: var(--brand);
  color: var(--brand-ink); cursor: pointer; min-height: 44px; }
.btn-primary:hover { background: var(--brand-hover); }
