/* WhatsApp look-alike chat page. Shared by all five demo sites.
   Layout: green band + grey page, centred chat card on desktop, full screen on phones. */

:root {
  color-scheme: light dark;
  --wa-page: #d1d7db;
  --wa-page-top: #00a884;
  --wa-chat-solid: #efeae2;
}
html.wa-dark {
  --wa-page: #0b141a;
  --wa-page-top: #0b141a;
  --wa-chat-solid: #0b141a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(var(--wa-page-top) 0 128px, var(--wa-page) 128px);
  font-family: Roboto, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
.stage { min-height: 100%; display: grid; place-items: center; padding: 16px; }

.wa {
  --wa-header: #008069;
  --wa-header-text: #fff;
  --wa-header-sub: rgba(255, 255, 255, 0.86);
  --wa-typing: #fff;
  --wa-bg: #efeae2;
  --wa-in: #fff;
  --wa-out: #d9fdd3;
  --wa-text: #111b21;
  --wa-meta: #667781;
  --wa-out-meta: #667781;
  --wa-tick: #53bdeb;
  --wa-accent: #00a884;
  --wa-send-ink: #fff;
  --wa-input-bg: #fff;
  --wa-icon: #54656f;
  --wa-btn: #027eb5;
  --wa-link: #027eb5;
  --wa-divider: rgba(11, 20, 26, 0.12);
  --wa-menu: #fff;
  --wa-chip: rgba(255, 255, 255, 0.92);
  --wa-chip-text: #54656f;
  --wa-badge: #fff;
  --wa-badge-check: #008069;
  --wa-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --wa-doodle: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'><g fill='none' stroke='%23000' stroke-opacity='.075' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><circle cx='32' cy='34' r='9'/><path d='M88 22l5 10 11 1.5-8 8 2 11-10-5.5L78 52.5l2-11-8-8 11-1.5z'/><path d='M160 44c-6-9-20-3-14 7 4 6 14 11 14 11s10-5 14-11c6-10-8-16-14-7z'/><rect x='204' y='20' width='16' height='26' rx='3'/><path d='M22 110h26M35 97v26'/><path d='M88 110c0-10 20-10 20 0s-20 10-20 0z'/><path d='M150 102l12 12M162 102l-12 12'/><circle cx='206' cy='112' r='5'/><path d='M26 184q10-14 20 0t20 0'/><path d='M104 168h32v22h-32zM104 168l16 12 16-12'/><circle cx='190' cy='180' r='11'/><path d='M184 180l4 4 8-8'/><path d='M60 226l8-8 8 8'/><path d='M150 222h26'/><circle cx='222' cy='222' r='4'/></g></svg>");
  --wa-tail: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13'><path d='M8 0H0C3.5 1 7 4.5 8 13z'/></svg>");

  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 440px);
  height: min(840px, calc(100vh - 32px));
  height: min(840px, calc(100dvh - 32px));
  overflow: hidden;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  color: var(--wa-text);
  font-size: 16px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  text-align: left;
  touch-action: manipulation; /* no double-tap zoom on bubbles */
}
.wa button { font: inherit; color: inherit; touch-action: manipulation; }

.wa.dark {
  --wa-header: #1f2c34;
  --wa-header-text: #e9edef;
  --wa-header-sub: #8696a0;
  --wa-typing: #00a884;
  --wa-bg: #0b141a;
  --wa-in: #1f2c34;
  --wa-out: #005c4b;
  --wa-text: #e9edef;
  --wa-meta: #8696a0;
  --wa-out-meta: #8fb8b0;
  --wa-send-ink: #111b21;
  --wa-input-bg: #1f2c34;
  --wa-icon: #8696a0;
  --wa-btn: #53bdeb;
  --wa-link: #53bdeb;
  --wa-divider: rgba(255, 255, 255, 0.1);
  --wa-menu: #233138;
  --wa-chip: #182229;
  --wa-chip-text: #8696a0;
  --wa-badge: #00a884;
  --wa-badge-check: #fff;
  --wa-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.35);
  --wa-doodle: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'><g fill='none' stroke='%23fff' stroke-opacity='.045' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><circle cx='32' cy='34' r='9'/><path d='M88 22l5 10 11 1.5-8 8 2 11-10-5.5L78 52.5l2-11-8-8 11-1.5z'/><path d='M160 44c-6-9-20-3-14 7 4 6 14 11 14 11s10-5 14-11c6-10-8-16-14-7z'/><rect x='204' y='20' width='16' height='26' rx='3'/><path d='M22 110h26M35 97v26'/><path d='M88 110c0-10 20-10 20 0s-20 10-20 0z'/><path d='M150 102l12 12M162 102l-12 12'/><circle cx='206' cy='112' r='5'/><path d='M26 184q10-14 20 0t20 0'/><path d='M104 168h32v22h-32zM104 168l16 12 16-12'/><circle cx='190' cy='180' r='11'/><path d='M184 180l4 4 8-8'/><path d='M60 226l8-8 8 8'/><path d='M150 222h26'/><circle cx='222' cy='222' r='4'/></g></svg>");
}

