/* หน่วยงานทดสอบ AI - ค้นหาคลังความรู้ (chat screen)
   Figma: หน่วยงานทดสอบ (หน่วยงานทดสอบ) · canvas "for Dev" · nodes 121:198 / 423 / 646 / 835 / 1026 / 1861
   Modals: 121:1766 (like) · 121:1453 (dislike) · 121:2298 (citation) */

/* [hidden] must beat the display:flex/grid rules below */
[hidden] { display: none !important; }

/* ---------- icon sizing (explicit per size class; no global img rule) ---------- */
.ico-12 { width: 12px;  height: 12px;  display: block; }
.ico-14 { width: 14px;  height: 14px;  display: block; }
.ico-16 { width: 16px;  height: 16px;  display: block; }
.ico-18 { width: 18px;  height: 18px;  display: block; }
.ico-20 { width: 20px;  height: 20px;  display: block; }
.ico-24 { width: 24px;  height: 24px;  display: block; }

/* ---------- app shell ---------- */
.app-body {
  display: flex;
  align-items: stretch;
  height: calc(100vh - 69px);
  min-height: 0;
}

/* =========================================================
   LEFT - chat history (240px)  node 121:223
   ========================================================= */
.chat-history {
  width: 240px;
  flex: 0 0 240px;
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.ch-titlebar {
  padding: 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ch-brand {
  font-size: 12px;
  font-weight: 700;
  background: linear-gradient(to left, var(--color-02), var(--color-01));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.ch-icons { display: flex; gap: 12px; align-items: center; }
.icon-button,
.collapse-icon {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border-radius: 5px;
  color: var(--text-500);
}
.icon-button:hover, .collapse-icon:hover { background: var(--bg-chip); }
.icon-button:focus-visible, .collapse-icon:focus-visible,
.sidebar-restore:focus-visible, .model-chip:focus-visible, .model-option:focus-visible {
  outline: 2px solid var(--color-02); outline-offset: 2px;
}
.history-search {
  margin: 0 12px 4px; padding: 7px 9px;
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border-active); border-radius: 8px; background: var(--bg-white);
}
.history-search input {
  min-width: 0; width: 100%; border: 0; outline: 0; background: transparent;
  font-family: var(--font-thai); font-size: 11px; color: var(--text-700);
}
.history-search input::placeholder { color: var(--text-300); }
.ch-list { padding: 20px 12px; display: flex; flex-direction: column; gap: 8px; }
.conv-active {
  width: 100%;
  background: var(--bg-active);
  border: 1px solid var(--border-active);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-01);
  text-align: left;
}
.ch-recent-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-450);
}
.ch-recent { display: flex; flex-direction: column; min-width: 0; }
.ch-item {
  --history-accent: #5d72aa;
  position: relative; display: block; width: 100%; min-width: 0; padding: 8px 16px 8px 10px;
  border-radius: 8px; margin-top: 4px; cursor: pointer; text-align: left;
  transition: background-color .16s ease, color .16s ease;
}
.ch-item::after {
  content: ''; position: absolute; top: 9px; right: 5px; bottom: 9px; width: 4px;
  border-radius: 999px; background: var(--history-accent); opacity: .62;
}
.ch-item:nth-of-type(3n + 1) { --history-accent: #5d72aa; }
.ch-item:nth-of-type(3n + 2) { --history-accent: #9a6b9f; }
.ch-item:nth-of-type(3n) { --history-accent: #4b8c83; }
.ch-item:hover { background: color-mix(in srgb, var(--history-accent) 8%, var(--bg-white)); }
.ch-item.is-active { background: color-mix(in srgb, var(--history-accent) 12%, var(--bg-white)); }
.ch-item.is-active::after { opacity: 1; }
.ch-item-title {
  font-size: 12px; font-weight: 600; line-height: 18px; color: var(--text-700);
  height: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ch-item-sub {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 10px; line-height: 15px; color: var(--text-400);
}
.ch-item-sub { font-size: 10px; line-height: 15px; color: var(--text-500); }
.ch-footer { border-top: 1px solid var(--border); }
.ch-footer-bar {
  background: var(--bg-white);
  padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px;
}
.ch-foot-left  { font-weight: 500; color: var(--text-450); }
.ch-foot-right { color: var(--text-500); cursor: pointer; }

/* =========================================================
   CENTER - chat column  node 121:264
   ========================================================= */
.chat-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; position: relative; }
.sidebar-restore {
  position: absolute; top: 18px; z-index: 20;
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg-white);
  box-shadow: 0 4px 14px rgba(21, 44, 101, .10);
}
.sidebar-restore:hover { border-color: var(--border-active); background: var(--bg-active); }
.sidebar-restore--left { left: 14px; }
.sidebar-restore--right { right: 14px; }
@media (min-width: 769px) {
  body.left-sidebar-collapsed .chat-history { width: 0; flex-basis: 0; border-right-color: transparent; }
  body.right-sidebar-collapsed .right-sidebar { width: 0; flex-basis: 0; padding-left: 0; padding-right: 0; border-color: transparent; overflow: hidden; }
}

.chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 24px 60px;
}

/* hero (state 1) - node 121:266 */
.hero {
  width: 100%;
  max-width: 760px;
  border: 1px solid var(--border-active);
  border-radius: 16px;
  padding: 20px 24px;
  background: linear-gradient(165.6deg,
    #f0f5ff 0%, #f2f6ff 14.286%, #f4f8ff 28.571%, #f6f9ff 42.857%,
    #f9fbff 57.143%, #fbfcff 71.429%, #fdfeff 85.714%, #ffffff 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hero-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--bg-white);
  overflow: hidden;
}
.hero-icon img { width: 48px; height: 48px; display: block; object-fit: contain; }
.hero-title {
  padding-top: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-900);
  text-align: center;
  line-height: normal;
}
.hero-title .accent { color: var(--color-02); }
.hero-sub {
  margin-top: 6px;
  width: 440px;
  max-width: 440px;
  font-size: 14px;
  line-height: 22.75px;
  color: var(--text-500);
  text-align: center;
}

/* conversation (states 2 / 6) - node 121:1929 */
.conversation { width: 100%; max-width: 760px; display: flex; flex-direction: column; gap: 32px; }
.conv-block { display: flex; flex-direction: column; }
.user-row { display: flex; justify-content: flex-end; }
.user-bubble {
  background: var(--color-01);
  color: #fff;
  font-size: 14px;
  line-height: 22.75px;
  padding: 12px 16px;
  border-radius: 16px 4px 16px 16px;
  max-width: 560px;
}
.ai-row { display: flex; gap: 12px; align-items: flex-start; padding-top: 24px; }
.ai-avatar {
  width: 26px; height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  background: var(--bg-white);
  overflow: hidden;
}
.ai-avatar img { width: 26px; height: 26px; display: block; object-fit: contain; }
.ai-card {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-white);
  border: 1px solid #eef0f3;
  border-radius: 4px 16px 16px 16px;
  padding: 14px 16px;
}
.ai-card.has-sources { cursor: pointer; transition: border-color .16s ease, box-shadow .16s ease; }
.ai-card.has-sources:hover { border-color: var(--border-active); }
.ai-card.is-source-active { border-color: var(--border-active); box-shadow: 0 8px 22px rgba(21,44,101,.07); }
.ai-text p { font-size: 14px; line-height: 22.75px; color: var(--text-900); }
.ai-cite { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--bg-chip); }
.ai-cite-label { font-size: 11px; font-weight: 700; line-height: 16.5px; color: var(--text-500); }
.ai-cite-chips { display: flex; gap: 6px; padding-top: 6px; }
.cite-chip {
  background: var(--bg-active);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  line-height: 16.5px;
  color: var(--color-01);
}
.cite-chip:hover { background: var(--border-active); }
.cite-chip { text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 8px;
}
.ai-foot-l { display: flex; gap: 12px; align-items: center; }
.fb-btn { display: flex; padding: 0; }
.fb-btn:hover { opacity: .6; }
.ai-foot-hint { font-size: 11px; color: var(--text-500); }
.copy-btn { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; color: var(--text-500); }

