/* ============================================================================
   TourismRevenue — AI assistant drawer (.ast-) and public visitor chat (.pcw-)
   Same tokens, radii and shadows as the ibjx copilot drawer; every colour is a
   design token from app.css so both themes and both palettes keep working.
   The two "on primary" colours are derived tokens: white surface in light mode,
   the light text colour in dark mode — never a literal.
   ============================================================================ */
#tr-assistant, #tr-public-chat {
  --ast-on-primary: var(--surface);
  --ast-z: 900;
  font-family: var(--font);
}
[data-theme="dark"] #tr-assistant, [data-theme="dark"] #tr-public-chat { --ast-on-primary: var(--text); }
#tr-assistant [hidden], #tr-public-chat [hidden] { display: none !important; }
.ast-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ── launcher ─────────────────────────────────────────────────────────────── */
.ast-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: var(--ast-z);
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: var(--ast-on-primary); display: grid; place-items: center; box-shadow: var(--shadow-lg);
  transition: transform .15s, box-shadow .15s;
}
.ast-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: var(--shadow-xl); }
.ast-fab:focus-visible { outline: 2px solid var(--primary-lt); outline-offset: 3px; }
.ast.is-open .ast-fab { display: none; }

/* ── drawer ───────────────────────────────────────────────────────────────── */
.ast-scrim { position: fixed; inset: 0; z-index: calc(var(--ast-z) - 2); background: var(--text); opacity: .35; }
.ast-drawer {
  position: fixed; top: 0; right: 0; z-index: calc(var(--ast-z) - 1); height: 100vh; height: 100dvh; width: 420px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-xl); color: var(--text);
  display: flex; flex-direction: column; transform: translateX(105%); transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.ast-drawer.is-in { transform: translateX(0); }
.ast-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary), var(--primary-dk)); color: var(--ast-on-primary);
}
.ast-head__title { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; }
.ast-head__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.ast-head__actions { display: flex; gap: 4px; }
.ast-iconbtn { background: transparent; border: 1px solid var(--border); color: inherit; width: 30px; height: 30px; opacity: .9;
  border-radius: var(--radius-sm); display: grid; place-items: center; cursor: pointer; transition: opacity .15s, background .15s; }
.ast-iconbtn:hover, .ast-iconbtn[aria-pressed="true"] { opacity: 1; background: var(--primary-lt); border-color: var(--primary-lt); }
.ast-iconbtn:focus-visible { outline: 2px solid var(--ast-on-primary); outline-offset: 1px; }

.ast-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.ast-notice { display: flex; gap: 10px; text-align: left; background: var(--warning-bg); border: 1px solid var(--warning);
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px; color: var(--text); }
.ast-notice svg { color: var(--warning); flex: 0 0 auto; margin-top: 1px; }
.ast-notice a { color: var(--primary-lt); font-weight: 600; }
.ast-welcome { margin: auto 0; padding: 20px 8px; text-align: center; }
.ast-welcome__icon { width: 56px; height: 56px; border-radius: var(--radius-lg); display: grid; place-items: center; margin: 0 auto 12px;
  background: var(--surface-2); color: var(--primary-lt); }
.ast-welcome__title { font-size: 17px; font-weight: 700; }
.ast-welcome__sub { font-size: 13px; margin-top: 4px; color: var(--text-muted); }
.ast-welcome__note { font-size: 11.5px; color: var(--text-faint); margin: 16px 0 0; line-height: 1.5; }
.ast-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.ast-chip, .pcw-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 7px 13px; font: inherit;
  font-size: 12.5px; color: var(--text); cursor: pointer; transition: border-color .15s, background .15s; }
