/* Live chat panel for the sign-in wall (public/sign-in/chat.js).
 *
 * The same design as the storefront widget (src/components/LiveChat.tsx): ink
 * header, lilac accents, cream thread, white team bubbles, ink visitor bubbles.
 * A full-screen sheet on phones; a 400px floating panel bottom-right from
 * 1024px. Loaded by /sign-in/ and /welcome/, so the panel carries its own
 * copy of the tokens it uses (the same values as gate.css), scoped to itself.
 */

.bpc[hidden], .bpc [hidden] { display: none !important; }
.bpc *, .bpc *::before, .bpc *::after { box-sizing: border-box; }

.bpc {
  --brand-h: 255;
  --secondary: 40 20% 94%;
  --color-bg: hsl(40 20% 97%);
  --color-fg: hsl(30 10% 15%);
  --color-card: hsl(40 15% 100%);
  --color-muted-fg: hsl(30 5% 46%);
  --color-border: hsl(35 12% 88%);
  --color-hero-lilac: hsl(var(--brand-h) 30% 75%);
  --color-brand-deep: hsl(var(--brand-h) 22% 56%);
  --color-lilac-tint: hsl(var(--brand-h) 45% 94%);
  --dark-bg: hsl(30 15% 8%);
  --dark-fg: hsl(35 10% 95%);
  --dark-muted: hsl(35 10% 65%);
  --dark-line: hsl(0 0% 100% / 0.14);
  --dark-fill: hsl(0 0% 100% / 0.08);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  box-sizing: border-box;
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; overflow: hidden;
  height: 100vh; height: 100dvh;
  background: var(--color-bg); color: var(--color-fg);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  box-shadow: 0 30px 80px -20px rgba(23, 20, 18, .45);
  animation: bpc-up .3s var(--ease-out);
}
.bpc:focus { outline: none; }
html.bpc-lock, html.bpc-lock body { overflow: hidden; }
/* Phones: paint the chat's background below and around the full-screen sheet.
   iOS 26 Safari can shrink the page for the keyboard and floats its address
   bar over a strip where the page behind shows through; this covers it
   whatever Safari does (same as src/hooks/use-keyboard-fit.ts). */
@media (max-width: 1023px) {
  .bpc { box-shadow: 0 50vh 0 50vh var(--color-bg); }
}
@media (min-width: 1024px) {
  .bpc {
    inset: auto 24px 24px auto; width: 400px;
    height: min(680px, calc(100vh - 48px)); height: min(680px, calc(100dvh - 48px));
    border-radius: 24px; border: 1px solid var(--color-border);
    animation-name: bpc-pop;
  }
  body.bpc-open .ink-wfab, body.bpc-open .ink-wmenu { display: none; }
}
@keyframes bpc-up { from { opacity: 0; transform: translateY(100%); } to { opacity: 1; transform: none; } }
@keyframes bpc-pop { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }

/* header */
.bpc-hd {
  position: relative; flex-shrink: 0; overflow: hidden;
  background: var(--dark-bg); color: var(--dark-fg);
  padding: max(calc(env(safe-area-inset-top) + 14px), 22px) 20px 18px;
  border-radius: 0 0 28px 28px;
}
.bpc-hd::before {
  content: ""; position: absolute; right: -60px; top: -80px; width: 200px; height: 200px;
  border-radius: 50%; background: hsl(var(--brand-h) 30% 75% / .18); pointer-events: none;
}
.bpc-hd-row { position: relative; display: flex; align-items: center; gap: 12px; }
.bpc-logo { position: relative; flex-shrink: 0; width: 42px; height: 42px; border-radius: 14px; background: hsl(0 0% 100% / .1); display: grid; place-items: center; }
.bpc-logo img { width: 28px; height: auto; display: block; }
.bpc-dot { position: absolute; right: -3px; bottom: -3px; width: 12px; height: 12px; border-radius: 50%; background: #22c55e; border: 2px solid var(--dark-bg); }
.bpc-dot.is-away { background: #f59e0b; }
.bpc-hd h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.bpc-hd-sub { display: block; margin-top: 2px; font-size: 12px; color: var(--dark-muted); }
.bpc-x {
  margin-left: auto; flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--dark-fill); border: 1px solid var(--dark-line); color: var(--dark-fg);
}
.bpc-x svg { width: 16px; height: 16px; }
.bpc-x:focus-visible { outline: 2px solid var(--color-hero-lilac); outline-offset: 2px; }

/* scrolling body */
.bpc-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 16px 12px; display: flex; flex-direction: column; gap: 14px; }

/* instant answers */
.bpc-faq h3, .bpc-form h3 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.bpc-faq-k { margin: 0 0 8px; font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--color-muted-fg); }
.bpc-faq-list { display: flex; flex-direction: column; gap: 6px; }
.bpc-faq-item { border: 1px solid var(--color-border); border-radius: 14px; background: var(--color-card); }
.bpc-faq-item summary { list-style: none; cursor: pointer; padding: 11px 14px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.bpc-faq-item summary::-webkit-details-marker { display: none; }
.bpc-faq-item summary::after { content: "+"; margin-left: auto; font-weight: 400; font-size: 18px; color: var(--color-muted-fg); }
.bpc-faq-item[open] summary::after { content: "\2212"; }
.bpc-faq-item p { margin: 0; padding: 0 14px 12px; font-size: 13px; line-height: 1.55; color: var(--color-muted-fg); white-space: pre-wrap; overflow-wrap: anywhere; }
.bpc-faq-item a, .bpc-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }

/* pre-chat form */
.bpc-form { display: flex; flex-direction: column; gap: 12px; padding: 2px; }
.bpc-form p.bpc-lead { margin: 0; font-size: 14px; line-height: 1.5; color: var(--color-muted-fg); }
.bpc-away { display: flex; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--color-lilac-tint); color: var(--color-brand-deep); font-size: 13px; line-height: 1.5; }
.bpc-label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 500; color: var(--color-muted-fg); }
.bpc-input {
  height: 46px; width: 100%; min-width: 0; box-sizing: border-box; border-radius: 12px;
  border: 1px solid var(--color-border); background: var(--color-card); color: var(--color-fg);
  padding: 0 14px; font: inherit; font-size: 16px; outline: none;
}
.bpc-input:focus { border-color: var(--color-fg); }
.bpc-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.bpc-chip { border-radius: 999px; border: 1px solid var(--color-border); background: var(--color-card); color: var(--color-fg); padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.bpc-chip[aria-pressed="true"] { background: var(--dark-bg); border-color: var(--dark-bg); color: var(--dark-fg); }
.bpc-cta { height: 48px; width: 100%; border: 0; border-radius: 999px; background: var(--color-fg); color: #fff; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
.bpc-cta:disabled { opacity: .6; cursor: default; }
.bpc-fine { margin: 0; text-align: center; font-size: 11px; line-height: 1.5; color: var(--color-muted-fg); }
.bpc-chip:focus-visible, .bpc-cta:focus-visible, .bpc-faq-item summary:focus-visible, .bpc-icon:focus-visible, .bpc-send:focus-visible { outline: 2px solid var(--color-brand-deep); outline-offset: 2px; }

/* thread */
.bpc-thread { display: flex; flex-direction: column; gap: 10px; }
.bpc-day { align-self: center; border-radius: 999px; padding: 4px 10px; font-size: 11px; color: var(--color-muted-fg); background: hsl(var(--secondary)); }
.bpc-msg { display: flex; flex-direction: column; gap: 3px; max-width: 82%; min-width: 0; align-self: flex-start; }
.bpc-msg.is-mine { align-self: flex-end; align-items: flex-end; }
.bpc-msg.is-pending { opacity: .6; }
.bpc-msg.is-cont { margin-top: -6px; }
.bpc-who { margin-bottom: 2px; font-size: 11px; font-weight: 600; color: var(--color-muted-fg); }
.bpc-bubble { border-radius: 16px 16px 16px 4px; border: 1px solid var(--color-border); background: var(--color-card); padding: 10px 14px; font-size: 14px; line-height: 1.5; }
.bpc-msg.is-mine .bpc-bubble { border-radius: 16px 16px 4px 16px; background: var(--dark-bg); border-color: var(--dark-bg); color: var(--dark-fg); }
.bpc-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bpc-time { font-size: 10px; color: var(--color-muted-fg); }
.bpc-photo { padding: 0; overflow: hidden; }
.bpc-photo img { display: block; max-width: 100%; width: 240px; height: auto; max-height: 320px; object-fit: cover; background: hsl(var(--secondary)); }
.bpc-photo .bpc-text { padding: 8px 12px; }
.bpc-card { padding: 0; overflow: hidden; min-width: 220px; }
.bpc-card-k { display: block; padding: 8px 14px; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; background: var(--color-lilac-tint); color: var(--color-brand-deep); }
.bpc-card-b { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; }
.bpc-card-b b { font-size: 14px; }
.bpc-card-meta { font-size: 13px; color: var(--color-muted-fg); }
.bpc-card-meta strong { color: var(--color-fg); }
.bpc-pay { display: block; margin-top: 4px; border-radius: 999px; padding: 10px; text-align: center; font-size: 13px; font-weight: 600; text-decoration: none; background: var(--dark-bg); color: var(--dark-fg); }
.bpc-state { display: block; margin-top: 4px; border-radius: 999px; padding: 8px; text-align: center; font-size: 12px; font-weight: 600; background: hsl(var(--secondary)); color: var(--color-muted-fg); }
.bpc-state.is-paid { background: hsl(142 60% 92%); color: hsl(142 60% 28%); }
.bpc-small { font-size: 11px; color: var(--color-muted-fg); }

.bpc-typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; border-radius: 16px 16px 16px 4px; border: 1px solid var(--color-border); background: var(--color-card); }
.bpc-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--color-muted-fg); animation: bpc-tp 1.2s infinite; }
.bpc-typing i:nth-child(2) { animation-delay: .2s; }
.bpc-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes bpc-tp { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

.bpc-err { flex-shrink: 0; margin: 0; padding: 6px 16px; font-size: 12px; color: hsl(0 60% 40%); background: hsl(0 60% 96%); }

/* composer */
.bpc-compose { flex-shrink: 0; display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--color-border); background: var(--color-card); }
.bpc-compose textarea {
  flex: 1; min-width: 0; resize: none; max-height: 120px; min-height: 42px; box-sizing: border-box;
  border-radius: 21px; border: 1px solid var(--color-border); background: var(--color-bg); color: var(--color-fg);
  padding: 10px 14px; font: inherit; font-size: 16px; line-height: 1.35; outline: none;
}
.bpc-compose textarea:focus { border-color: var(--color-fg); }
.bpc-icon, .bpc-send { flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; border: 0; }
.bpc-icon { background: hsl(var(--secondary)); color: var(--color-fg); }
.bpc-send { background: var(--color-fg); color: #fff; }
.bpc-send:disabled, .bpc-icon:disabled { opacity: .5; cursor: default; }
.bpc-icon svg, .bpc-send svg { width: 18px; height: 18px; }
.bpc-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) { .bpc, .bpc-typing i { animation: none; } }
