[data-maple-chat] *,
[data-maple-chat] *::before,
[data-maple-chat] *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[data-maple-chat] {
  --chat-blue: #0254fe;
  --chat-blue-hover: #0142cc;
  --chat-bg: #ffffff;
  --chat-border: #e5e7eb;
  --chat-text: #1f2a37;
  --chat-text-muted: #6b7280;
  --chat-bubble-user: #0254fe;
  --chat-bubble-bot: #f3f4f6;
  --chat-radius: 16px;
  --chat-shadow: 0 20px 60px rgba(15, 23, 42, 0.15);

  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--chat-text);
}

/* ── Launcher button ── */

[data-maple-chat-launcher] {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--chat-blue);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(2, 84, 254, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

[data-maple-chat-launcher]:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(2, 84, 254, 0.45);
}

[data-maple-chat-launcher] svg {
  width: 30px;
  height: 30px;
  fill: white;
  transition: opacity 0.15s ease;
}

[data-maple-chat-launcher][data-state="open"] .maple-chat-icon-chat {
  display: none;
}

[data-maple-chat-launcher][data-state="closed"] .maple-chat-icon-close {
  display: none;
}

/* ── Panel ── */

[data-maple-chat-panel] {
  display: none;
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 500px;
  max-width: calc(100vw - 32px);
  height: 720px;
  max-height: calc(100vh - 120px);
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  flex-direction: column;
  overflow: hidden;
}

[data-maple-chat-panel][data-state="open"] {
  display: flex;
}

/* ── Header ── */