.ast-chip:hover, .pcw-chip:hover { border-color: var(--accent); background: var(--surface); }
.ast-messages { display: flex; flex-direction: column; gap: 12px; }
.ast-msg { display: flex; flex-direction: column; gap: 6px; max-width: 92%; }
.ast-msg--user { align-self: flex-end; align-items: flex-end; }
.ast-msg--assistant { align-self: flex-start; }
.ast-msg__bubble { padding: 10px 13px; border-radius: var(--radius-lg); font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.ast-msg--user .ast-msg__bubble { background: var(--primary); color: var(--ast-on-primary); border-bottom-right-radius: 4px; }
.ast-msg--assistant .ast-msg__bubble { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.ast-msg--error .ast-msg__bubble { background: var(--danger-bg); border-color: var(--danger); }
.ast-msg__bubble p { margin: 0 0 8px; } .ast-msg__bubble p:last-child { margin-bottom: 0; }
.ast-msg__bubble ul, .ast-msg__bubble ol { margin: 4px 0; padding-left: 18px; } .ast-msg__bubble li { margin: 2px 0; }
.ast-msg__bubble code { background: var(--surface); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.ast-msg--user .ast-msg__bubble code { background: var(--primary-dk); border-color: var(--primary-dk); color: inherit; }
.ast-msg__bubble a { color: var(--primary-lt); text-decoration: underline; }
.ast-msg__bubble strong { font-weight: 650; }
.ast-typing { display: inline-flex; gap: 4px; }
.ast-typing span, .pcw-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: astBlink 1.2s infinite; }
.ast-typing span:nth-child(2), .pcw-typing span:nth-child(2) { animation-delay: .2s; }
.ast-typing span:nth-child(3), .pcw-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes astBlink { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }

.ast-composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); flex: none; background: var(--surface); }
.ast-composer textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  font: inherit; font-size: 13.5px; background: var(--surface-2); color: var(--text); max-height: 120px; line-height: 1.4; }
.ast-composer textarea:focus { outline: none; border-color: var(--primary-lt); background: var(--surface); }
.ast-composer textarea:disabled { opacity: .55; cursor: not-allowed; }
.ast-send, .pcw-send { flex: 0 0 auto; width: 40px; height: 40px; border-radius: var(--radius); border: none; cursor: pointer;
  background: var(--primary); color: var(--ast-on-primary); display: grid; place-items: center; transition: opacity .15s, transform .15s; }
.ast-send:disabled, .pcw-send:disabled { opacity: .45; cursor: not-allowed; }
.ast-send:not(:disabled):hover, .pcw-send:not(:disabled):hover { transform: scale(1.05); }

.ast-history { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.ast-history__title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: 4px 6px; }
.ast-history__item { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; font: inherit;
  background: none; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; text-align: left;
  color: var(--text); transition: background .15s, border-color .15s; }
.ast-history__item:hover, .ast-history__item:focus-visible { background: var(--surface-2); border-color: var(--border); }
.ast-history__name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ast-history__meta { font-size: 11px; color: var(--text-faint); flex: 0 0 auto; }
.ast-empty { padding: 20px; text-align: center; font-size: 13px; color: var(--text-muted); }