/* input area - node 121:300 */
.input-area {
  background: var(--bg-white);
  border: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.input-form {
  background: var(--bg-chip);
  border-radius: 9px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.input-left { display: flex; gap: 12px; align-items: center; height: 21px; padding: 0 12px; flex: 1 1 auto; min-width: 0; }
.chat-input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: none;
  outline: none;
  font-size: 14px;
  color: var(--text-900);
}
.chat-input::placeholder { color: var(--text-400); }
.input-right { display: flex; gap: 12px; align-items: center; }
.model-picker { position: relative; }
.model-chip {
  display: flex; gap: 12px; align-items: center;
  height: 21px; padding: 0 12px;
  font-size: 14px; color: var(--text-500);
}
.model-chip[aria-expanded="true"] { color: var(--color-01); }
.model-menu {
  position: absolute; right: 0; bottom: calc(100% + 10px); z-index: 80;
  width: 280px; padding: 8px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg-white);
  box-shadow: 0 16px 40px rgba(15, 23, 42, .16);
}
.model-menu-title { padding: 5px 8px 7px; font-size: 11px; font-weight: 700; color: var(--text-500); }
.model-option {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 10px; border-radius: 8px; text-align: left; color: var(--text-700);
}
.model-option:hover { background: var(--bg-chip); }
.model-option.is-selected { background: var(--bg-active); color: var(--color-01); }
.model-option > span:first-child { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.model-option b { font-size: 12px; line-height: 16px; }
.model-option small { font-size: 10px; line-height: 14px; font-weight: 400; color: var(--text-450); }
.model-check { visibility: hidden; font-weight: 700; }
.model-option.is-selected .model-check { visibility: visible; }
.send-btn {
  width: 34px; height: 34px;
  border-radius: 17px;
  background: var(--color-01);
  display: flex; align-items: center; justify-content: center;
}
.input-meta { display: flex; align-items: center; justify-content: space-between; }
.input-meta-left { display: flex; gap: 6px; align-items: center; }
.input-meta p, .input-meta-right { font-size: 11px; color: var(--text-500); }

/* =========================================================
   RIGHT - sources sidebar (420px)  node 121:318
   ========================================================= */
.right-sidebar {
  width: 420px;
  flex: 0 0 420px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
}
.rs-top { display: flex; flex-direction: column; gap: 16px; }

.rs-header { display: flex; align-items: center; justify-content: space-between; }
.rs-header-left { display: flex; gap: 8px; align-items: center; }
.rs-title { font-size: 14px; font-weight: 700; color: var(--text-900); }
.rs-badge {
  background: var(--bg-chip);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-500);
}
/* ===== AI semantic doc search ===== */
.ai-search {
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(150deg, #f0f5ff 0%, #ffffff 55%, #fff6f1 100%);
  border: 1px solid var(--border-active);
}
.ai-search-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ai-search-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; color: var(--color-01);
}
.ai-search-badge svg { color: var(--color-02); flex-shrink: 0; }
.ai-search-sub { font-size: 10px; color: var(--text-450); white-space: nowrap; }
.ai-search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 4px 4px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.ai-search-box:focus-within {
  border-color: var(--color-01);
  box-shadow: 0 0 0 3px rgba(21, 44, 101, .10);
}
.ai-search-box input {
  flex: 1 1 auto; min-width: 0;
  border: none; background: none; outline: none;
  font-family: var(--font-thai);
  font-size: 12px; font-weight: 500; color: var(--text-700);
  padding: 7px 0;
}
.ai-search-box input::placeholder { color: var(--text-300); font-weight: 400; }
.ai-search-go {
  width: 30px; height: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--color-01); color: #fff;
}
.ai-search-go:hover { background: #1d3a80; }
.ai-search-hints { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ai-search-hints .hint-label { font-size: 10px; color: var(--text-450); align-self: center; }
.ai-hint {
  font-family: var(--font-thai);
  font-size: 10.5px; font-weight: 600; color: var(--text-600);
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}
.ai-hint:hover { border-color: var(--color-02); color: var(--color-02); }
.ai-searching {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-500);
  padding: 8px 2px 0;
}
.ai-searching[hidden] { display: none; }
.ai-searching .spin {
  width: 12px; height: 12px; flex-shrink: 0;
  border: 2px solid var(--border); border-top-color: var(--color-02);
  border-radius: 50%;
  animation: aiSearchSpin .7s linear infinite;
}
@keyframes aiSearchSpin { to { transform: rotate(360deg); } }

/* คำถามที่พบบ่อย - ปุ่มคำถาม (อยู่ในฮีโร่ กลางหน้าจอ) */
.faq-item {
  width: 100%;
  background: var(--bg-app);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  text-align: left;
}
.faq-item:hover { background: var(--bg-active); }
.faq-item-l { display: flex; gap: 8px; align-items: center; }
.spark { font-size: 14px; font-weight: 500; line-height: 21px; color: var(--color-02); }
.faq-item-t { font-size: 14px; font-weight: 500; line-height: 21px; color: var(--color-01); }
.arrow { font-size: 14px; font-weight: 500; line-height: 21px; color: var(--color-02); }

/* หมวดหมู่เอกสาร - การ์ดกะทัดรัด 5 แถว (แทนการ์ดหมวดขนาดใหญ่เดิม) */
.cat-list {
  order: 2;
  background: var(--bg-white); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px;
}
.cat-list-head { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.cat-list-title { font-size: 13px; font-weight: 700; color: var(--text-900); }
.cat-list-chev {
  margin-left: auto; display: flex; align-items: center; justify-content: center;
  color: var(--color-01); transition: transform .15s ease;
}
.cat-list.is-collapsed .cat-list-chev { transform: rotate(-90deg); }
.cat-list-body { padding-top: 6px; }
.cat-list.is-collapsed .cat-list-body { display: none; }
.cat-row {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 5px; border-radius: 6px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.cat-row:last-child { border-bottom: none; }
.cat-row:hover { background: var(--bg-active); }
.cat-row-name { font-size: 12.5px; font-weight: 600; color: var(--text-700); line-height: 18px; }
.cat-row-n { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--text-500); }
.cat-row-chev { display: flex; align-items: center; justify-content: center; color: var(--text-400); }
.cat-row:hover .cat-row-name { color: var(--color-01); }
.cat-row:hover .cat-row-chev { color: var(--color-01); }

/* document result cards - node 121:781 … (states 4 / 5) */
.doc-results { display: flex; flex-direction: column; gap: 16px; order: 2; }
.doc-search-state {
  padding: 22px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  background: #fff;
}
.doc-search-state.is-busy::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--orange);
  animation: apiPulse 1s ease-in-out infinite;
}
.doc-source-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--navy);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
}
.doc-source-link:hover { text-decoration: underline; }
.ch-empty { padding: 6px 10px; color: var(--text-muted); font-size: 11px; }
.scope-selected { display: grid; gap: 6px; margin-top: 10px; }
.scope-selected-item { display: block; overflow: hidden; padding: 6px 8px; border: 1px solid #dbe6e3; border-radius: 7px; background: #f7fbfa; color: var(--navy); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.scope-clear { width: 100%; margin-top: 10px; padding: 7px 10px; border: 1px solid #d9a36b; border-radius: 7px; background: #fffaf3; color: #8a4c12; font: inherit; font-size: 11px; cursor: pointer; }
.scope-clear:hover { background: #fff2df; }
.corpus-card { border-style: dashed; }
.corpus-copy { margin: 10px 0 0; color: var(--text-muted); font-size: 12px; line-height: 1.65; }
.input-meta-actions { display: flex; align-items: center; gap: 10px; }
.api-settings-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 9px;
  background: #fff;
  color: var(--text-muted);
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}
.api-settings-btn.is-online { border-color: #86c7aa; color: #18724d; background: #effbf5; }
.ai-stream-status { margin-top: 10px; color: var(--text-muted); font-size: 11px; }
.ai-card.is-streaming { border-color: #b9cceb; }
.ai-card.has-error { border-color: #f0aaa0; background: #fff8f6; }
.send-btn:disabled { opacity: .5; cursor: wait; }
@keyframes apiPulse { 0%, 100% { opacity: .3; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }
.doc-card {
  background: var(--bg-white);
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.02));
}
.doc-head { display: flex; align-items: center; justify-content: space-between; }
.doc-head-l { display: flex; gap: 6px; align-items: center; min-width: 0; }
.doc-check {
  width: 16px; height: 16px;
  border: 1px solid var(--color-01);
  border-radius: 4px;
  display: block;
  cursor: pointer;
  position: relative;
}
.doc-check .check-on { display: none; position: absolute; top: -1px; left: -1px; }
.doc-card.is-checked .doc-check { border-color: transparent; }
.doc-card.is-checked .doc-check .check-on { display: block; }
.doc-pct { flex: 0 0 auto; }
.doc-kind { font-size: 10px; font-weight: 600; color: var(--text-450); white-space: nowrap; }
.doc-pct { font-size: 15px; font-weight: 700; line-height: 27px; color: var(--color-01); }
.doc-pct.is-green { color: var(--success-700); }
.doc-body { display: flex; flex-direction: column; gap: 4px; }
.doc-title {
  font-size: 12px; font-weight: 700; color: var(--color-01);
  height: 20px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.doc-desc {
  font-size: 12px; line-height: 18px; color: var(--text-500);
  height: 54px; overflow: hidden;
}

/* =========================================================
   MODALS
   ========================================================= */
.overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.modal {
  background: var(--bg-white);
  border-radius: 16px;
  box-shadow: 0 12px 24px rgba(0,0,0,.13);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal--feedback { width: 740px; max-height: calc(100vh - 62px); }
.modal--citation { width: 1240px; max-height: calc(100vh - 120px); }

.modal-head {
  background: var(--color-01);
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between;
  flex: 0 0 auto;
}
.modal-head--tall { padding: 20px 24px; }
.modal-head-l { display: flex; gap: 14px; align-items: center; }
.icon-badge {
  background: rgba(255,255,255,.1);
  border-radius: 8px;
  padding: 10px;
  display: flex; align-items: center; justify-content: center;
}
.modal-head-text { display: flex; flex-direction: column; gap: 2px; }
.modal-title { font-size: 18px; font-weight: 600; color: #fff; }
.modal-sub { font-size: 12px; color: rgba(255,255,255,.7); }
.modal-close { padding: 4px; border-radius: 4px; display: flex; }
.modal-close:hover { background: rgba(255,255,255,.12); }

.modal-body {
  padding: 24px;
  display: flex; flex-direction: column; gap: 20px;
  overflow-y: auto;
}
.modal-foot {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between;
  flex: 0 0 auto;
}
.btn-cancel { padding: 10px 20px; font-size: 14px; font-weight: 600; color: var(--text-500); }
.btn-submit {
  background: var(--color-01);
  border-radius: 8px;
  padding: 10px 20px;
  display: flex; gap: 8px; align-items: center;
  font-size: 14px; font-weight: 600; color: #fff;
}

/* --- feedback modal body --- */
.q-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.q-label { font-size: 12px; font-weight: 500; color: var(--text-500); }
.q-row { display: flex; align-items: center; justify-content: space-between; }
.q-text { font-size: 14px; font-weight: 600; line-height: 20px; color: #1e293b; }
.q-chev { display: flex; transform: rotate(180deg); }
.q-answer p { font-size: 14px; line-height: 22.75px; color: var(--text-900); }

.fb-section { display: flex; flex-direction: column; gap: 10px; }
.fb-section[hidden] { display: none; }
.fb-label { font-size: 14px; font-weight: 600; color: #1e293b; }

.sat-buttons { display: flex; gap: 12px; }
.sat-btn {
  flex: 1 1 0;
  min-width: 0;
  border-radius: 10px;
  padding: 12px 16px;
  display: flex; gap: 8px; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500;
  background: var(--bg-white);
  border: 1px solid var(--border);
  color: var(--text-500);
}
.sat-btn .sat-ico-on { display: none; }
.sat-up.is-active {
  background: var(--success-bg); border: 1.5px solid var(--success-600); color: var(--success-700); font-weight: 600;
}
.sat-down.is-active {
  background: rgba(252,65,61,.08); border: 1px solid #fc413d; color: var(--danger-700);
}
.sat-btn.is-active .sat-ico-on  { display: block; }
.sat-btn.is-active .sat-ico-off { display: none; }
/* dislike state: inactive thumbs-up keeps the 1.5px neutral border per Figma 121:1478 */
.modal--feedback.is-dislike .sat-up { background: none; border: 1.5px solid var(--border); font-weight: 600; }

.stars-row { display: flex; gap: 12px; align-items: center; }
.stars { display: flex; gap: 6px; }
.star { display: flex; width: 24px; height: 24px; }
.stars-label { font-size: 14px; font-weight: 600; color: #1e293b; }

.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt-row {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  text-align: left;
}
.opt-txt { display: flex; flex-direction: column; justify-content: center; }
.opt-t { font-size: 13px; font-weight: 500; color: #1e293b; }
.opt-s { font-size: 13px; font-weight: 500; color: var(--text-500); }
.opt-box {
  width: 18px; height: 18px;
  flex: 0 0 18px;
  border: 1px solid var(--text-500);
  border-radius: 4px;
  position: relative;
}
.opt-row.is-checked .opt-box { background: var(--color-01); border-color: var(--color-01); }
.opt-row.is-checked .opt-box::after {
  content: "";
  position: absolute; left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.fb-textarea {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  height: 100px;
  resize: none;
  outline: none;
  font-size: 13px;
  line-height: 20px;
  color: var(--text-900);
}
.fb-textarea::placeholder { color: var(--text-500); }

.meta-card {
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.meta-sender { font-size: 11px; color: var(--text-500); }
.meta-sender b { font-weight: 600; color: #1e293b; }
.meta-secure { display: flex; gap: 4px; align-items: center; }
.meta-secure p { font-size: 11px; color: var(--text-500); }

/* --- citation modal --- */
.nav-bar {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
  flex: 0 0 auto;
}
.tabs { display: flex; gap: 8px; align-items: center; }
.tab {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex; gap: 8px; align-items: center;
  font-size: 13px; font-weight: 500; color: #1e293b;
}
.tab--active { background: var(--color-01); border-color: var(--color-01); color: #fff; font-weight: 600; }
.paginator { display: flex; gap: 12px; align-items: center; }
.pg-word { font-size: 13px; color: var(--text-500); }
.pg-controls {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex; gap: 10px; align-items: center;
}
.pg-btn { display: flex; width: 12px; height: 12px; align-items: center; justify-content: center; overflow: hidden; }
.pg-numbers { display: flex; gap: 4px; align-items: center; font-size: 13px; }
.pg-numbers b { font-weight: 700; color: #1e293b; }
.pg-numbers span { color: var(--text-500); }

.canvas {
  background: var(--bg-chip);
  padding: 24px;
  display: flex; flex-direction: column; align-items: center;
  overflow-y: auto;
}
.doc-container {
  width: 100%;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  display: flex; flex-direction: column; gap: 24px;
}
.doc-header-row { display: flex; align-items: flex-start; justify-content: space-between; }
.doc-title-block { display: flex; flex-direction: column; gap: 6px; }
.dc-title { font-size: 18px; font-weight: 700; color: #1e293b; }
.dc-sub { font-size: 13px; color: var(--text-500); }
.dl-btn {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex; gap: 6px; align-items: center;
  font-size: 13px; font-weight: 600; color: #1e293b;
}
.page-box {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
}
.pdf-page-wrap {
  display: flex; justify-content: center; align-items: flex-start;
  min-height: 620px; max-height: 66vh; overflow: auto;
  padding: 18px; border: 1px solid var(--border); border-radius: 8px; background: #e8edf5;
}
.pdf-page-image {
  display: block; width: min(100%, 1120px); height: auto; background: #fff;
  box-shadow: 0 8px 24px rgba(15, 35, 73, .16);
}
.pb-title { font-size: 15px; font-weight: 700; color: #1e293b; }
.pb-text, .pb-text p { font-size: 14px; line-height: 1.6; color: #1e293b; }
.pb-strong { font-weight: 600; }
.excerpt-box {
  background: #fffbeb;
  border: 1px solid #fef3c7;
  border-radius: 6px;
  padding: 16px;
}
.excerpt-box p { font-size: 14px; line-height: 1.6; color: #b45309; }
.excerpt-box b { font-weight: 700; }

.foot-left { display: flex; gap: 8px; align-items: center; }
.foot-label { font-size: 13px; color: var(--text-500); }
.cite-pill {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px; font-weight: 500; color: #1e293b;
}
.foot-right { display: flex; gap: 12px; align-items: center; }
.copy-cite-btn {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  display: flex; gap: 8px; align-items: center;
  font-size: 13px; font-weight: 600; color: #1e293b;
}
.close-win-btn {
  background: var(--color-01);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px; font-weight: 700; color: #fff;
}

/* =========================================================
   ===== S2 / S3 / S4 / S12 UPGRADE =====
   ========================================================= */

/* ---------- toast (shell.js) ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: var(--color-01); color: #fff; font-size: 13px; font-weight: 500;
  padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: all .2s ease; z-index: 300; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- hamburger (mobile only) ---------- */
.hamburger { display: none; padding: 6px; margin-right: 2px; border-radius: 8px; }
.hamburger:hover { background: var(--bg-chip); }

/* ---------- file-type badges ---------- */
.ft {
  display: inline-block; border-radius: 4px; padding: 1px 6px;
  font-size: 10px; font-weight: 700; line-height: 15px; letter-spacing: .2px;
}
.ft--pdf   { background: #fee2e2; color: #b91c1c; }
.ft--word  { background: #dbeafe; color: #1d4ed8; }
.ft--excel { background: #dcfce7; color: #15803d; }
.ft--csv   { background: #fef3c7; color: #b45309; }

/* =========================================================
   HERO - คำถามที่พบบ่อย (หลัก) + ชุดสาธิตระบบ (รอง)
   ========================================================= */
.hero-faq { width: 100%; margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border-active); }
.hero-faq-title { font-size: 13px; font-weight: 700; color: var(--color-01); text-align: center; }
.hero-faq-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px;
}
.hero-faq .faq-item { padding: 11px 14px; gap: 8px; }
.hero-faq .faq-item-l { align-items: flex-start; }
.hero-faq .faq-item-t { font-size: 13px; line-height: 19px; }
.hero-faq .arrow { flex: 0 0 auto; align-self: center; }

/* ชุดสาธิตระบบ - แถวรอง ตัวอักษรเล็กและสีจางกว่าคำถามที่พบบ่อย */
.sugg {
  width: 100%; margin-top: 12px; padding-top: 10px;
  border-top: 1px dashed var(--border-active);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.sugg-label { flex: 0 0 auto; font-size: 10.5px; font-weight: 700; color: var(--text-450); }
.sugg-grid { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.sugg-chip {
  flex: 1 1 220px;
  background: none; border: 1px dashed var(--border); border-radius: 8px;
  padding: 5px 10px; display: flex; gap: 6px; align-items: center; text-align: left;
  font-size: 11px; line-height: 16px; font-weight: 500; color: var(--text-500);
}
.sugg-chip:hover { background: var(--bg-white); border-color: var(--color-01); color: var(--color-01); }
.sugg-chip .spark { flex: 0 0 auto; font-size: 11px; line-height: 16px; color: var(--text-400); }
.sugg-chip:hover .spark { color: var(--color-02); }
.sugg-chip--test { border-style: dashed; border-color: var(--border); }
.sugg-tag {
  margin-left: auto; flex: 0 0 auto; align-self: center;
  background: var(--bg-chip); color: var(--text-500); border-radius: 4px;
  padding: 1px 6px; font-size: 9.5px; font-weight: 700;
}

/* =========================================================
   RIGHT SIDEBAR - ขอบเขตการค้นหา (scope filter card)
   Lives in the sources panel, below the doc search bar / above หมวดหมู่เอกสาร.
   On mobile the same node is teleported into #scopeSheetMount.
   ========================================================= */
.chat-history { overflow-y: auto; }
.scope {
  order: 0;
  background: var(--bg-white); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px;
}
.scope-head { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.scope-title { font-size: 13px; font-weight: 700; color: var(--text-900); }
.scope-count {
  background: var(--bg-active); color: var(--color-01); border-radius: 4px;
  padding: 1px 6px; font-size: 10px; font-weight: 700;
}
.scope-chev { margin-left: auto; display: flex; align-items: center; justify-content: center; transition: transform .15s ease; }
.scope.is-collapsed .scope-chev { transform: rotate(-90deg); }
.scope-body { padding-top: 12px; }
.scope.is-collapsed .scope-body { display: none; }
.scope-category-rows { max-height: 228px; overflow-y: auto; padding-right: 3px; scrollbar-width: thin; }
.scope-loading { padding: 8px 2px; font-size: 10px; color: var(--text-450); }
.scope-sub { font-size: 10.5px; font-weight: 700; color: var(--text-450); padding: 4px 0 6px; text-transform: uppercase; letter-spacing: .2px; }
.scope-sub--yr { padding-top: 12px; }
.scope-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 5px; border-radius: 6px; cursor: pointer;
}
.scope-row:hover { background: var(--bg-active); }
.scope-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.scope-box {
  width: 15px; height: 15px; flex: 0 0 15px; border: 1.5px solid var(--text-400);
  border-radius: 4px; position: relative; background: #fff;
}
.scope-row input:checked + .scope-box { background: var(--color-01); border-color: var(--color-01); }
.scope-row input:checked + .scope-box::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 9px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.scope-row input:focus-visible + .scope-box { outline: 2px solid var(--color-02); outline-offset: 1px; }
.scope-txt { font-size: 12px; font-weight: 500; color: var(--text-700); line-height: 18px; }
.scope-n { margin-left: auto; font-size: 10.5px; color: var(--text-500); }
.scope-years { display: flex; align-items: center; gap: 6px; }
.scope-select {
  flex: 1 1 0; min-width: 0; font-family: var(--font-thai); font-size: 12px; font-weight: 500;
  color: var(--text-700); background: #fff; border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 7px; cursor: pointer;
}
.scope-dash { font-size: 12px; color: var(--text-500); }
.scope-hint { margin-top: 9px; font-size: 11px; line-height: 16px; color: var(--text-500); }

/* the same #scope node renders inside the mobile sheet - drop its own card chrome there.
   The sheet always shows the full body, even if the desktop panel was auto-collapsed
   by the answer state (สถานะ B). */
#scopeSheetMount .scope { border: none; border-radius: 0; padding: 0; }
#scopeSheetMount .scope.is-collapsed .scope-body { display: block; }

/* mobile-only trigger button (left drawer) that opens the scope sheet */
.mobile-scope-btn { display: none; }

/* =========================================================
   ANSWER - confidence bar, sentence citations, [คำนวณ]
   ========================================================= */
.conf {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border-radius: 8px; padding: 7px 10px; margin-bottom: 12px;
  font-size: 11px; font-weight: 600;
}
.conf-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }
.conf-meter { width: 68px; height: 5px; border-radius: 3px; background: rgba(15,23,42,.1); overflow: hidden; }
.conf-meter i { display: block; height: 100%; border-radius: 3px; }
.conf-pct { min-width: 34px; font-variant-numeric: tabular-nums; }
.conf-count { font-weight: 500; }
.conf-warn { margin-left: auto; font-weight: 600; color: #b45309; cursor: help; }
.conf.is-high  { background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857; }
.conf.is-high  .conf-dot, .conf.is-high  .conf-meter i { background: var(--success-600); }
.conf.is-check { background: #fffbeb; border: 1px solid #fde68a; color: #b45309; }
.conf.is-check .conf-dot, .conf.is-check .conf-meter i { background: #f59e0b; }
.conf.is-none  { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.conf.is-none  .conf-dot { background: var(--danger-600); }
.conf.is-none  .conf-meter i { background: var(--danger-600); }

.ai-h { font-size: 14px; font-weight: 700; line-height: 22.75px; color: var(--text-900); }
.ai-body { font-size: 14px; line-height: 25px; color: var(--text-900); white-space: pre-line; }
.ai-card.is-revealing .sent { opacity: 0; }
.sent { transition: opacity .3s ease, background-color .15s ease; border-radius: 3px; }
.ai-card.is-revealing .sent.on { opacity: 1; }
.sent.is-lit { background: #fff3cd; box-shadow: 0 0 0 2px #fff3cd; }
.sent--warn { background: #fffbeb; box-shadow: 0 0 0 2px #fffbeb; }

.cmark {
  display: inline-block; vertical-align: super; margin-left: 2px;
  min-width: 15px; height: 15px; line-height: 15px; padding: 0 3px;
  border-radius: 4px; background: var(--bg-active); border: 1px solid var(--border-active);
  color: var(--color-01); font-size: 9.5px; font-weight: 700; text-align: center;
  cursor: pointer; user-select: none;
}
.cmark:hover, .cmark:focus { background: var(--color-01); border-color: var(--color-01); color: #fff; outline: none; }
.cmark--warn { background: #fef3c7; border-color: #fcd34d; color: #b45309; }
.cmark--warn:hover, .cmark--warn:focus { background: #f59e0b; border-color: #f59e0b; color: #fff; }

.calc-line {
  margin-top: 10px; background: #f8fafc; border: 1px solid var(--border);
  border-left: 3px solid var(--color-02); border-radius: 8px; padding: 8px 12px;
  font-size: 13.5px; line-height: 21px; color: var(--text-900);
}
.calc-val { font-weight: 700; color: var(--color-01); }
.calc-chip {
  display: inline-block; margin-left: 6px; vertical-align: middle;
  background: #fff2ec; border: 1px solid #f9c8b3; border-radius: 5px;
  padding: 1px 7px; font-size: 10.5px; font-weight: 700; color: var(--color-02);
}
.calc-chip::before { content: "["; }
.calc-chip::after  { content: "]"; }
.calc-chip:hover { background: var(--color-02); border-color: var(--color-02); color: #fff; }

.calc-pop {
  position: fixed; z-index: 260; background: #fff; border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 16px 40px rgba(15,23,42,.18); padding: 14px 16px;
}
.calc-pop[hidden] { display: none; }
.calc-head { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.calc-badge { background: #fff2ec; border: 1px solid #f9c8b3; border-radius: 5px; padding: 1px 7px; font-size: 10.5px; font-weight: 700; color: var(--color-02); }
.calc-title { font-size: 13px; font-weight: 700; color: var(--text-900); }
.calc-close { margin-left: auto; font-size: 13px; color: var(--text-500); padding: 2px 4px; }
.calc-rows { padding: 10px 0 6px; display: flex; flex-direction: column; gap: 6px; }
.calc-row { display: flex; gap: 10px; align-items: baseline; }
.calc-src { flex: 1 1 auto; font-size: 11.5px; line-height: 17px; color: var(--text-600); }
.calc-num { flex: 0 0 auto; font-size: 12.5px; font-weight: 700; color: var(--text-900); font-variant-numeric: tabular-nums; }
.calc-row--sum { border-top: 1px solid var(--border); padding-top: 6px; }
.calc-row--sum .calc-src { font-weight: 700; color: var(--text-900); }
.calc-row--sum .calc-num { color: var(--color-02); }
.calc-formula {
  background: var(--bg-chip); border-radius: 6px; padding: 7px 10px;
  font-size: 12px; font-weight: 600; color: var(--text-700); text-align: center;
}
.calc-foot { margin-top: 8px; font-size: 10.5px; line-height: 16px; color: var(--text-450); }

/* answer footer additions */
.ai-foot-r { display: flex; gap: 12px; align-items: center; }
.report-btn { font-size: 11px; font-weight: 500; color: var(--text-500); text-decoration: underline; text-underline-offset: 2px; }
.report-btn:hover { color: var(--color-02); }
.export-btn { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; color: var(--text-500); }
.export-btn:hover, .copy-btn:hover { color: var(--color-01); }

/* mobile-only "แหล่งอ้างอิง (n)" pill */
.src-pill { display: none; }

/* =========================================================
   STREAMING STATE
   ========================================================= */
.ai-card--stream { display: flex; flex-direction: column; gap: 10px; }
.stream-step { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--text-500); }
.stream-step.is-wait { opacity: .4; }
.stream-step.is-done { color: #047857; }
.stream-step .spin {
  width: 13px; height: 13px; flex: 0 0 13px; border-radius: 50%;
  border: 2px solid var(--border-active); border-top-color: var(--color-01);
  animation: spin .7s linear infinite;
}
.stream-step.is-wait .spin { animation: none; border-top-color: var(--border-active); }
.stream-step .tick { width: 13px; flex: 0 0 13px; text-align: center; font-weight: 700; color: var(--success-700); }
@keyframes spin { to { transform: rotate(360deg); } }
.stream-scope {
  background: var(--bg-chip); border-radius: 6px; padding: 5px 9px;
  font-size: 10.5px; font-weight: 500; color: var(--text-500); align-self: flex-start;
}

/* =========================================================
   S3 ABSTAIN CARD
   ========================================================= */
.ai-card--abstain { border-color: #fecaca; }
.ab-head { display: flex; gap: 10px; align-items: flex-start; }
.ab-icon {
  width: 22px; height: 22px; flex: 0 0 22px; border-radius: 50%;
  background: #fee2e2; color: #b91c1c; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.ab-title { font-size: 14px; font-weight: 700; color: var(--text-900); line-height: 21px; }
.ab-sub { font-size: 12.5px; line-height: 19px; color: var(--text-500); }
.ab-reason {
  margin-top: 12px; background: #fff8f8; border: 1px solid #fecaca;
  border-radius: 8px; padding: 10px 14px;
}
.ab-reason-t { font-size: 11.5px; font-weight: 700; color: #b91c1c; }
.ab-reason ul { margin: 6px 0 0 16px; }
.ab-reason li { font-size: 12.5px; line-height: 20px; color: var(--text-700); }
.ab-reason b { font-weight: 700; color: #b91c1c; }
.ab-sec { margin-top: 14px; }
.ab-sec-t { font-size: 11.5px; font-weight: 700; color: var(--text-450); margin-bottom: 7px; }
.ab-sec-note { font-weight: 500; color: var(--text-500); }
.ab-near { display: flex; flex-direction: column; gap: 7px; }
.ab-near-btn {
  width: 100%; background: var(--bg-active); border: 1px solid var(--border-active);
  border-radius: 10px; padding: 10px 13px; display: flex; align-items: center; gap: 8px;
  text-align: left; font-size: 13px; font-weight: 500; color: var(--color-01); line-height: 20px;
}
.ab-near-btn:hover { background: #e3edff; border-color: var(--color-01); }
.ab-near-btn .arrow { margin-left: auto; }
.ab-docs { display: flex; flex-direction: column; gap: 8px; }
.ab-doc {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--bg-white); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px;
}
.ab-doc-l { flex: 1 1 auto; min-width: 0; }
.ab-doc-name {
  font-size: 12.5px; font-weight: 700; color: var(--text-900); line-height: 19px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ab-doc-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding-top: 3px; }
.ab-doc-meta span { font-size: 10.5px; color: var(--text-450); }
.ab-filetype { color: var(--color-02) !important; font-weight: 700; }
.ab-doc-why { padding-top: 4px; font-size: 11.5px; line-height: 17px; color: var(--text-500); }
.ab-doc-r { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
.ab-pct { font-size: 14px; font-weight: 700; color: #b45309; }
.ab-doc-open { border: 1px solid var(--color-01); border-radius: 6px; padding: 5px 8px; color: var(--color-01); font-size: 10.5px; font-weight: 700; white-space: nowrap; }
.ab-doc-open:hover { background: var(--bg-active); }
.ab-related-state { padding: 10px 12px; border: 1px dashed var(--border-active); border-radius: 8px; color: var(--text-500); font-size: 11.5px; }
.ab-report {
  margin-top: 14px; width: 100%; background: var(--color-01); border-radius: 8px;
  padding: 10px 16px; font-size: 13px; font-weight: 600; color: #fff;
}
.ab-report:hover { background: #0f2350; }

/* =========================================================
   RIGHT PANEL - แหล่งอ้างอิงของคำตอบ
   ========================================================= */
.ans-src {
  order: 0;
  background: var(--bg-active); border: 1px solid var(--border-active);
  border-radius: 12px; padding: 12px;
}
.ans-src-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ans-src-title { font-size: 13px; font-weight: 700; color: var(--color-01); }
.ans-src-hint { font-size: 10px; color: var(--text-450); }
.ans-src-list { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }

/* ===== สถานะ B - มีคำตอบแล้ว: แหล่งอ้างอิงของคำตอบเป็นพระเอก
   ส่วนช่องค้นเอกสารด้วย AI ย่อลง (ซ่อนคำใบ้และคำอธิบายย่อย) ===== */
.right-sidebar.has-answer .ai-search { padding: 10px 12px; }
.right-sidebar.has-answer .ai-search-head { margin-bottom: 8px; }
.right-sidebar.has-answer .ai-search-sub { display: none; }
.right-sidebar.has-answer .ai-search-hints { display: none; }

.cite-card {
  background: var(--bg-white); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; cursor: pointer; transition: box-shadow .15s ease, border-color .15s ease;
}
.cite-card:hover { border-color: var(--border-active); }
.cite-card.is-selected { border-color: var(--color-01); background: #f8fbff; box-shadow: inset 0 0 0 1px rgba(28, 59, 125, .08); }
.cite-card.is-hit {
  border-color: var(--color-02);
  box-shadow: 0 0 0 3px rgba(236,89,36,.18);
}
.cc-top { display: flex; gap: 8px; align-items: flex-start; }
.cc-num {
  width: 18px; height: 18px; flex: 0 0 18px; border-radius: 5px;
  background: var(--color-01); color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.cite-card.is-hit .cc-num { background: var(--color-02); }
.cc-name {
  flex: 1 1 auto; min-width: 0; font-size: 12.5px; font-weight: 700; line-height: 18px;
  color: var(--text-900);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cc-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; min-width: 0; padding: 7px 0 0 26px; }
.cc-id, .cc-pos { font-size: 10.5px; color: var(--text-450); }
.cc-id {
  display: block; min-width: 0; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cc-pos { font-weight: 600; color: var(--text-600); }
.cc-quote {
  margin: 8px 0 0 26px; background: #fffbeb; border-left: 3px solid #fcd34d;
  border-radius: 0 6px 6px 0; padding: 8px 10px;
  font-size: 11.5px; color: #7c4a03;
}
.cc-quote-t {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 19px; max-height: 57px;
}
.cc-foot { display: flex; align-items: center; gap: 8px; padding: 10px 0 0 26px; }
.cc-rel { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; min-width: 0; }
.cc-bar { width: 46px; height: 5px; border-radius: 3px; background: var(--bg-chip); overflow: hidden; flex: 0 0 46px; }
.cc-bar i { display: block; height: 100%; background: var(--success-600); border-radius: 3px; }
.cc-pct { font-size: 12px; font-weight: 700; color: var(--success-700); }
.cc-rel-l { font-size: 10px; color: var(--text-500); }
.cc-open {
  flex: 0 0 auto; background: var(--bg-white); border: 1px solid var(--color-01);
  border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: 600; color: var(--color-01);
}
.cc-open:hover { background: var(--color-01); color: #fff; }
.cc-select { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; border: 1px solid var(--border-active); border-radius: 6px; padding: 4px 8px; color: var(--color-01); font-size: 10.5px; font-weight: 700; white-space: nowrap; }
.cc-select:hover { background: #eaf1ff; border-color: var(--color-01); }
.cc-select-mark { display: grid; place-items: center; width: 12px; height: 12px; border: 1.5px solid currentColor; border-radius: 3px; }
.cc-select[aria-pressed="true"] { border-color: var(--color-01); background: var(--color-01); color: #fff; }
.cc-select[aria-pressed="true"] .cc-select-mark::after { content: ""; width: 5px; height: 3px; border-left: 1.5px solid #fff; border-bottom: 1.5px solid #fff; transform: rotate(-45deg) translateY(-1px); }

/* =========================================================
   S4 SOURCE VIEWER - TOC, in-doc search, Excel table
   ========================================================= */
.nav-bar-r { display: flex; gap: 16px; align-items: center; }
.doc-find {
  display: flex; gap: 7px; align-items: center;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
.doc-find input {
  width: 150px; border: none; background: none; outline: none;
  font-size: 12.5px; color: var(--text-900);
}
.doc-find input::placeholder { color: var(--text-400); }
.doc-find-n { font-size: 10.5px; font-weight: 600; color: var(--color-02); white-space: nowrap; }

.viewer { display: flex; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.toc {
  width: 236px; flex: 0 0 236px; background: var(--bg-white);
  border-right: 1px solid var(--border); padding: 16px 14px; overflow-y: auto;
}
.toc-label { font-size: 11px; font-weight: 700; color: var(--text-450); margin-bottom: 8px; }
.toc-list { display: flex; flex-direction: column; gap: 3px; }
.toc-item {
  width: 100%; display: flex; gap: 8px; align-items: baseline; text-align: left;
  border-radius: 7px; padding: 8px 9px; font-size: 12px; line-height: 18px; color: var(--text-700);
}
.toc-item:hover { background: var(--bg-chip); }
.toc-item.is-on { background: var(--bg-active); color: var(--color-01); font-weight: 700; }
.toc-t { flex: 1 1 auto; min-width: 0; }
.toc-p { flex: 0 0 auto; font-size: 10.5px; color: var(--text-500); }
.toc-item.is-on .toc-p { color: var(--color-01); }
.toc-meta { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.tm-row { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; font-size: 10.5px; color: var(--text-450); }
.tm-row b { font-weight: 600; color: var(--text-700); text-align: right; }
.canvas { flex: 1 1 auto; min-width: 0; }
.dc-title { overflow: hidden; text-overflow: ellipsis; }
.pb-text mark, .pb-title mark, .ex-t mark, .xls-tbl mark {
  background: #fde68a; color: #78350f; border-radius: 2px; padding: 0 1px;
}
.back-chat-btn {
  background: var(--bg-white); border: 1px solid var(--color-01); border-radius: 8px;
  padding: 10px 18px; font-size: 13px; font-weight: 700; color: var(--color-01);
}
.back-chat-btn:hover { background: var(--bg-active); }

/* document info tab */
.info-tbl { width: 100%; border-collapse: collapse; }
.info-tbl th, .info-tbl td {
  text-align: left; padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--border);
}
.info-tbl th { width: 230px; font-weight: 600; color: var(--text-500); background: #f8fafc; }
.info-tbl td { color: var(--text-900); font-weight: 500; }

/* Excel / CSV table view */
.xls { display: flex; flex-direction: column; gap: 14px; }
.xls-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.xls-file { font-size: 13px; font-weight: 700; color: var(--text-900); }
.xls-hint { font-size: 11px; color: var(--text-450); }
.xls-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.xls-tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.xls-tbl th, .xls-tbl td { border: 1px solid #e7edf5; padding: 8px 10px; text-align: left; white-space: nowrap; }
.xls-cols th { background: #eef2f7; color: var(--text-450); font-size: 11px; font-weight: 700; text-align: center; }
.xls-hdr th { background: #f8fafc; color: var(--text-700); font-weight: 700; }
.xls-tbl tbody th { background: #eef2f7; color: var(--text-450); font-size: 11px; font-weight: 700; text-align: center; width: 34px; }
.xls-tbl td { color: var(--text-900); background: #fff; }
.xls-tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.xls-tbl tr.is-row td, .xls-tbl tr.is-row th { background: #fffbeb; }
.xls-tbl td.is-cell {
  background: #fde68a; font-weight: 700; color: #78350f;
  box-shadow: inset 0 0 0 2px #f59e0b;
}
.xls-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 12px; }
.xls-tab {
  background: var(--bg-chip); border: 1px solid var(--border); border-radius: 6px 6px 0 0;
  padding: 6px 12px; font-size: 12px; font-weight: 500; color: var(--text-600);
}
.xls-tab.is-on { background: #fff; border-color: var(--color-01); color: var(--color-01); font-weight: 700; }

/* =========================================================
   S12 - mobile drawer + citation bottom sheet
   ========================================================= */
.drawer-backdrop, .sheet-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 90;
}
.drawer-backdrop[hidden], .sheet-backdrop[hidden] { display: none; }
.sheet-backdrop { z-index: 190; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  background: #fff; border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(15,23,42,.2);
  max-height: 76vh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .22s ease;
}
.sheet[hidden] { display: none; }
.sheet.is-open { transform: translateY(0); }
.sheet-grab { width: 44px; height: 4px; border-radius: 2px; background: var(--border); margin: 8px auto 4px; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 10px; border-bottom: 1px solid var(--border);
}
.sheet-title { font-size: 14px; font-weight: 700; color: var(--color-01); }
.sheet-close { padding: 4px; }
.sheet-list { padding: 14px 16px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

/* ===== laptop / tablet-landscape breakpoints (3-column squeeze) ===== */
@media (max-width: 1440px) {
  .right-sidebar { width: 360px; flex: 0 0 360px; }
}
@media (max-width: 1280px) {
  .right-sidebar { width: 320px; flex: 0 0 320px; padding: 16px; }
  .chat-history { width: 220px; flex: 0 0 220px; }
  .chat-scroll { padding: 20px 16px 48px; }
}
@media (max-width: 1150px) and (min-width: 769px) {
  .hamburger { display: flex; }
  .chat-history {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
    width: 282px; flex: 0 0 282px;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(15, 23, 42, .18);
  }
  .chat-history.is-open { transform: translateX(0); }
  .mobile-scope-btn { display: none; }
}

@media (max-width: 768px) {
  .sidebar-restore { display: none !important; }
  .app-header { padding: 10px 14px; height: auto; }
  .brand { gap: 8px; }
  .brand-sub { display: none; }
  .hamburger { display: flex; }
  .app-nav { gap: 12px; }
  .app-nav a { display: none; }
  .app-nav .avatar { width: 32px; height: 32px; }

  .app-body { min-height: 0; height: auto; flex-direction: column; }

  /* left sidebar → off-canvas drawer */
  .chat-history {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
    width: 282px; flex-basis: 282px;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(15,23,42,.18);
  }
  .chat-history.is-open { transform: translateX(0); }

  /* Document search remains available as a drawer; citations still use the bottom sheet. */
  .right-sidebar {
    display: block; position: fixed; top: 0; right: 0; bottom: 0; z-index: 100;
    width: min(92vw, 360px); overflow-y: auto;
    transform: translateX(100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(15,23,42,.18);
  }
  .right-sidebar.is-open { transform: translateX(0); }

  .chat-main { flex: 1 1 auto; min-height: calc(100vh - 56px); }
  .chat-scroll { padding: 14px 12px 20px; }
  .hero, .conversation { width: 100%; max-width: 100%; }
  .hero { padding: 18px 14px; }
  .hero-title { font-size: 18px; }
  .hero-sub { width: 100%; max-width: 100%; font-size: 13px; line-height: 21px; }
  .hero-faq-grid { grid-template-columns: 1fr; }
  .hero-faq .faq-item-t { font-size: 12.5px; }
  .sugg { flex-direction: column; align-items: stretch; }
  .sugg-label { text-align: center; }
  .sugg-grid { flex-direction: column; }
  .sugg-chip {
    flex-basis: auto; width: 100%; box-sizing: border-box;
    flex-wrap: wrap; row-gap: 4px;
  }
  .sugg-chip > span:not(.spark):not(.sugg-tag) { min-width: 0; flex: 1 1 auto; }
  .sugg-tag { margin-left: 0; }
  .user-bubble { max-width: 88%; font-size: 13.5px; }
  .ai-row { gap: 8px; }
  .ai-card { padding: 12px 13px; }
  .ai-body { font-size: 13.5px; line-height: 24px; }

  .conf { gap: 6px; font-size: 10.5px; padding: 6px 8px; }
  .conf-meter { width: 46px; }
  .conf-warn { margin-left: 0; width: 100%; }

  .src-pill {
    display: flex; align-items: center; gap: 6px; margin-top: 12px;
    background: var(--bg-active); border: 1px solid var(--border-active); border-radius: 999px;
    padding: 8px 14px; font-size: 12.5px; font-weight: 700; color: var(--color-01);
  }
  .src-pill::after { content: "›"; font-size: 15px; line-height: 1; }
  .ai-cite { display: none; }

  .ai-foot { flex-wrap: wrap; gap: 8px; }
  .ai-foot-hint { display: none; }

  /* input pinned to the bottom */
  .input-area {
    position: sticky; bottom: 0; z-index: 20;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 16px rgba(15,23,42,.06);
  }
  .input-meta-left p { font-size: 10px; line-height: 15px; }
  .input-meta-right { display: none; }
  .model-chip { display: none; }

  /* modals full-screen-ish */
  .modal--feedback, .modal--citation { width: 100%; max-width: 100%; max-height: 100vh; border-radius: 0; }
  .overlay { align-items: stretch; }
  .modal { border-radius: 0; width: 100%; }
  .modal-head { padding: 12px 14px; }
  .modal-title { font-size: 15px; }
  .modal-sub { display: none; }
  .nav-bar { flex-direction: column; align-items: stretch; gap: 10px; padding: 10px 14px; }
  .nav-bar-r { justify-content: space-between; gap: 10px; }
  .doc-find { flex: 1 1 auto; }
  .doc-find input { width: 100%; }
  .viewer { flex-direction: column; }
  .toc { width: 100%; flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--border); max-height: 132px; }
  .toc-meta { display: none; }
  .canvas { padding: 12px; }
  .doc-container { padding: 16px 14px; gap: 16px; }
  .doc-header-row { flex-direction: column; gap: 10px; align-items: stretch; }
  .page-box { padding: 14px; }
  .modal-foot { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .foot-right { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .close-win-btn { display: none; }
  .back-chat-btn { grid-column: span 1; }
  .opt-grid { grid-template-columns: 1fr; }
  .sat-buttons { flex-direction: column; }
  .xls-bar { flex-direction: column; align-items: flex-start; gap: 4px; }
  .info-tbl th { width: 120px; font-size: 12px; }
  .info-tbl td { font-size: 12px; }

  .mobile-scope-btn {
    display: flex; align-items: center; justify-content: space-between;
    width: calc(100% - 24px); margin: 0 12px 12px;
    padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--bg-white); font-size: 12.5px; font-weight: 600; color: var(--text-700);
  }
  .mobile-scope-count {
    background: var(--bg-active); color: var(--color-01); border-radius: 4px;
    padding: 1px 6px; font-size: 10px; font-weight: 700;
  }
}

/* =========================================================
   MODE SWITCH - segmented tab (สนทนาถาม-ตอบ | ตารางวิเคราะห์)
   Shared visual pattern - same rules duplicated in css/matrix.css so both
   pages render pixel-identical (index.html and matrix.html load separate
   stylesheets; only tokens.css is common between them and it is orchestrator-owned).
   ========================================================= */
.mode-switch-bar { display: flex; justify-content: center; padding: 14px 24px 0; }
.mode-switch {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px;
  background: var(--bg-chip); border: 1px solid var(--border); border-radius: 10px;
  width: fit-content;
}
.mode-tab {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 16px; border-radius: 8px;
  font-size: 12.5px; font-weight: 600; line-height: 1.45; color: var(--text-500);
  transition: background .15s ease, color .15s ease;
}
.mode-tab:hover { color: var(--color-01); }
.mode-tab.is-active {
  background: var(--color-01); color: #fff;
}
.mode-tab.is-active:hover { color: #fff; }

@media (max-width: 420px) {
  .mode-switch-bar { padding: 10px 12px 0; }
  .mode-switch { width: 100%; }
  .mode-tab { flex: 1 1 0; text-align: center; padding: 7px 8px; font-size: 12px; }
}

/* =========================================================
   THAI NORMALIZATION LAYER - left sidebar mini-panel
   ========================================================= */
.norm-panel {
  margin-top: 12px;
  border: 1px solid var(--border-active);
  border-radius: 10px;
  padding: 10px 11px;
  background: var(--bg-active);
}
.norm-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.norm-head-l { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.norm-title { font-size: 11px; font-weight: 700; color: var(--color-01); line-height: 15px; }
.norm-sub { font-size: 9.5px; font-weight: 500; color: var(--text-450); }
.norm-toggle {
  flex: 0 0 auto; width: 30px; height: 17px; border-radius: 999px;
  background: var(--border-active); position: relative; transition: background .15s ease;
}
.norm-toggle-dot {
  position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.25); transition: transform .15s ease;
}
.norm-toggle.is-on { background: var(--color-01); }
.norm-toggle.is-on .norm-toggle-dot { transform: translateX(13px); }
.norm-toggle:focus-visible { outline: 2px solid var(--color-02); outline-offset: 2px; }
.norm-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.norm-chip {
  background: var(--bg-white); border: 1px solid var(--border-active); border-radius: 999px;
  padding: 2px 7px; font-size: 9.5px; font-weight: 600; color: var(--color-01);
}

/* hero suggested-prompt normalization demo chip */
.sugg-chip--norm { border-style: dashed; border-color: var(--border-active); }
.sugg-tag--norm { background: var(--bg-active); color: var(--text-500); }

/* =========================================================
   GROUNDEDNESS CHECK - "ตรวจสอบคำตอบนี้"
   ========================================================= */
.verify-btn { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; color: var(--text-500); }
.verify-btn:hover { color: var(--color-01); }
.verify-btn[hidden] { display: none; }
.verify-status { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 12.5px; color: var(--text-500); }
.verify-status .spin {
  width: 13px; height: 13px; flex: 0 0 13px; border-radius: 50%;
  border: 2px solid var(--border-active); border-top-color: var(--color-01);
  animation: spin .7s linear infinite;
}
.sent--verify { cursor: help; }
.sent--green { background: var(--success-bg); box-shadow: 0 0 0 2px var(--success-bg); }
.sent--amber { background: var(--warn-bg); box-shadow: 0 0 0 2px var(--warn-bg); }
.verify-result {
  margin-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--bg-chip); border-radius: 8px; padding: 8px 12px;
  font-size: 12px; font-weight: 500; color: var(--text-700);
}
.ver-clear { flex: 0 0 auto; font-size: 11px; font-weight: 600; color: var(--color-01); text-decoration: underline; text-underline-offset: 2px; }

/* =========================================================
   ABSTAIN - Thai Normalization hint box
   ========================================================= */
.ab-norm-hint {
  margin-top: 12px; background: var(--warn-bg); border: 1px solid #fde68a;
  border-radius: 8px; padding: 12px 14px;
}
.ab-norm-hint p { font-size: 12.5px; line-height: 19px; color: #92400e; }
.ab-norm-btn {
  margin-top: 10px; background: var(--color-01); border-radius: 8px; padding: 9px 14px;
  font-size: 12.5px; font-weight: 600; color: #fff;
}
.ab-norm-btn:hover { background: #0f2350; }

/* extra streaming step - normalization conversion note */
.stream-step.norm-step { color: #047857; }

/* =========================================================
   EXPORT MENU - บันทึกข้อความ (.doc) / ตาราง CSV
   ========================================================= */
.export-wrap { position: relative; }
.export-chev { display: block; transition: transform .15s ease; }
.export-wrap.is-open .export-chev { transform: rotate(180deg); }
.export-menu {
  /* position/left/top/width are set by positionExportMenu() in js/chat.js so the
     menu always clamps within the viewport, regardless of where the trigger sits */
  position: fixed; z-index: 260; min-width: 168px; max-width: calc(100vw - 24px);
  background: var(--bg-white); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 28px rgba(15,23,42,.14); padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.export-menu[hidden] { display: none; }
.export-item {
  width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 500; color: var(--text-700);
}
.export-item:hover { background: var(--bg-chip); color: var(--color-01); }

@media (max-width: 420px) {
  .brand-name { font-size: 14px; }
  .chat-history { width: 86vw; flex-basis: 86vw; }
  .cc-quote, .cc-meta, .cc-foot { margin-left: 0; padding-left: 0; }
  .cc-quote { margin-top: 8px; }
}