.wa-i { width: 24px; height: 24px; fill: currentColor; flex: none; display: block; }

/* ---------- header ---------- */
.wa-header {
  position: relative; z-index: 5; flex: none; min-height: 58px;
  display: flex; align-items: center; gap: 2px; padding: 4px 4px 4px 6px;
  background: var(--wa-header); color: var(--wa-header-text);
}
.wa-hbtn {
  width: 44px; height: 44px; flex: none; border: 0; background: none; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; color: inherit;
}
.wa-hbtn:hover { background: rgba(127, 127, 127, 0.15); }
.wa-back { margin: 0; }
.wa-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; overflow: hidden;
  display: grid; place-items: center; font-size: 21px; margin: 0 8px 0 2px;
}
.wa-avatar img { width: 100%; height: 100%; object-fit: cover; }
.wa-title { flex: 1; min-width: 0; }
.wa-name { display: flex; align-items: center; gap: 4px; font-size: 1.125rem; font-weight: 500; line-height: 1.2; }
.wa-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-verified { flex: none; width: 16px; height: 16px; }
.wa-verified svg { width: 16px; height: 16px; display: block; }
.wa-status { margin-top: 1px; font-size: 0.8125rem; line-height: 1.2; color: var(--wa-header-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-status.typing { color: var(--wa-typing); }
.wa-menu {
  position: absolute; top: 46px; right: 6px; z-index: 20; min-width: 190px; padding: 8px 0;
  background: var(--wa-menu); color: var(--wa-text); border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4); display: none;
}
.wa-menu.open { display: block; }
.wa-menu button {
  display: block; width: 100%; min-height: 48px; padding: 12px 20px; text-align: left; border: 0; background: none; cursor: pointer;
}
.wa-menu button:hover { background: rgba(127, 127, 127, 0.15); }

/* ---------- body / wallpaper ---------- */
.wa-body {
  position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column;
  background-color: var(--wa-bg); background-image: var(--wa-doodle); background-size: 300px 300px;
}
.wa-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 8px 12px 12px;
  display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: rgba(127, 127, 127, 0.45) transparent;
}

.wa-chip {
  align-self: center; margin: 6px 0 10px; padding: 5px 12px; border-radius: 8px;
  background: var(--wa-chip); color: var(--wa-chip-text); box-shadow: var(--wa-shadow);
  font-size: 0.78125rem; line-height: 1.3;
}
.wa-system {
  align-self: center; max-width: 92%; margin: 8px 0; padding: 6px 12px; border-radius: 8px; text-align: center;
  background: var(--wa-chip); color: var(--wa-chip-text); box-shadow: var(--wa-shadow); font-size: 0.78125rem; line-height: 1.35;
}
.wa-system.error { background: #fde7e7; color: #a12727; }
.wa.dark .wa-system.error { background: #3a1d1d; color: #ff9d9d; }

/* ---------- messages ---------- */
.wa-msg { display: flex; flex-direction: column; min-width: 0; }
.wa-msg.in { align-items: flex-start; }
.wa-msg.out { align-items: flex-end; }
.wa-msg.first { margin-top: 8px; }
.wa-col { display: flex; flex-direction: column; gap: 2px; max-width: 82%; min-width: 0; }
.wa-msg.out .wa-col { align-items: flex-end; }

.wa-bubble {
  --bg: var(--wa-in);
  position: relative; padding: 6px 8px 8px 9px; border-radius: 8px; background: var(--bg);
  box-shadow: var(--wa-shadow); color: var(--wa-text); min-width: 64px; max-width: 100%;
  animation: wa-pop 0.16s ease-out; overflow-wrap: anywhere;
}
.wa-msg.out .wa-bubble { --bg: var(--wa-out); }
.wa-msg.in.tail .wa-bubble { border-top-left-radius: 0; }
.wa-msg.out.tail .wa-bubble { border-top-right-radius: 0; }
.wa-msg.tail .wa-bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px; background: var(--bg);
  -webkit-mask: var(--wa-tail) center / 100% 100% no-repeat; mask: var(--wa-tail) center / 100% 100% no-repeat;
}
.wa-msg.in.tail .wa-bubble::before { left: -8px; }
.wa-msg.out.tail .wa-bubble::before { right: -8px; transform: scaleX(-1); }
@keyframes wa-pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }

