/* ผู้ช่วย AI (#401) — tokens from app.css only. .ai-btn-ink is ink, never coral. */
.ai-root { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--paper); position: relative; font-family: var(--font-thai); color: var(--ink); }
.ai-root h1, .ai-root h2 { margin: 0; }
.ai-root a:not(.ai-btn):not(.ai-menu-row) { color: var(--p-deep); }
.ai-mut { color: var(--mut); }
.ai-small { font-size: 12.5px; }
.ai-ok { color: var(--success-deep); } .ai-bad { color: var(--danger-deep); } .ai-warn { color: var(--warning-deep); }
.ai-block { display: flex; align-items: center; justify-content: center; width: 100%; box-sizing: border-box; text-decoration: none; }

/* header */
.ai-head { flex-shrink: 0; min-height: 64px; padding: 0 32px; background: var(--cream); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; box-sizing: border-box; }
.ai-title { flex: 1; min-width: 0; font-family: var(--font-display); font-size: 22px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-btn { font-family: inherit; font-size: 14px; font-weight: 600; min-height: 44px; padding: 0 16px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--white); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ai-btn:disabled { opacity: .45; cursor: not-allowed; }
.ai-btn-ink { background: var(--ink); border-color: var(--ink); color: var(--white); }
.ai-big { font-size: 15px; font-weight: 700; padding: 0 20px; }
.ai-icon-btn { width: 44px; height: 44px; flex-shrink: 0; border: 0; background: none; font-size: 22px; color: var(--ink); cursor: pointer; border-radius: var(--r-sm); display: inline-flex; align-items: center; justify-content: center; font-family: inherit; }
.ai-quota { min-height: 44px; display: flex; align-items: center; gap: 8px; font-family: inherit; font-size: 13px; color: var(--ink); border: 1px solid var(--line-2); background: var(--white); border-radius: var(--r-sm); padding: 0 12px; cursor: pointer; }
.ai-quota-bar { width: 56px; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; display: block; }
.ai-quota-bar span { display: block; height: 6px; background: var(--spa); }

/* body */
.ai-main { flex: 1; min-height: 0; display: flex; position: relative; }
.ai-chatcol { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ai-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.ai-thread { padding: 20px 28px 8px; display: flex; flex-direction: column; gap: 14px; font-size: 15px; line-height: 1.55; min-height: 100%; box-sizing: border-box; }
.ai-user { align-self: flex-end; max-width: min(460px, 85%); background: var(--ink); color: var(--white); padding: 10px 14px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-ai { display: flex; flex-direction: column; gap: 8px; max-width: 100%; }
.ai-who { font-size: 12px; font-weight: 700; color: var(--p-deep); }
.ai-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-toolchip { display: inline-flex; font-size: 12px; color: var(--ink-2); background: var(--white); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.ai-toolchip.ai-run { color: var(--mut); }
.ai-toolchip.ai-bad { color: var(--danger-deep); }
.ai-think { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-2); }
.ai-dots { display: inline-flex; gap: 4px; } .ai-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--mut); animation: ai-bounce 1s infinite ease-in-out; }
.ai-dots i:nth-child(2) { animation-delay: .15s; } .ai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-bounce { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ai-dots i { animation: none; opacity: .6; } }
.ai-err { background: var(--danger-tint); color: var(--danger-deep); border-radius: var(--r-md); padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

/* home */
.ai-home { margin: auto; width: 100%; max-width: 560px; padding: 28px 0; display: flex; flex-direction: column; gap: 10px; }
.ai-home h2 { font-family: var(--font-display); font-size: 24px; font-weight: 600; }
.ai-home p { margin: 0; }
.ai-sub { font-size: 12px; font-weight: 700; color: var(--mut); margin-top: 8px; }
.ai-list { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.ai-list-row { width: 100%; min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 14px; background: none; border: 0; border-top: 1px solid var(--line); font-family: inherit; font-size: 15px; color: var(--ink); cursor: pointer; text-align: left; }
.ai-list-row:first-child { border-top: 0; }
.ai-center { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; box-sizing: border-box; overflow-y: auto; }

/* cards */
.ai-card { background: var(--white); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--sh-md); overflow: hidden; }
.ai-consent, .ai-quota-out { max-width: 520px; width: 100%; padding: 22px; box-sizing: border-box; display: flex; flex-direction: column; gap: 12px; }
.ai-consent h2, .ai-quota-out h2 { font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.ai-consent p, .ai-quota-out p { margin: 0; font-size: 14px; line-height: 1.55; }
.ai-consent ul { margin: 6px 0 0; padding-left: 18px; font-size: 14px; line-height: 1.6; }
.ai-two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ai-row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.ai-quota-out { margin: 6px 0; }

/* proposal card */
.ai-proposal { max-width: 720px; }
.ai-phead { padding: 12px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.ai-phead > div { flex: 1; min-width: 0; }
.ai-kind { font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--p-deep); }
.ai-ptitle { font-size: 16px; font-weight: 700; }
.ai-pill { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 10px; white-space: nowrap; background: var(--line); color: var(--ink-2); }
.ai-pill.ai-warn { background: var(--warning-tint); color: var(--warning-deep); }
.ai-pill.ai-ok { background: var(--success-tint); color: var(--success-deep); }
.ai-pill.ai-bad { background: var(--danger-tint); color: var(--danger-deep); }
.ai-prow { display: grid; grid-template-columns: 44px 1fr auto 150px; align-items: center; border-top: 1px solid var(--line); font-size: 14px; }
.ai-chk { display: flex; align-items: center; justify-content: center; min-height: 44px; }
.ai-chk input { width: 20px; height: 20px; accent-color: var(--ink); }
.ai-plabel { padding: 10px 12px; }
.ai-pbefore { padding: 10px 12px; color: var(--mut); text-decoration: line-through; }
.ai-pnew { padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.ai-pinput { width: 100%; box-sizing: border-box; font-family: inherit; font-size: 15px; font-weight: 700; border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 0 10px; min-height: 44px; background: var(--white); color: var(--ink); }
.ai-pinput:disabled { background: var(--paper); }
.ai-pfoot { padding: 10px 16px; background: var(--cream); border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.ai-pact { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* composer */
.ai-composer { flex-shrink: 0; padding: 8px 28px 16px; display: flex; flex-direction: column; gap: 8px; }
.ai-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-chip { min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--white); font-family: inherit; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; }
.ai-box { display: flex; align-items: flex-end; gap: 8px; background: var(--white); border: 1px solid var(--line-2); border-radius: 22px; padding: 6px 6px 6px 16px; }
.ai-box textarea { flex: 1; min-width: 0; border: 0; outline: 0; resize: none; font-family: inherit; font-size: 16px; line-height: 1.5; padding: 9px 0; background: transparent; color: var(--ink); max-height: 140px; }
.ai-send { flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--ink); color: var(--white); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-family: inherit; font-weight: 700; font-size: 13px; }
.ai-send:disabled { background: var(--line-2); cursor: not-allowed; }
.ai-stop { width: auto; padding: 0 16px; border-radius: 22px; }

/* preview: 300px pane (wide) / bar + sheet (narrower) */
.ai-pane { width: 300px; flex-shrink: 0; background: var(--cream); border-left: 1px solid var(--line); padding: 20px; box-sizing: border-box; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.ai-pgroups { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); font-size: 14px; overflow: hidden; }
.ai-pgl { padding: 8px 12px; font-size: 12px; font-weight: 700; color: var(--mut); background: var(--paper); }
.ai-pgr { padding: 9px 12px; display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); }
.ai-new { color: var(--p-deep); }
.ai-previewbar { display: none; margin: 0 16px 8px; min-height: 48px; align-items: center; gap: 8px; padding: 0 14px; background: var(--white); border: 1px solid var(--line-2); border-radius: var(--r-md); font-family: inherit; font-size: 14px; color: var(--ink); cursor: pointer; text-align: left; }
.ai-previewbar span:nth-child(2) { flex: 1; min-width: 0; color: var(--mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-backdrop { position: absolute; inset: 0; background: rgba(42,38,34,.4); z-index: 5; }
.ai-sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 80%; overflow-y: auto; z-index: 6; background: var(--cream); border-radius: 20px 20px 0 0; padding: 20px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--sh-lg); }
.ai-x { align-self: flex-end; }
@media (max-width: 1023px) {
  .ai-pane { display: none; }
  .ai-previewbar { display: flex; }
}
@media (min-width: 1024px) { .ai-sheet, .ai-backdrop { display: none; } }

/* menu */
.ai-menu { position: absolute; top: 56px; right: 16px; z-index: 7; min-width: 220px; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-lg); overflow: hidden; }
.ai-menu-row { display: flex; align-items: center; width: 100%; box-sizing: border-box; min-height: 48px; padding: 0 16px; background: none; border: 0; border-top: 1px solid var(--line); font-family: inherit; font-size: 15px; color: var(--ink); cursor: pointer; text-align: left; text-decoration: none; }
.ai-menu-row:first-child { border-top: 0; }
.ai-danger { color: var(--danger-deep); }

/* history */
.ai-histwrap { flex: 1; overflow: auto; padding: 20px 28px; display: flex; flex-direction: column; gap: 12px; }
.ai-hist { width: 100%; border-collapse: collapse; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); font-size: 14px; }
.ai-hist th { text-align: left; padding: 10px 12px; font-size: 12px; color: var(--mut); background: var(--paper); }
.ai-hist td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }

/* phone / narrow */
@media (max-width: 699px), (max-width: 1023px) and (max-height: 1023px) {
  .ai-head { padding: 0 8px 0 4px; min-height: 56px; gap: 6px; }
  .ai-title { font-size: 18px; }
  .ai-thread { padding: 14px 14px 6px; }
  .ai-composer { padding: 6px 12px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .ai-prow { grid-template-columns: 44px 1fr 86px; grid-template-areas: "c l n" "c b n"; }
  .ai-prow .ai-chk { grid-area: c; } .ai-plabel { grid-area: l; padding: 8px 8px 0; } .ai-pbefore { grid-area: b; padding: 0 8px 8px; font-size: 13px; } .ai-pnew { grid-area: n; }
  .ai-two { grid-template-columns: 1fr; }
  .ai-histwrap { padding: 12px; } .ai-hist { font-size: 13px; }
  .ai-previewbar { margin: 0 12px 6px; }
  .ai-menu { top: 52px; right: 8px; }
  /* chat open = full screen: the bar goes away (Back is in the header) */
  body:has(#screen-desktop-assistant.visible .ai-root[data-tabbar="off"]) #tabbar-mobile { display: none; }
  .screen[id^="screen-desktop-"]:has(.ai-root[data-tabbar="off"]) { padding-bottom: 0 !important; } /* app.css reserves the bar's 62px with !important */
}
@media (max-width: 380px) { .ai-quota-l { display: none; } }

/* header button + side panel / half-sheet (#403) */
.ai-ctx-btn { position: relative; font-family: var(--font-thai); display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px; font-size: 12px; font-weight: 700; border: 1.5px solid var(--p); background: var(--p-cream); color: var(--p-deep); border-radius: 7px; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.ai-ctx-btn::after { content: ''; position: absolute; inset: -5px -2px; } /* 34px to match its siblings, 44px to touch */
.ai-ctx-btn[data-ai-ctx="calendar"] { height: 32px; } /* its bar siblings are 32px */
.ai-ctx-btn[hidden] { display: none; }
@media (max-width: 699px) { .ai-ctx-btn { padding: 0; width: 34px; } .ai-ctx-btn span { display: none; } }
.ai-panel-wrap { position: fixed; inset: 0; z-index: 1200; }
.ai-scrim { position: absolute; inset: 0; background: rgba(42,38,34,.4); }
.ai-panel { position: absolute; left: 0; right: 0; bottom: 0; height: 75vh; height: 75dvh; display: flex; flex-direction: column; background: var(--paper); border-radius: 20px 20px 0 0; box-shadow: var(--sh-lg); overflow: hidden; }
@media (min-width: 1024px) {
  .ai-scrim { background: rgba(42,38,34,.18); }
  .ai-panel { left: auto; top: 0; height: auto; width: 420px; border-radius: 0; border-left: 1px solid var(--line); }
}
.ai-in-panel { height: 100%; }
.ai-in-panel .ai-head { padding: 0 8px 0 20px; min-height: 64px; gap: 8px; }
.ai-ph { flex: 1; min-width: 0; }
.ai-ph-t { font-size: 16px; font-weight: 700; }
.ai-ph-s { font-size: 12px; color: var(--mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-chips-l { font-weight: 700; white-space: normal; }
.ai-btn-link { font-family: inherit; min-height: 44px; padding: 0 8px; background: none; border: 0; font-size: 13px; font-weight: 700; color: var(--p-deep); text-decoration: underline; cursor: pointer; }
.ai-in-panel .ai-pane { display: none; }
.ai-in-panel .ai-previewbar { display: flex; margin: 0 16px 8px; }
.ai-in-panel .ai-sheet { display: flex; }
.ai-in-panel .ai-backdrop { display: block; }
.ai-in-panel .ai-thread { padding: 14px 20px 6px; }
.ai-in-panel .ai-composer { padding: 6px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
.ai-in-panel .ai-prow { grid-template-columns: 44px 1fr 86px; grid-template-areas: "c l n" "c b n"; }
.ai-in-panel .ai-prow .ai-chk { grid-area: c; } .ai-in-panel .ai-plabel { grid-area: l; padding: 8px 8px 0; } .ai-in-panel .ai-pbefore { grid-area: b; padding: 0 8px 8px; font-size: 13px; } .ai-in-panel .ai-pnew { grid-area: n; }
.ai-in-panel .ai-two { grid-template-columns: 1fr; }

/* ── ตั้งร้านให้ AI ช่วย (#402): inside the onboarding wizard, steps 2-4 ── */
.onb-ai-tog-wrap:empty { display: none; }
.onb-ai-tog-wrap { display: flex; justify-content: flex-end; margin: -10px 0 14px; }
.onb-ai-tog { display: inline-flex; gap: 4px; padding: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md); }
.onb-ai-tab { min-height: 44px; min-width: 96px; padding: 0 14px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-2); font: 600 14px var(--font-thai); cursor: pointer; }
.onb-ai-tab[aria-pressed="true"] { background: var(--white); color: var(--ink); box-shadow: var(--sh-sm, 0 1px 3px rgba(0,0,0,.12)); }
.onb-ai-mut { color: var(--mut); font-size: 13px; }
.onb-ai-box { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper); display: flex; flex-direction: column; margin-bottom: 14px; }
.onb-ai-thread { padding: 14px; display: flex; flex-direction: column; gap: 10px; max-height: 260px; overflow-y: auto; font-size: 14px; line-height: 1.55; }
.onb-ai-user { align-self: flex-end; max-width: 85%; background: var(--ink); color: var(--white); padding: 8px 12px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.onb-ai-thumb { display: block; max-width: 160px; max-height: 120px; border-radius: 8px; margin-bottom: 4px; }
.onb-ai-who { font-size: 12px; font-weight: 700; color: var(--p-deep); }
.onb-ai-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.onb-ai-err { margin: 10px 14px; background: var(--danger-tint); color: var(--danger-deep); border-radius: var(--r-md); padding: 8px 12px; font-size: 13.5px; }
.onb-ai-thread .onb-ai-err { margin: 0; }
.onb-ai-photo { padding: 0 14px 8px; }
.onb-ai-composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px; border-top: 1px solid var(--line); background: var(--white); border-radius: 0 0 var(--r-md) var(--r-md); }
.onb-ai-composer textarea { flex: 1; min-width: 0; min-height: 44px; border: 0; outline: 0; resize: none; font: 15px/1.4 var(--font-thai); padding: 10px 6px; background: transparent; color: var(--ink); box-sizing: border-box; }
.onb-ai-send { flex-shrink: 0; min-width: 44px; height: 44px; border-radius: 22px; border: 0; background: var(--ink); color: var(--white); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; font: 600 14px var(--font-thai); }
.onb-ai-icon { flex-shrink: 0; width: 44px; height: 44px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-family: inherit; font-size: 16px; }
.onb-ai-icon:disabled, .onb-ai-send:disabled { opacity: .45; cursor: not-allowed; }
.onb-ai-card { border: 1.5px solid var(--ink); border-radius: var(--r-md); background: var(--white); padding: 14px; margin-bottom: 14px; }
.onb-ai-card-h { font: 700 15px var(--font-thai); margin-bottom: 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.onb-ai-note { font-size: 12px; font-weight: 600; color: var(--warning-deep); }
.onb-ai-dow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 14px; }
.onb-ai-dow-l { font-size: 12px; font-weight: 700; color: var(--mut); width: 100%; }
.onb-ai-dow-c { position: relative; }
.onb-ai-dow-c input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.onb-ai-dow-c span { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--white); font: 600 14px var(--font-thai); }
.onb-ai-dow-c input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--white); }
.onb-ai-dow-c input:focus-visible + span { outline: 2px solid var(--p-deep); outline-offset: 2px; }
.onb-ai-staff-row { display: flex; gap: 8px; margin-bottom: 8px; }
.onb-ai-staff-row input { flex: 1; min-width: 0; min-height: 44px; border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 0 12px; font: 15px/1.5 var(--font-thai); box-sizing: border-box; }
.onb-ai-consent a { color: var(--p-deep); }
.onb-ai-consent .ai-consent { box-shadow: none; max-width: none; padding: 16px; }
.onb-ai-center { display: block; }
@media (max-width: 760px) { .onb-ai-consent .ai-two { grid-template-columns: 1fr; } }