[data-maple-chat-header] {
  padding: 18px 22px;
  background: var(--chat-blue);
  color: white;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

[data-maple-chat-header-text] {
  flex: 1;
  min-width: 0;
}

[data-maple-chat-new] {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

[data-maple-chat-new]:hover {
  background: rgba(255, 255, 255, 0.3);
}

[data-maple-chat-close] {
  display: none;
}

[data-maple-chat-avatar] {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1;
}

[data-maple-chat-header-text] h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  color: white;
}

[data-maple-chat-header-text] p {
  font-size: 14px;
  margin: 0;
  opacity: 0.8;
  color: white;
}

/* ── Messages area ── */

[data-maple-chat-messages] {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

[data-maple-chat-messages]::-webkit-scrollbar {
  width: 6px;
}

[data-maple-chat-messages]::-webkit-scrollbar-track {
  background: transparent;
}

[data-maple-chat-messages]::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 999px;
}

/* ── Message bubbles ── */

[data-maple-chat-msg] {
  max-width: 85%;
  padding: 14px 18px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 16px;
  line-height: 1.5;
}

[data-maple-chat-msg][data-role="user"] {
  align-self: flex-end;
  background: var(--chat-bubble-user);
  color: white;
  border-bottom-right-radius: 4px;
}

[data-maple-chat-msg][data-role="assistant"] {
  align-self: flex-start;
  background: var(--chat-bubble-bot);
  color: var(--chat-text);
  border-bottom-left-radius: 4px;
}

[data-maple-chat-msg] p {
  margin: 0 0 6px 0;
}

[data-maple-chat-msg] p:last-child {
  margin-bottom: 0;
}

[data-maple-chat-msg] strong {
  font-weight: 600;
}

[data-maple-chat-msg] a {
  color: inherit;
  text-decoration: underline;
}

[data-maple-chat-msg][data-role="assistant"] a {
  color: var(--chat-blue);
}

/* ── Typing indicator ── */

[data-maple-chat-typing] {
  align-self: flex-start;
  display: none;
  gap: 5px;
  padding: 14px 18px;
  margin: 0 20px 12px 20px;
  background: var(--chat-bubble-bot);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

[data-maple-chat-typing][data-visible="true"] {
  display: flex;
}

[data-maple-chat-typing] span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: maple-chat-bounce 1.4s ease-in-out infinite;
}

[data-maple-chat-typing] span:nth-child(2) {
  animation-delay: 0.2s;
}

[data-maple-chat-typing] span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes maple-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* ── Booking success card ── */

[data-maple-chat-booking] {
  align-self: flex-start;
  max-width: 85%;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 16px;
  padding: 16px;
}

[data-maple-chat-booking] .booking-title {
  font-weight: 600;
  font-size: 16px;
  color: #15803d;
  margin-bottom: 4px;
}

[data-maple-chat-booking] .booking-detail {
  font-size: 15px;
  color: #166534;
}

/* ── Quick-reply prompts ── */

[data-maple-chat-prompts] {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 0;
  align-self: flex-end;
  max-width: 100%;
  justify-content: flex-end;
}

[data-maple-chat-prompts]:empty {
  display: none;
}

[data-maple-chat-prompts][data-layout="stack"] {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 6px;
  max-width: 85%;
  align-items: flex-end;
}

[data-maple-chat-prompt] {
  display: inline-block;
  padding: 11px 18px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  color: var(--chat-blue);
  background: white;
  border: 1px solid var(--chat-blue);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  text-align: left;
}

[data-maple-chat-prompt]:hover {
  background: var(--chat-blue);
  color: white;
}

[data-maple-chat-prompts][data-layout="stack"] [data-maple-chat-prompt] {
  width: 100%;
  padding: 13px 20px;
  border-radius: 14px;
  font-size: 16px;
  text-align: center;
}

/* ── Inline form inputs (collect_input) ── */

[data-maple-chat-form] {
  align-self: flex-end;
  max-width: 85%;
  width: 85%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 0 0;
}

[data-maple-chat-form][data-form-type="place"] {
  max-width: 85%;
  width: 85%;
}

[data-maple-chat-form-label] {
  font-size: 13px;
  color: var(--chat-text-muted);
  padding-left: 2px;
}

[data-maple-chat-form-row] {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

[data-maple-chat-form-input] {
  flex: 1;
  border: 1.5px solid var(--chat-border);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  color: var(--chat-text);
  background: var(--chat-bg);
  transition: border-color 0.15s ease;
  min-width: 0;
}

[data-maple-chat-form-input]:focus {
  border-color: var(--chat-blue);
}

[data-maple-chat-form-input]::placeholder {
  color: #9ca3af;
}

[data-maple-chat-form-input][data-invalid="true"] {
  border-color: #ef4444;
}

[data-maple-chat-form-error] {
  font-size: 12px;
  color: #ef4444;
  padding-left: 2px;
  min-height: 0;
}

[data-maple-chat-form-submit] {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--chat-blue);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
  align-self: flex-start;
}

[data-maple-chat-form-submit]:hover {
  background: var(--chat-blue-hover);
}

[data-maple-chat-form-submit] svg {
  width: 18px;
  height: 18px;
  fill: white;
}

/* Places autocomplete dropdown (appears above input) */
[data-maple-chat-places-results] {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  margin-bottom: 4px;
  max-height: 240px;
  overflow-y: auto;
}

[data-maple-chat-place-item] {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.1s ease;
  border-bottom: 1px solid var(--chat-border);
}

[data-maple-chat-place-item]:last-child {
  border-bottom: none;
}

[data-maple-chat-place-item]:hover {
  background: #f3f4f6;
}

[data-maple-chat-place-name] {
  font-size: 14px;
  font-weight: 500;
  color: var(--chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-maple-chat-place-address] {
  font-size: 12px;
  color: var(--chat-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

[data-maple-chat-places-wrap] {
  position: relative;
  flex: 1;
  min-width: 0;
}

[data-maple-chat-places-wrap] [data-maple-chat-form-input] {
  width: 100%;
}

/* Place map preview card */
[data-maple-chat-place-card] {
  align-self: stretch;
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  background: var(--chat-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
}

[data-maple-chat-place-card] img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}

[data-maple-chat-place-card-info] {
  padding: 10px 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

[data-maple-chat-place-card-pin] {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--chat-text-muted);
}

[data-maple-chat-place-card-text] {
  flex: 1;
  min-width: 0;
}

[data-maple-chat-place-card-name] {
  font-size: 14px;
  font-weight: 600;
  color: var(--chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-maple-chat-place-card-address] {
  font-size: 12px;
  color: var(--chat-text-muted);
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

[data-maple-chat-place-card-actions] {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  margin-top: 1px;
}

[data-maple-chat-place-card-btn] {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-text-muted);
  transition: background 0.1s ease, color 0.1s ease;
}

[data-maple-chat-place-card-btn]:hover {
  background: #f3f4f6;
  color: var(--chat-text);
}

/* ── Input area ── */

[data-maple-chat-input-area] {
  padding: 12px 20px 6px;
  border-top: 1px solid var(--chat-border);
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-shrink: 0;
  background: var(--chat-bg);
}

[data-maple-chat-input] {
  flex: 1;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  padding: 13px 18px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  height: 48px;
  min-height: 48px;
  max-height: 120px;
  overflow-y: auto;
  color: var(--chat-text);
  background: var(--chat-bg);
}

[data-maple-chat-input]:focus {
  border-color: var(--chat-blue);
}

[data-maple-chat-input]::placeholder {
  color: #9ca3af;
}

[data-maple-chat-send] {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--chat-blue);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

[data-maple-chat-send]:hover {
  background: var(--chat-blue-hover);
}

[data-maple-chat-send]:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

[data-maple-chat-send] svg {
  width: 20px;
  height: 20px;
  fill: white;
}

/* ── Powered by ── */

[data-maple-chat-footer] {
  text-align: center;
  padding: 4px 8px 8px;
  font-size: 13px;
  color: #9ca3af;
  flex-shrink: 0;
}

/* ── Mobile: full-screen takeover ── */

@media (max-width: 640px) {
  [data-maple-chat] {
    bottom: 16px;
    right: 16px;
  }

  [data-maple-chat-panel] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  [data-maple-chat-panel][data-state="open"] ~ [data-maple-chat-launcher] {
    display: none;
  }

  [data-maple-chat-close] {
    display: flex;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
  }

  [data-maple-chat-close]:hover {
    background: rgba(255, 255, 255, 0.3);
  }

  [data-maple-chat-header] {
    padding: 16px 20px;
    padding-top: max(16px, env(safe-area-inset-top, 16px));
  }

  [data-maple-chat-input-area] {
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  }

  [data-maple-chat-footer] {
    padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
  }
}
