/* R9: FAS help chatbot («ผู้ช่วยการใช้งาน FAS»). Uses the backend theme vars, so Light / Dark follow body.fas-backend. */
.fas-help { --help-accent: var(--lime, #41E36A); font-family: var(--font, "Prompt", system-ui, sans-serif); }
.fas-help[hidden], .fas-help [hidden] { display: none !important; }
.fas-help-launcher-wrap {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px) + var(--fas-help-lift, 0px)); z-index: 190;
  transition: bottom 0.18s ease;
}
.fas-help.is-launcher-hidden .fas-help-launcher-wrap { display: none; }
.fas-help-dismiss {
  position: absolute; top: -8px; right: -8px; z-index: 1;
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
  background: #04140a; color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}
.fas-help-dismiss svg { width: 14px; height: 14px; }
.fas-help-launcher {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 18px 0 14px;
  border: 0; border-radius: 999px; cursor: pointer;
  background: var(--help-accent); color: #04140a; font: 600 14px/1 var(--font, "Prompt", sans-serif);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}
html[data-fas-theme="light"] .fas-help-launcher { color: #ffffff; box-shadow: 0 10px 24px rgba(20, 60, 32, 0.22); }
.fas-help-launcher svg { width: 22px; height: 22px; flex: none; }
.fas-help-launcher:focus-visible, .fas-help-dismiss:focus-visible, .fas-help-close:focus-visible, .fas-help-send:focus-visible, .fas-help-chip:focus-visible {
  outline: 2px solid var(--help-accent); outline-offset: 2px;
}
.fas-help.is-open .fas-help-launcher-wrap, body.fas-nav-open .fas-help-launcher-wrap, html.has-fas-dialog .fas-help-launcher-wrap { display: none; }
.fas-help-panel {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 195;
  width: min(390px, calc(100vw - 40px)); height: min(600px, calc(100vh - 40px)); height: min(600px, calc(100dvh - 40px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border-strong); border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
}
html[data-fas-theme="light"] .fas-help-panel { box-shadow: 0 22px 50px rgba(20, 28, 22, 0.18); }
.fas-help-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--panel);
}
.fas-help-mark {
  flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--lime-dim); color: var(--help-accent);
}
.fas-help-mark svg { width: 20px; height: 20px; }
.fas-help-title { flex: 1; min-width: 0; }
.fas-help-title strong { display: block; font-size: 15px; font-weight: 700; color: var(--text); }
.fas-help-title small { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fas-help-close {
  flex: none; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.fas-help-close:hover { background: var(--ghost-hover); color: var(--text); }
.fas-help-close svg { width: 18px; height: 18px; }
.fas-help-log { flex: 1; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.fas-help-msg { max-width: 88%; padding: 10px 12px; border-radius: 14px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.fas-help-msg.is-bot { align-self: flex-start; background: var(--bg-card-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.fas-help-msg.is-user { align-self: flex-end; background: var(--lime-dim); border: 1px solid color-mix(in srgb, var(--help-accent) 35%, transparent); border-bottom-right-radius: 4px; }
.fas-help-msg.is-error { border-color: color-mix(in srgb, var(--danger, #ff4655) 55%, transparent); color: var(--text); }
.fas-help-msg.is-scope { border-style: dashed; }
.fas-help-msg.is-notice { border-style: solid; border-color: color-mix(in srgb, var(--warning, #f5a524) 60%, transparent); }
.fas-help.is-locked .fas-help-input { opacity: 0.6; cursor: not-allowed; }
.fas-help-msg strong { font-weight: 700; }
.fas-help-src { display: block; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); font-size: 11.5px; color: var(--muted); white-space: normal; }
.fas-help-typing { display: inline-flex; gap: 4px; align-items: center; }
.fas-help-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: fasHelpDot 1s infinite ease-in-out; }
.fas-help-typing i:nth-child(2) { animation-delay: .15s; } .fas-help-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes fasHelpDot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.fas-help-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.fas-help-chip {
  border: 1px solid var(--border-strong); background: transparent; color: var(--text); cursor: pointer;
  border-radius: 999px; padding: 6px 11px; font: 500 12.5px/1.3 var(--font, "Prompt", sans-serif);
}
.fas-help-chip:hover { border-color: var(--help-accent); color: var(--help-accent); }
.fas-help-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); background: var(--panel); }
.fas-help-input {
  flex: 1; min-height: 42px; max-height: 120px; resize: none; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--input-bg); color: var(--text);
  font: 400 14px/1.45 var(--font, "Prompt", sans-serif);
}
.fas-help-input::placeholder { color: var(--faint); }
.fas-help-input:focus { outline: none; border-color: var(--help-accent); }
.fas-help-send {
  flex: none; width: 42px; height: 42px; border-radius: 12px; border: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--help-accent); color: #04140a;
}
html[data-fas-theme="light"] .fas-help-send { color: #ffffff; }
.fas-help-send:disabled { opacity: .45; cursor: not-allowed; }
.fas-help-send svg { width: 18px; height: 18px; }
.fas-help-note { padding: 0 14px 8px; font-size: 11px; color: var(--faint); text-align: center; background: var(--panel); }
@media (max-width: 640px) {
  .fas-help-launcher-wrap { right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px) + var(--fas-help-lift, 0px)); }
  .fas-help-launcher { height: 46px; padding: 0 14px 0 12px; }
  .fas-help-panel { inset: 0; width: 100%; height: 100%; border-radius: 0; border: 0; }
  .fas-help-input { font-size: 16px; } /* no iOS zoom on focus */
  .fas-help-msg { max-width: 92%; }
}
@media (prefers-reduced-motion: reduce) { .fas-help-typing i { animation: none; } .fas-help-launcher-wrap { transition: none; } }

/* R9 (คุณติ้ง): FAS admin only — «คำถามที่ผู้ช่วยตอบไม่ได้» list. Same theme vars, so Light / Dark follow the backend. */
.fas-help-fb { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 24px; font-family: var(--font, "Prompt", system-ui, sans-serif); }
.fas-help-fb[hidden] { display: none !important; }
.fas-help-fb-backdrop { position: absolute; inset: 0; background: rgba(4, 8, 6, 0.62); }
html[data-fas-theme="light"] .fas-help-fb-backdrop { background: rgba(20, 28, 22, 0.38); }
.fas-help-fb-card {
  position: relative; width: min(1040px, 100%); max-height: min(780px, calc(100dvh - 48px)); display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
}
html[data-fas-theme="light"] .fas-help-fb-card { box-shadow: 0 22px 50px rgba(20, 28, 22, 0.18); }
.fas-help-fb-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.fas-help-fb-head .fas-help-title small { white-space: normal; }
.fas-help-fb-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.fas-help-fb-bar label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.fas-help-fb-bar select {
  height: 36px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--input-bg); color: var(--text);
  font: 500 13px/1 var(--font, "Prompt", sans-serif);
}
.fas-help-fb-bar select:focus-visible, .fas-help-fb-csv:focus-visible { outline: 2px solid var(--help-accent, var(--lime, #41E36A)); outline-offset: 2px; }
.fas-help-fb-csv {
  margin-left: auto; display: inline-flex; align-items: center; height: 36px; padding: 0 14px; border-radius: 10px; text-decoration: none;
  background: var(--lime, #41E36A); color: #04140a; font: 600 13px/1 var(--font, "Prompt", sans-serif);
}
html[data-fas-theme="light"] .fas-help-fb-csv { color: #ffffff; }
.fas-help-fb-counts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 12px 16px 4px; }
.fas-help-fb-count { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-card-2); }
.fas-help-fb-count b { display: block; font-size: 22px; line-height: 1.2; color: var(--text); }
.fas-help-fb-count span { font-size: 12px; color: var(--muted); }
.fas-help-fb-list { flex: 1; overflow: auto; padding: 8px 16px 16px; overscroll-behavior: contain; }
.fas-help-fb-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fas-help-fb-table th { position: sticky; top: 0; background: var(--bg-card); text-align: left; font-weight: 600; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.fas-help-fb-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text); }
.fas-help-fb-table td small { display: block; color: var(--muted); font-size: 11.5px; }
.fas-help-fb-table td.is-date { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.fas-help-fb-table td.is-q { min-width: 260px; line-height: 1.55; word-break: break-word; }
.fas-help-fb-pill { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid var(--border-strong); color: var(--text); }
.fas-help-fb-pill.is-unanswered { border-color: color-mix(in srgb, var(--warning, #f5a524) 60%, transparent); background: color-mix(in srgb, var(--warning, #f5a524) 14%, transparent); }
.fas-help-fb-pill.is-sales { border-color: color-mix(in srgb, var(--lime, #41E36A) 60%, transparent); background: var(--lime-dim); }
.fas-help-fb-pill.is-out_of_scope { border-style: dashed; color: var(--muted); }
.fas-help-fb-empty { margin: 14px 0; text-align: center; color: var(--muted); font-size: 13px; }
html.has-fas-help-fb { overflow: hidden; }
@media (max-width: 640px) {
  .fas-help-fb { padding: 0; }
  .fas-help-fb-card { width: 100%; height: 100%; max-height: none; border-radius: 0; border: 0; }
  .fas-help-fb-counts { grid-template-columns: 1fr; }
  .fas-help-fb-csv { margin-left: 0; }
  .fas-help-fb-table thead { display: none; }
  .fas-help-fb-table, .fas-help-fb-table tbody, .fas-help-fb-table tr, .fas-help-fb-table td { display: block; width: 100%; }
  .fas-help-fb-table tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  .fas-help-fb-table td { border: 0; padding: 3px 0; }
  .fas-help-fb-table td.is-q { min-width: 0; font-size: 14px; }
}
