/* Wavy Assistant chat */
.chat-page {
  max-width: 720px;
  margin: 0 auto;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  height: min(72vh, 640px);
  min-height: 420px;
  background: var(--wavy-surface);
  border: 1px solid var(--wavy-border);
  border-radius: var(--wavy-radius-xl);
  overflow: hidden;
  box-shadow: var(--wavy-shadow-purple);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.25), rgba(212, 175, 55, 0.08));
  border-bottom: 1px solid var(--wavy-border);
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wavy-purple-dim);
  border: 1px solid var(--wavy-border-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.chat-header-text h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
}

.chat-header-text p {
  font-size: 0.75rem;
  color: var(--wavy-muted);
  margin: 2px 0 0;
}

.chat-status {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--wavy-success);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wavy-success);
  box-shadow: 0 0 8px var(--wavy-success);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 88%;
  animation: chatIn 0.28s var(--wavy-ease);
}

@keyframes chatIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg--bot {
  align-self: flex-start;
}

.chat-msg--user {
  align-self: flex-end;
}

.chat-bubble {
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg--bot .chat-bubble {
  background: var(--wavy-surface2);
  border: 1px solid var(--wavy-border);
  border-bottom-left-radius: 4px;
  color: var(--wavy-text-soft);
}

.chat-msg--user .chat-bubble {
  background: linear-gradient(135deg, var(--wavy-purple-dark), var(--wavy-purple));
  border-bottom-right-radius: 4px;
  color: #fff;
}

.chat-msg--typing .chat-bubble {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
}

.chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wavy-muted);
  animation: chatDot 1.2s infinite;
}

.chat-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatDot {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
}

.chat-quick-btn {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--wavy-border-gold);
  background: var(--wavy-gold-dim);
  color: var(--wavy-gold-light);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.chat-quick-btn:hover {
  background: rgba(212, 175, 55, 0.22);
  transform: translateY(-1px);
}

.chat-quick-btn--primary {
  border-color: var(--wavy-purple);
  background: var(--wavy-purple-dim);
  color: var(--wavy-purple-light);
}

.chat-form-inline {
  padding: 0 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-form-inline select,
.chat-form-inline input {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 10px 12px;
  border-radius: var(--wavy-radius);
  border: 1px solid var(--wavy-border);
  background: var(--wavy-surface2);
  color: var(--wavy-text);
}

.chat-form-inline button {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 10px;
  border-radius: var(--wavy-radius);
  border: none;
  background: var(--wavy-gold);
  color: var(--wavy-black);
  font-weight: 600;
  cursor: pointer;
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--wavy-border-subtle);
  background: var(--wavy-surface2);
}

.chat-input-bar input {
  flex: 1;
  font-family: inherit;
  font-size: 0.88rem;
  padding: 11px 14px;
  border-radius: 999px;
  border: 1px solid var(--wavy-border);
  background: var(--wavy-surface);
  color: var(--wavy-text);
  outline: none;
}

.chat-input-bar input:focus {
  border-color: var(--wavy-purple);
  box-shadow: 0 0 0 3px var(--wavy-purple-dim);
}

.chat-input-bar input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--wavy-gold);
  color: var(--wavy-black);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send:not(:disabled):hover {
  transform: scale(1.05);
}

.chat-link-card {
  margin-top: 8px;
  padding: 12px;
  border-radius: var(--wavy-radius);
  background: var(--wavy-gold-dim);
  border: 1px solid var(--wavy-border-gold);
}

.chat-link-card .link-url {
  font-size: 0.78rem;
  word-break: break-all;
  color: var(--wavy-gold-light);
  margin: 8px 0;
  padding: 8px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
}

.chat-link-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chat-link-actions button {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--wavy-border);
  background: var(--wavy-surface);
  color: var(--wavy-text);
  cursor: pointer;
}

.chat-link-actions button:first-child {
  background: var(--wavy-gold);
  border-color: var(--wavy-gold);
  color: var(--wavy-black);
  font-weight: 600;
}

.chat-fee-note {
  font-size: 0.75rem;
  color: var(--wavy-muted);
  margin-top: 6px;
}

@media (max-width: 600px) {
  .chat-page { padding: 0 12px; }
  .chat-shell {
    height: min(72dvh, calc(100dvh - var(--wavy-header-h) - 88px));
    min-height: 320px;
    border-radius: var(--clay-radius-lg, var(--wavy-radius-xl));
  }
  .chat-msg { max-width: 92%; }
  .chat-quick-btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 0.85rem;
  }
  .chat-input-bar input,
  .chat-form-inline input,
  .chat-form-inline select {
    font-size: 16px; /* prevent iOS zoom on focus */
  }
  .chat-form-inline button {
    min-height: 44px;
  }
}

/* Floating chat widget (homepage) */
.wavy-float-chat {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  right: max(24px, env(safe-area-inset-right, 0px));
  z-index: 500;
  font-family: var(--wavy-font);
}