/* ── public visitor chat ──────────────────────────────────────────────────── */
#tr-public-chat { position: fixed; right: 20px; bottom: 20px; z-index: var(--ast-z); }
.pcw-fab {
  position: relative; width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--primary-lt); color: var(--ast-on-primary); box-shadow: var(--shadow-lg);
  display: grid; place-items: center; transition: transform .18s, filter .18s;
}
.pcw-fab:hover { transform: translateY(-2px); filter: brightness(1.08); }
.pcw-fab:focus-visible { outline: 2px solid var(--primary-lt); outline-offset: 3px; }
.pcw-fab__open, .pcw-fab__close { display: grid; place-items: center; }
.pcw-fab__close { display: none; }
.pcw.is-open .pcw-fab__open { display: none; }
.pcw.is-open .pcw-fab__close { display: grid; }
.pcw-fab__badge {
  position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px;
  background: var(--danger); color: var(--surface); border-radius: 10px; font-size: 11px; font-weight: 800;
  display: grid; place-items: center; border: 2px solid var(--surface);
}
.pcw-panel {
  position: absolute; right: 0; bottom: 72px; width: 370px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 120px); background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); display: flex; flex-direction: column;
  overflow: hidden; animation: pcwIn .2s ease;
}
@keyframes pcwIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.pcw-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-dk)); color: var(--ast-on-primary);
}
.pcw-head__id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pcw-head__avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-lt); display: grid; place-items: center; flex: none; }
.pcw-head__title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcw-head__status { font-size: 12px; opacity: .8; margin-top: 1px; }
.pcw-head__x { background: none; border: none; color: inherit; cursor: pointer; padding: 4px; display: grid; place-items: center; border-radius: var(--radius-sm); opacity: .85; }
.pcw-head__x:hover { opacity: 1; background: var(--primary-lt); }
.pcw-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); min-height: 0; }
.pcw-msg { max-width: 84%; display: flex; flex-direction: column; gap: 2px; }
.pcw-msg--me { align-self: flex-end; align-items: flex-end; }
.pcw-msg--them { align-self: flex-start; }
.pcw-msg--system { align-self: center; max-width: 95%; }
.pcw-msg__who { font-size: 11px; color: var(--text-muted); font-weight: 600; margin: 0 4px; }
.pcw-msg__body { padding: 9px 13px; border-radius: var(--radius-lg); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.pcw-msg--them .pcw-msg__body { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.pcw-msg--me .pcw-msg__body { background: var(--primary-lt); color: var(--ast-on-primary); border-bottom-right-radius: 4px; }
.pcw-msg--staff .pcw-msg__body { background: var(--success-bg); color: var(--text); border: 1px solid var(--success); }
.pcw-msg--system .pcw-msg__body { background: var(--info-bg); color: var(--text-muted); border: 1px dashed var(--info); font-size: 12.5px; text-align: center; }
.pcw-msg__body p { margin: 0 0 6px; } .pcw-msg__body p:last-child { margin: 0; }
.pcw-msg__body ul { margin: 4px 0; padding-left: 18px; }
.pcw-msg__body a { color: var(--primary-lt); text-decoration: underline; }
.pcw-msg--me .pcw-msg__body a { color: inherit; }
.pcw-msg__body code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.pcw-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; background: var(--bg); }
.pcw-typing { display: flex; gap: 4px; padding: 6px 20px 8px; background: var(--bg); }
.pcw-foot { border-top: 1px solid var(--border); padding: 10px 12px 8px; background: var(--surface); flex: none; }
.pcw-human { display: inline-flex; align-items: center; gap: 6px; margin: 0 auto 8px; background: none; border: 1px solid var(--border); color: var(--primary-lt);
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 5px 12px; border-radius: 999px; cursor: pointer; }
.pcw-foot .pcw-human { display: flex; width: max-content; }
.pcw-human:hover { border-color: var(--primary); background: var(--surface-2); }
.pcw-form { display: flex; gap: 8px; align-items: center; }
.pcw-input { flex: 1; min-width: 0; height: 42px; padding: 0 14px; border: 1px solid var(--border); border-radius: 999px; font: inherit; font-size: 14px; background: var(--surface-2); color: var(--text); }
.pcw-input:focus { outline: none; border-color: var(--primary-lt); background: var(--surface); }
.pcw-send { border-radius: 50%; width: 42px; height: 42px; background: var(--primary-lt); }
.pcw-send--wide { width: auto; border-radius: 999px; padding: 0 16px; font: inherit; font-size: 13px; font-weight: 600; }
.pcw-legal { text-align: center; font-size: 11px; color: var(--text-faint); margin-top: 6px; }
.pcw-contact { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); flex: none; }
.pcw-contact__title { font-size: 13px; font-weight: 700; }
.pcw-contact .pcw-input { width: 100%; box-sizing: border-box; }
.pcw-contact__actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pcw-contact__actions .pcw-human { margin: 0; }

/* ── phones: full-screen sheets ───────────────────────────────────────────── */
@media (max-width: 640px) {
  .ast-drawer { width: 100vw; }
  .ast-fab { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  #tr-public-chat { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .pcw-panel { position: fixed; inset: 0; width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: none; border-radius: 0; border: none; bottom: auto; }
  .pcw.is-open .pcw-fab { display: none; }
}

/* ── motion ───────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ast-drawer, .ast-fab, .ast-send, .pcw-fab, .pcw-send, .ast-iconbtn, .ast-chip, .pcw-chip, .ast-history__item { transition: none; }
  .pcw-panel { animation: none; }
  .ast-typing span, .pcw-typing span { animation: none; opacity: .6; }
}
