/* qa.css: Q&A (ASK + list + inbox + editor) — handoff ฉบับ 4 ข้อ D + 3.1 ข้อ 4.3 · tokens จาก tokens.css, components จาก style.css
   ไม่มี chat bubble: ผู้ใช้ = YOU · + ไทย muted 14 / คำตอบ = Anuphan 18 + เส้นนำ cyan 2px ซ้าย */

/* ------------------------------------------------------------ header + tabs */
.qa-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.qa-title { margin: 0; font-family: var(--font-hud); font-size: 20px; font-weight: 700; letter-spacing: .18em; line-height: 1.2; }
.qa-sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.qa-seg { margin-bottom: var(--s-4); align-self: flex-start; }
.qa-seg a { font-family: var(--font-hud); font-size: var(--lbl-size); font-weight: 600; letter-spacing: var(--lbl-track); text-transform: uppercase; gap: 8px; }
.qa-badge { min-width: 18px; height: 18px; padding: 0 5px; background: var(--amber); color: var(--on-amber); font-size: 11px; line-height: 18px; text-align: center; letter-spacing: 0; }
.qa-seg .ico { width: 12px; height: 12px; }

/* ------------------------------------------------------------------- ASK */
.qa-ctx { display: flex; align-items: center; gap: 12px; }
.qa-ctx .lbl { flex: 0 0 auto; }
/* entry to the desktop Q&A stage (#/stage): only where that page renders (stage.css, ADR 0023) */
.qa-stage-link { display: none; margin-left: auto; color: var(--scan); text-decoration: none; min-height: var(--touch); align-items: center; }
@media (min-width: 1200px) and (pointer: fine) { .qa-stage-link { display: inline-flex; } }
@media (min-width: 1200px) and (hover: hover) and (pointer: fine) { .qa-stage-link:hover { text-decoration: underline; } }
.qa-place { min-height: var(--touch); flex: 1 1 auto; min-width: 0; }

.qa-stage { display: flex; flex-direction: column; align-items: center; padding-top: 6px; }
.qa-ret { position: relative; width: 260px; height: 210px; }
.reticle { position: absolute; inset: 0; color: var(--scan); }
/* the selected robot body (mascot/body.js) stands inside the reticle circles; the legacy raven keeps its canvas box */
.qa-body { position: absolute; left: 60px; top: 6px; width: 140px; height: 198px; }
.qa-body[data-body="raven"] { left: 10px; top: 10px; width: 240px; height: 190px; }
.qa-body:focus-visible { outline: 2px solid var(--focus, var(--scan)); outline-offset: 2px; }
.qa-ret .raven-fallback { position: absolute; left: 55px; top: 40px; width: 150px; height: 125px; }
.qa-status { margin: -4px 0 0; min-height: 1.6em; text-align: center; }

/* LISTENING sweep: one line, 2400ms linear, fades in/out 200ms (.run keeps it turning while it fades out) */
.sweep { transform-box: view-box; transform-origin: 130px 105px; opacity: 0; transition: opacity 200ms ease; }
.sweep.run { animation: qa-sweep 2400ms linear infinite; }
.sweep.on { opacity: 1; }
@keyframes qa-sweep { to { transform: rotate(360deg); } }