.wavy-float-chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 499;
  background: rgba(45, 38, 64, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.wavy-float-chat-backdrop.is-visible {
  display: block;
  opacity: 1;
}

.wavy-float-chat-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border: 1px solid var(--wavy-border-gold);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--wavy-purple-dark), var(--wavy-purple));
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--wavy-shadow-purple), 0 8px 32px rgba(0, 0, 0, 0.45);
  transition: transform 0.2s, box-shadow 0.2s;
}

.wavy-float-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: var(--wavy-shadow-gold), 0 12px 40px rgba(0, 0, 0, 0.5);
}

.wavy-float-chat-toggle.is-open {
  display: none;
}

.wavy-float-chat-icon { font-size: 1.2rem; }

.wavy-float-chat-panel {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  right: max(24px, env(safe-area-inset-right, 0px));
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100dvh - 120px));
  max-height: calc(100dvh - 120px);
  display: none;
  flex-direction: column;
  background: var(--wavy-surface);
  border: 1px solid var(--wavy-border);
  border-radius: var(--wavy-radius-xl);
  box-shadow: var(--wavy-shadow-purple), 0 24px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  z-index: 501;
}

.wavy-float-chat-panel.is-visible,
.wavy-float-chat-panel:not([hidden]) {
  display: flex;
  animation: chatIn 0.25s var(--wavy-ease);
}

.wavy-float-chat-panel[hidden] {
  display: none !important;
}

.wavy-float-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.3), rgba(212, 175, 55, 0.1));
  border-bottom: 1px solid var(--wavy-border);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.wavy-float-chat-head strong {
  display: block;
  font-size: 0.9rem;
}

.wavy-float-chat-head span {
  font-size: 0.72rem;
  color: var(--wavy-muted);
}

.wavy-float-chat-close {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--wavy-text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  z-index: 3;
  -webkit-tap-highlight-color: transparent;
}

.wavy-float-chat-close:hover {
  background: rgba(255, 255, 255, 0.16);
}

.wavy-float-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.wavy-float-chat-messages .chat-msg {
  max-width: 90%;
}

.wavy-float-chat-messages .chat-bubble {
  font-size: 0.9rem;
  line-height: 1.55;
}

.wavy-float-chat-quick {
  padding: 0 12px 8px;
  flex-shrink: 0;
}

.wavy-float-chat-quick .chat-quick-btn {
  min-height: 40px;
}

.wavy-float-chat-form {
  padding: 0 12px 8px;
}

.wavy-float-chat-inputbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--wavy-border-subtle);
  background: var(--wavy-surface2);
  flex-shrink: 0;
}

.wavy-float-chat-inputbar input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 999px;
  border: 1px solid var(--wavy-border);
  background: var(--wavy-surface);
  color: var(--wavy-text);
  outline: none;
  -webkit-appearance: none;
}

.wavy-float-chat-inputbar .chat-send {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.wavy-float-chat-expand {
  display: block;
  text-align: center;
  padding: 8px;
  font-size: 0.72rem;
  color: var(--wavy-gold);
  text-decoration: none;
  border-top: 1px solid var(--wavy-border-subtle);
}

.wavy-float-chat-expand:hover { text-decoration: underline; }

/* Tablet — slightly larger panel */
@media (max-width: 768px) {
  .wavy-float-chat-panel {
    width: min(400px, calc(100vw - 24px));
    height: min(560px, calc(100dvh - 100px));
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
}

/* Mobile — full-screen chat drawer */
@media (max-width: 480px) {
  .wavy-float-chat {
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    right: max(16px, env(safe-area-inset-right, 0px));
  }

  .wavy-float-chat-label { display: none; }

  .wavy-float-chat-toggle {
    padding: 16px;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    justify-content: center;
    box-shadow: var(--wavy-shadow-purple), 0 6px 24px rgba(91, 33, 182, 0.25);
  }

  .wavy-float-chat-toggle.is-open {
    display: none;
  }

  .wavy-float-chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .wavy-float-chat-panel.is-visible,
  .wavy-float-chat-panel:not([hidden]) {
    animation: chatSlideUp 0.3s var(--wavy-ease);
  }

  @keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }

  .wavy-float-chat-head {
    padding: 14px 16px;
    padding-top: max(14px, env(safe-area-inset-top, 0px));
    min-height: 56px;
  }

  .wavy-float-chat-head strong { font-size: 1rem; }

  .wavy-float-chat-messages {
    padding: 16px 14px;
    gap: 12px;
  }

  .wavy-float-chat-messages .chat-msg {
    max-width: 88%;
  }

  .wavy-float-chat-quick {
    padding: 0 14px 10px;
  }

  .wavy-float-chat-quick .chat-quick-btn {
    min-height: 44px;
    font-size: 0.85rem;
    padding: 10px 16px;
  }

  .wavy-float-chat-form {
    padding: 0 14px 10px;
  }

  .wavy-float-chat-form input,
  .wavy-float-chat-form select {
    font-size: 16px;
    min-height: 44px;
  }

  .wavy-float-chat-inputbar {
    padding: 12px 14px max(12px, env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .wavy-float-chat-expand {
    padding: 12px;
    font-size: 0.8rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  body.wavy-float-chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }
}