.wa-text { white-space: pre-wrap; font-size: 1rem; line-height: 1.3125; }
/* Leaves room at the end of the last line for the time, so it sits inside the bubble like WhatsApp. */
.wa-text::after { content: ""; display: inline-block; height: 1px; width: 54px; }
.wa-msg.out .wa-text::after { width: 76px; }
.wa-text a { color: var(--wa-link); text-decoration: none; }
.wa-text a:hover { text-decoration: underline; }
.wa-text code { font-family: Consolas, "SF Mono", monospace; font-size: 0.92em; }
.wa-text b { font-weight: 700; }

.wa-time {
  position: absolute; right: 8px; bottom: 5px; display: flex; align-items: center; gap: 3px;
  font-size: 0.6875rem; line-height: 1; color: var(--wa-meta); white-space: nowrap; user-select: none;
}
.wa-msg.out .wa-time { color: var(--wa-out-meta); }
.wa-tick { width: 16px; height: 16px; fill: var(--wa-out-meta); margin: -3px 0; }
.wa-tick.read { fill: var(--wa-tick); }

.wa-bubble.has-img { padding: 3px; }
.wa-bubble.has-img .wa-text { padding: 3px 5px 5px 6px; }
.wa-img img { display: block; width: 100%; max-width: 250px; max-height: 320px; object-fit: cover; border-radius: 6px; }
.wa-bubble.has-img .wa-time.on-img { right: 9px; bottom: 7px; color: #fff; text-shadow: 0 0 4px rgba(0, 0, 0, 0.6); }
.wa-bubble.has-img .wa-time.on-img .wa-tick { fill: #fff; }
.wa-bubble.has-img .wa-time.on-img .wa-tick.read { fill: var(--wa-tick); }
.wa-bubble.has-img .wa-time:not(.on-img) { right: 10px; bottom: 6px; }
.wa-photo-chip { color: var(--wa-meta); font-style: italic; }

/* quick-reply buttons (under the bot bubble, like WhatsApp Business) */
.wa-qrs { display: flex; flex-direction: column; gap: 3px; width: min(100vw, 330px); max-width: 100%; }
.wa-qr {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 46px; padding: 10px 14px;
  border: 0; border-radius: 8px; background: var(--wa-in); color: var(--wa-btn); font-size: 0.96875rem; text-align: center;
  box-shadow: var(--wa-shadow); cursor: pointer;
}
.wa-qr:active { filter: brightness(0.94); }
.wa-qr .wa-i { width: 18px; height: 18px; }

/* booking / summary card */
.wa-card-title { font-weight: 700; display: flex; gap: 6px; align-items: center; padding-bottom: 5px; margin-bottom: 5px; border-bottom: 1px solid var(--wa-divider); }
.wa-card-line { display: flex; gap: 8px; padding: 1.5px 0; font-size: 0.9375rem; }
.wa-card-line .k { color: var(--wa-meta); flex: none; }
.wa-card-line .v { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* catalog carousel */
.wa-msg.wide { align-self: stretch; }
.wa-carousel {
  display: flex; gap: 6px; overflow-x: auto; scroll-snap-type: x proximity; padding: 2px 12px 6px 0; margin: 4px 0 0;
  max-width: 100%; scrollbar-width: none;
}
.wa-carousel::-webkit-scrollbar { display: none; }
.wa-item {
  flex: 0 0 236px; display: flex; flex-direction: column; overflow: hidden; scroll-snap-align: start;
  background: var(--wa-in); border-radius: 8px; box-shadow: var(--wa-shadow);
}
.wa-item-media { position: relative; height: 132px; background-size: cover; background-position: center; display: grid; place-items: center; font-size: 48px; }
.wa-item-media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.wa-item-body { padding: 8px 10px 10px; flex: 1; }
.wa-item-title { font-weight: 700; font-size: 0.96875rem; line-height: 1.25; }
.wa-item-sub { color: var(--wa-meta); font-size: 0.84375rem; line-height: 1.3; margin-top: 2px; }
.wa-item-price { margin-top: 6px; font-weight: 700; color: var(--wa-accent); }
.wa-item-cta {
  border: 0; border-top: 1px solid var(--wa-divider); background: none; padding: 11px; width: 100%; min-height: 44px;
  color: var(--wa-btn); font-size: 0.96875rem; cursor: pointer; display: flex; justify-content: center; gap: 7px; align-items: center;
}
.wa-item-cta .wa-i { width: 17px; height: 17px; }

/* ---------- composer ---------- */
.wa-input { flex: none; position: relative; z-index: 3; display: flex; align-items: flex-end; gap: 6px; padding: 4px 6px calc(6px + env(safe-area-inset-bottom)); }
.wa-pill {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; border-radius: 24px; background: var(--wa-input-bg);
  padding: 0 2px; min-height: 48px; box-shadow: var(--wa-shadow); color: var(--wa-meta);
}
.wa-ibtn {
  width: 44px; height: 48px; flex: none; border: 0; background: none; cursor: pointer; display: grid; place-items: center;
  color: var(--wa-icon); border-radius: 50%;
}
.wa-field {
  flex: 1; min-width: 0; border: 0; outline: 0; resize: none; background: transparent; color: var(--wa-text);
  font: inherit; font-size: 1rem; line-height: 20px; padding: 14px 6px; height: 48px; max-height: 120px; overflow-y: auto;
}
.wa-field::placeholder { color: var(--wa-meta); }
.wa-pill.typing .wa-camera { display: none; }
.wa-sendbtn {
  width: 48px; height: 48px; flex: none; border: 0; border-radius: 50%; background: var(--wa-accent); color: var(--wa-send-ink);
  display: grid; place-items: center; cursor: pointer; box-shadow: 0 1px 1px var(--wa-divider);
}
.wa-sendbtn .i-send { display: none; }
.wa-input.has-text .wa-sendbtn .i-send { display: block; }
.wa-input.has-text .wa-sendbtn .i-mic { display: none; }

.wa-emoji {
  display: none; flex: none; background: var(--wa-menu); border-top: 1px solid var(--wa-divider);
  padding: 8px; max-height: 188px; overflow-y: auto; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.wa-emoji.open { display: grid; }
.wa-emoji button { border: 0; background: none; font-size: 24px; line-height: 1; padding: 6px 0; cursor: pointer; border-radius: 6px; }
.wa-emoji button:hover { background: var(--wa-divider); }

/* photo preview (before sending an image) */
.wa-preview { position: absolute; inset: 0; z-index: 30; display: none; flex-direction: column; background: #0b141a; color: #e9edef; }
.wa-preview.open { display: flex; }
.wa-preview-top { padding: 10px 6px; display: flex; }
.wa-preview-top button { width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: #e9edef; display: grid; place-items: center; cursor: pointer; }
.wa-preview-img { flex: 1; min-height: 0; display: grid; place-items: center; padding: 6px 12px; }
.wa-preview-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.wa-preview-bar { padding: 8px 10px 14px; display: flex; flex-direction: column; gap: 10px; background: linear-gradient(transparent, rgba(0, 0, 0, 0.5)); }
.wa-preview-row { display: flex; gap: 8px; align-items: flex-end; }
.wa-preview-row .wa-pill { background: #202c33; }
.wa-preview-row .wa-field { color: #e9edef; }
.wa-preview-to { align-self: flex-start; background: rgba(32, 44, 51, 0.9); padding: 5px 12px; border-radius: 16px; font-size: 0.8125rem; }

.wa-toast {
  position: absolute; left: 50%; bottom: 76px; z-index: 40; max-width: 86%; transform: translateX(-50%); padding: 9px 15px;
  border-radius: 20px; background: rgba(17, 27, 33, 0.92); color: #fff; font-size: 0.8125rem; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.wa-toast.show { opacity: 1; }

.wa button:focus-visible { outline: 3px solid var(--wa-tick); outline-offset: 2px; }

/* Phones (portrait or landscape): the chat is the whole screen. Height/top follow the visual viewport (see trackViewport). */
@media (max-width: 520px), (max-height: 520px) {
  html, body { overflow: hidden; overscroll-behavior: none; }
  body { background: var(--wa-chat-solid); }
  .stage { padding: 0; display: block; min-height: 0; }
  .wa {
    position: fixed; left: 0; right: 0; width: auto; border-radius: 0; box-shadow: none;
    top: var(--wa-top, 0px); height: var(--wa-vh, 100vh); height: var(--wa-vh, 100dvh);
  }
  .wa-header { padding-top: calc(4px + env(safe-area-inset-top)); padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right)); }
  .wa-scroll { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .wa-input { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
}
@media (prefers-reduced-motion: reduce) {
  .wa-bubble { animation: none; }
}