/* conversation */
.qa-log { display: flex; flex-direction: column; gap: 20px; padding: 14px 0 16px; }
.qa-hello { margin: 0; font-size: var(--fs-sm); color: var(--muted); text-align: center; }
.qa-pair { display: flex; flex-direction: column; gap: 6px; scroll-margin-bottom: calc(var(--nav-h) + 220px); }
.qa-pair.in { animation: qa-rise 300ms var(--ease-out) both; }
@keyframes qa-rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes qa-fade { from { opacity: 0; } }
.qa-q { margin: 0; font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.qa-q .lbl { color: var(--muted); }
.qa-a { display: flex; flex-direction: column; gap: 8px; }
.qa-answer { margin: 0; font-family: var(--font-ui); font-size: 18px; line-height: 1.65; overflow-wrap: anywhere; }
.qa-note { margin: 0; font-size: 13px; color: var(--muted); }
.qa-err { margin: 0; font-size: var(--fs-sm); color: var(--danger); }
.qa-wait { margin: 0; display: flex; align-items: center; gap: 10px; min-height: 28px; }
.qa-a-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.qa-play {
  width: 44px; height: 44px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; padding: 0;
  background: none; border: 1px solid var(--line-strong); color: var(--scan); cursor: pointer;
  transition: transform 140ms var(--ease-out);
}
.qa-play .ico { width: 16px; height: 16px; }
.qa-play:active { transform: scale(.95); }
.qa-play[aria-pressed="true"] { border-color: var(--amber); color: var(--amber); }
.qa-play:disabled { color: var(--muted); border-color: var(--line); cursor: not-allowed; }
.qa-play:focus-visible, .qa-send:focus-visible, .qa-mic:focus-visible { outline: 2px solid var(--scan); outline-offset: 2px; }
.qa-src { min-height: var(--touch); display: inline-flex; align-items: center; gap: 4px; color: var(--scan); text-decoration: none; }
.qa-src .th { font-family: var(--font-ui); font-size: 13px; font-weight: 500; }
.qa-matches summary { min-height: var(--touch); display: flex; align-items: center; cursor: pointer; }
.qa-matches ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.qa-matches li { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; background: var(--panel); border-left: 2px solid var(--line-strong); font-size: 13px; }
.qa-m-name { color: var(--text); }
.qa-m-text { color: var(--muted); overflow-wrap: anywhere; }

/* ASK fills the screen so the bar sits at the bottom even with a short conversation */
main#view:has(> .qa-bar) {
  display: flex; flex-direction: column;
  min-height: calc(100dvh - 56px - env(safe-area-inset-top));
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
main#view:has(> .qa-bar) > .qa-log { flex: 1 0 auto; }

/* bottom bar: --panel + top line, sticks above the tab bar */
.qa-bar {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 10; isolation: isolate;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin: 0 calc(-1 * max(var(--edge), env(safe-area-inset-left))) 0;
  padding: 12px max(var(--edge), env(safe-area-inset-right)) 14px max(var(--edge), env(safe-area-inset-left));
  background: var(--panel-solid); border-top: 1px solid var(--line);
}
.qa-input { flex: 1 1 140px; min-width: 0; min-height: 48px; }
.qa-input[hidden], .qa-send[hidden] { display: none; }
.qa-send {
  width: 48px; height: 48px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; padding: 0;
  background: none; border: 1px solid var(--line-strong); color: var(--text); cursor: pointer; transition: transform 140ms var(--ease-out);
}
.qa-send .ico { width: 20px; height: 20px; }
.qa-send:active { transform: scale(.95); }
.qa-bar > .gate { display: contents; }
.qa-bar .gate-why { order: 9; flex: 1 1 100%; font-size: 12px; }
.qa-bar .gate-why .btn { font-family: var(--font-ui); letter-spacing: 0; text-transform: none; font-size: 13px; min-height: var(--touch); }
.qa-mic {
  position: relative; width: 60px; height: 60px; flex: 0 0 auto; border-radius: 50%; border: 0; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--amber); color: var(--on-amber); cursor: pointer; transition: transform 140ms var(--ease-out);
}
.qa-mic .ico { width: 26px; height: 26px; }
.qa-mic:active { transform: scale(.95); }
.qa-mic:disabled { background: var(--track); color: var(--muted); cursor: not-allowed; }
.qa-mic.on::before, .qa-mic.on::after {
  content: ""; position: absolute; inset: 0; border: 1.5px solid var(--amber); border-radius: 50%;
  animation: qa-ring 1600ms ease-out infinite; pointer-events: none;
}
.qa-mic.on::after { animation-delay: 800ms; }
@keyframes qa-ring { from { transform: scale(1); opacity: .7; } to { transform: scale(1.5); opacity: 0; } }
.qa-wave { flex: 1 1 140px; display: flex; align-items: center; justify-content: space-between; height: 40px; min-width: 0; }
.qa-wave[hidden] { display: none; }
.qa-wave span { width: 3px; height: 28px; background: var(--idle-bar); transform: scaleY(.25); transition: background-color 200ms ease; }
.qa-wave.on span { background: var(--amber); }

