/* Chat widget on top of a screenshot of the business's own homepage.
   Brand values (--brand, --brand-ink, --brand-text, --font) are set from business.json by app.js. */
:root {
  --brand: #1f5f8b; --brand-ink: #fff; --brand-text: #1f5f8b;
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --ink: #1d1f23; --muted: #5f646c; --line: #e6e8ec; --bubble: #f1f2f4; --surface: #fff;
  --radius: 16px; --ease: cubic-bezier(.25, 1, .5, 1);
  --z-scrim: 10; --z-panel: 20; --z-launcher: 30;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: #f4f5f7; overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }

/* Their homepage, as a still backdrop */
.site { position: fixed; inset: 0; }
.site img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top center; user-select: none; }
.scrim { position: fixed; inset: 0; z-index: var(--z-scrim); background: rgb(0 0 0 / .32); opacity: 0; pointer-events: none; transition: opacity .2s var(--ease); }

/* Launcher: bottom-right, bottom-left in RTL (inline-end) */
.launcher {
  position: fixed; z-index: var(--z-launcher); bottom: 24px; inset-inline-end: 24px;
  width: 60px; height: 60px; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; background: var(--brand); color: var(--brand-ink);
  box-shadow: 0 6px 20px rgb(0 0 0 / .22), 0 1px 3px rgb(0 0 0 / .15);
  transition: transform .2s var(--ease);
}
.launcher:hover { transform: scale(1.05); }
.launcher:active { transform: scale(.96); }
.launcher:focus-visible { outline: 3px solid var(--brand-text); outline-offset: 3px; }
.launcher > svg { grid-area: 1 / 1; transition: opacity .15s, transform .2s var(--ease); }
.launcher .i-close, .open-chat .launcher .i-open { opacity: 0; transform: rotate(-30deg) scale(.7); }
.open-chat .launcher .i-close { opacity: 1; transform: none; }

/* Panel */
.panel {
  position: fixed; z-index: var(--z-panel); bottom: 100px; inset-inline-end: 24px;
  width: 384px; height: min(580px, calc(100dvh - 124px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 18px 50px rgb(0 0 0 / .22), 0 2px 8px rgb(0 0 0 / .12);
  opacity: 0; visibility: hidden; transform: translateY(12px) scale(.98); transform-origin: bottom right;
  transition: opacity .2s var(--ease), transform .25s var(--ease), visibility 0s .25s;
}
[dir="rtl"] .panel { transform-origin: bottom left; }
.open-chat .panel { opacity: 1; visibility: visible; transform: none; transition: opacity .2s var(--ease), transform .25s var(--ease), visibility 0s; }

.head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.logo { max-height: 34px; max-width: 120px; object-fit: contain; flex: none; }
.name { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; line-height: 1.25; text-wrap: balance; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.close { display: none; flex: none; width: 40px; height: 40px; margin-inline-end: -8px; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; place-items: center; }
.close:hover { background: var(--bubble); color: var(--ink); }
.close:focus-visible { outline: 2px solid var(--brand-text); }

.log { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.msg { max-width: 84%; padding: 9px 13px; border-radius: 18px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; unicode-bidi: plaintext; animation: in .22s var(--ease); }
.msg.assistant { align-self: flex-start; background: var(--bubble); border-end-start-radius: 6px; }
.msg.user { align-self: flex-end; background: var(--brand-text); color: #fff; border-end-end-radius: 6px; }
.msg + .msg.user, .msg.user + .msg { margin-top: 6px; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); opacity: .35; animation: dot 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 30% { opacity: 1; transform: translateY(-2px); } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0 2px; }
.chips:empty, .chips[hidden] { display: none; }
.chips button {
  border: 1px solid color-mix(in srgb, var(--brand-text) 45%, white); background: var(--surface); color: var(--brand-text);
  border-radius: 999px; padding: 7px 13px; font-size: 14px; line-height: 1.3; cursor: pointer; text-align: start;
  transition: background-color .15s;
}
.chips button:hover { background: color-mix(in srgb, var(--brand) 9%, white); }
.chips button:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 1px; }

.composer { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; border-top: 1px solid var(--line); }
.composer input { flex: 1; min-width: 0; height: 44px; padding: 0 16px; font-size: 16px; border: 1px solid #d5d8de; border-radius: 22px; background: var(--surface); }
.composer input::placeholder { color: #6b7079; }
.composer input:focus { outline: none; border-color: var(--brand-text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.send { flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); cursor: pointer; transition: opacity .15s; }
.send:disabled { opacity: .45; cursor: default; }
.send:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 2px; }
[dir="rtl"] .send svg { transform: scaleX(-1); }
.note { margin: 0; padding: 4px 16px 10px; text-align: center; font-size: 12px; line-height: 1.4; color: var(--muted); }

/* Phone: closed until the first tap, then a sheet over a slightly dimmed site */
@media (max-width: 640px) {
  .launcher { bottom: 20px; inset-inline-end: 18px; }
  .panel {
    inset: auto 0 0 0; width: auto; height: min(88dvh, 720px);
    border-radius: var(--radius) var(--radius) 0 0; padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(24px); transform-origin: bottom center;
  }
  [dir="rtl"] .panel { transform-origin: bottom center; }
  .open-chat .scrim { opacity: 1; pointer-events: auto; }
  .open-chat .launcher { opacity: 0; pointer-events: none; }
  .close { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