/* ----------------------------------------------------------------- Q&A list */
.qa-list-tools { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-4); }
.qa-list-sel { flex: 1 1 220px; min-width: 0; }
.qa-list-q { flex: 1 1 200px; min-width: 0; }
.qa-list-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s-3); padding-bottom: var(--s-3); border-bottom: 1px solid var(--line); }
.qa-list-head .lbl { margin: 0; }
.qa-list-head .th { font-family: var(--font-ui); font-size: 13px; }
.qa-list .list > li:first-child { border-top: 0; }
.qa-qa { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 auto; }
.qa-qa .li-title { font-weight: 600; overflow-wrap: anywhere; }
.qa-qa-a { color: var(--muted); font-size: var(--fs-sm); }
.qa-tags { margin-top: 2px; }
.qa-list .list-item > .ico { color: var(--muted); width: 16px; height: 16px; flex: 0 0 auto; }
.qa-acc { padding: 4px 0 12px; }
.qa-acc summary { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: 52px; cursor: pointer; list-style: none; }
.qa-acc summary::-webkit-details-marker { display: none; }
.qa-acc .chev { width: 16px; height: 16px; color: var(--muted); transition: transform 200ms var(--ease-in-out); flex: 0 0 auto; }
.qa-acc[open] .chev { transform: rotate(180deg); }
.qa-acc-a { margin: 0 0 8px; font-size: 16px; line-height: 1.65; animation: qa-drop 200ms var(--ease-out) both; }
@keyframes qa-drop { from { opacity: 0; transform: translateY(-4px); } }
.csv-table { max-height: 50dvh; overflow: auto; overscroll-behavior: contain; border: 1px solid var(--line); }
.csv-table .table td, .csv-table .table th { white-space: normal; }
.qa-del-row { padding-top: var(--s-4); border-top: 1px solid var(--line); }

.qa-list-head .gate { display: contents; }
.qa-list-head .gate-why { flex: 1 1 100%; }
/* Thai inside shared HUD components (gate switch button, mock flag) must not be letter-spaced */
main#view:has(> .qa-head) .gate-why .btn, main#view:has(> .qa-head) .mock-flag {
  font-family: var(--font-ui); letter-spacing: 0; text-transform: none;
}

/* -------------------------------------------------------------------- INBOX */
.qa-inbox-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-3); padding: var(--s-3) 4px; }
.qa-inbox-row .li-body { flex: 1 1 200px; min-width: 0; }
.qa-inbox-row .li-title { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.qa-inbox-row .li-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.qa-inbox-row .btn-sm { min-height: var(--touch); }

/* ------------------------------------------------------------------ desktop */
@media (min-width: 900px) {
  main#view:has(> .qa-head) { max-width: 720px; }
  main#view:has(> .qa-bar) { min-height: calc(100dvh - 72px); padding-bottom: 0; }
  .qa-bar { bottom: 0; margin: 0; padding: 12px var(--s-4) 14px; }
  .qa-src .th { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .sweep.run { animation: none; }
  /* fade 200ms (3.1 ข้อ 6.1) — !important duration beats style.css's global .001ms reduced-motion clamp */
  .qa-pair.in { animation: qa-fade 200ms ease both; animation-duration: 200ms !important; }
  .qa-acc-a { animation: qa-fade 200ms ease both; animation-duration: 200ms !important; }
  .qa-mic.on::before, .qa-mic.on::after { animation: none; opacity: 0; }
  .qa-play:active, .qa-send:active, .qa-mic:active { transform: none; }
}
