/* ============================================================
   AI CHAT MODAL
   Deliberate exception to the single-stylesheet convention — this
   feature is large (5 step layouts, message bubbles, a card form, a
   recording-state mic button) and fully self-contained beyond the same
   theme-root.css custom properties style.css already consumes.
   ============================================================ */

.chat-modal .modal-dialog { max-width: 620px; }
.chat-modal .modal-content {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border: 1px solid var(--line);
  border-radius: 6px;
  position: relative;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-modal .modal-content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.chat-modal .modal-body {
  padding: clamp(1.75rem, 4vw, 2.75rem);
}

.chat-agent-head {
  display: flex;
  align-items: center;
  gap: .85rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line-soft);
}
.chat-identity-note {
  margin: -1rem 0 1.25rem;
  color: var(--muted);
  font-size: .8rem;
  text-align: center;
}
.chat-agent-photo {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: var(--bg-2);
  border: 1.5px solid var(--gold);
  box-shadow: 0 4px 14px -6px rgba(217,164,65,.55);
}
.chat-agent-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-agent-name {
  font-family: var(--f-serif);
  font-size: 1.2rem;
  color: var(--heading);
  letter-spacing: .01em;
}

/* Steps — only the one matching the modal body's data-step shows */
.chat-step { display: none; }
.modal-body[data-step="identity"] .chat-step[data-step-panel="identity"] { display: block; }
.modal-body[data-step="otp"] .chat-step[data-step-panel="otp"] { display: block; }
.modal-body[data-step="paywall"] .chat-step[data-step-panel="paywall"] { display: block; }
.modal-body[data-step="ready"] .chat-step[data-step-panel="ready"] { display: block; }
.modal-body[data-step="chat"] .chat-step[data-step-panel="chat"] { display: flex; }
.modal-body[data-step="error"] .chat-step[data-step-panel="error"] { display: block; }
.modal-body[data-step="loading"] .chat-step[data-step-panel="loading"] { display: block; }

/* Text and voice are separate, mutually-exclusive chat UIs (chat.js sets
   [data-chat-mode] once, when the session starts) — never both at once. */
#chatVoiceRow { display: none; }
.modal-body[data-chat-mode="voice"] #chatSendForm { display: none; }
.modal-body[data-chat-mode="voice"] #chatVoiceRow { display: flex; }

/* Spinner — used both for the full-step loader (while /chat/status
   resolves on open) and inside buttons while their own request is in
   flight. Pure CSS, no image asset. */
.chat-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(217,164,65,.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: chatSpin .7s linear infinite;
  vertical-align: -4px;
}
.chat-spinner-lg { width: 38px; height: 38px; border-width: 3px; }
@keyframes chatSpin { to { transform: rotate(360deg); } }

.chat-loading-panel { padding: 3.5rem 0; }

.chat-btn-spinner { display: none; }
.chat-btn-spinner::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(12,11,15,.25);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: chatSpin .7s linear infinite;
  vertical-align: -3px;
}
.btn-loading .chat-btn-label { visibility: hidden; }
.btn-loading .chat-btn-spinner {
  display: block;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.btn-loading { position: relative; }
.btn-outline-gold.btn-loading .chat-btn-spinner::before { border-color: rgba(217,164,65,.3); border-top-color: var(--gold-2); }

.chat-form { max-width: 420px; margin: 0 auto; }
.chat-form-wide { max-width: 100%; }
.chat-form-divider {
  font-family: var(--f-sans);
  font-size: .78rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold-2);
  border-top: 1px solid var(--line-soft);
  margin: 1.5rem 0 1rem;
  padding-top: 1.25rem;
}
.chat-step-note { color: var(--muted); font-size: .9rem; margin-bottom: 1.25rem; }
.chat-step-error {
  color: #e2836f;
  font-size: .85rem;
  min-height: 1.2em;
  margin: .5rem 0 0;
  text-align: center;
}
.chat-step-links {
  display: flex;
  justify-content: space-between;
  margin-top: 1rem;
  font-size: .85rem;
}
.chat-empty-label {
  margin: auto;
  color: var(--muted);
  font-style: italic;
  font-size: .85rem;
  text-align: center;
  padding: 2rem 0;
}
.chat-messages-loading {
  margin: auto;
  padding: 2rem 0;
}
.chat-step-links a { color: var(--muted); }
.chat-step-links a:hover { color: var(--gold-2); }
.chat-otp-input {
  text-align: center;
  font-size: 1.6rem;
  letter-spacing: .5rem;
  font-family: var(--f-sans);
}

/* Saved payment methods — paywall step */
.chat-saved-cards { max-width: 420px; margin: 0 auto 1rem; }
.chat-saved-cards-list { display: flex; flex-direction: column; gap: .5rem; }
.chat-saved-card-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem .8rem;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.chat-saved-card-row:has(input:checked) {
  border-color: var(--gold);
  background: rgba(217, 164, 65, .08);
}
.chat-saved-card-row input { accent-color: var(--gold); }
.chat-saved-card-brand { text-transform: capitalize; font-weight: 600; color: var(--heading); }
.chat-saved-card-last4 { color: var(--muted); letter-spacing: .04em; }
.chat-saved-card-expiry { margin-left: auto; color: var(--muted); font-size: .85rem; }
.chat-use-new-card-link {
  display: inline-block;
  margin-top: .6rem;
  color: var(--muted);
  font-size: .85rem;
}
.chat-use-new-card-link:hover { color: var(--gold-2); }

/* Live chat panel */
.chat-step-live {
  flex-direction: column;
  max-height: 65vh;
  position: relative;
}
.chat-credits-indicator {
  flex: 0 0 auto;
  text-align: center;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--gold-2);
  background: rgba(217, 164, 65, .08);
  border: 1px solid rgba(217, 164, 65, .2);
  border-radius: 999px;
  padding: .3rem .8rem;
  margin: 0 auto .65rem;
  width: fit-content;
}
.chat-credits-indicator:empty { display: none; }
.chat-gate-banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .7rem .9rem;
  margin: 0 0 .75rem;
  border: 1px solid rgba(217, 164, 65, .35);
  border-radius: 8px;
  background: rgba(217, 164, 65, .08);
}
.chat-gate-banner-text {
  margin: 0;
  color: var(--text);
  font-size: .88rem;
  flex: 1 1 200px;
}
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: .25rem .9rem 1rem .25rem;
  margin-right: -.65rem;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  min-height: 240px;
  /* Soften the hard top edge when scrolled — a small premium touch. */
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 18px, #000 calc(100% - 10px), transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 18px, #000 calc(100% - 10px), transparent 100%);
}
/* Custom scrollbar — thin, gold, matches the site's theme instead of the
   browser's default light-theme chrome. */
.chat-messages { scrollbar-width: thin; scrollbar-color: var(--gold) transparent; }
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--gold-hi), var(--gold));
  border-radius: 10px;
}
.chat-messages::-webkit-scrollbar-thumb:hover { background: var(--gold-2); }

.chat-bubble {
  max-width: 78%;
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  line-height: 1.55;
  word-wrap: break-word;
  box-shadow: 0 4px 14px -10px rgba(0,0,0,.5);
}
.chat-bubble-user {
  align-self: flex-end;
  background: linear-gradient(165deg, var(--gold-hi), var(--gold));
  color: var(--ink);
  border-bottom-right-radius: 3px;
}
.chat-bubble-agent {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  color: var(--text);
  border-bottom-left-radius: 3px;
}
.chat-bubble-time {
  display: block;
  font-size: .68rem;
  opacity: .6;
  margin-top: .3rem;
  letter-spacing: .02em;
}
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: .3rem;
  padding: .65rem .95rem;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chatTypingBounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-send-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  border-top: 1px solid var(--line-soft);
  padding-top: .85rem;
}
.chat-send-row .form-control { flex: 1 1 auto; }
.chat-send-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.chat-mic-btn {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.chat-mic-btn:hover { color: var(--gold-2); border-color: var(--gold); }
.chat-mic-btn.recording {
  color: #fff;
  background: #d1495b;
  border-color: #d1495b;
  /* Steady heartbeat — always present while recording, independent of
     actual volume, so "it's recording" is never in doubt even in silence. */
  animation: chatMicPulse 1.1s infinite ease-in-out;
}
@keyframes chatMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(209, 73, 91, .5); }
  50% { box-shadow: 0 0 0 8px rgba(209, 73, 91, 0); }
}
/* Reactive ring — grows/fades with live mic volume (chat.js writes
   --mic-level every animation frame via the Web Audio analyser). Layered
   on top of the steady heartbeat pulse above, not a replacement for it. */
.chat-mic-btn.recording::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(209, 73, 91, .75);
  transform: scale(calc(1 + var(--mic-level, 0) * 0.55));
  opacity: calc(.3 + var(--mic-level, 0) * .6);
  transition: transform .08s ease-out, opacity .08s ease-out;
  pointer-events: none;
}

/* Voice-mode row — the mic is the entire input surface here (no text
   field alongside it), so it gets a much larger, centered treatment
   instead of the small icon-sized button that sits next to text input. */
.chat-voice-row {
  flex-direction: column;
  align-items: center;
  gap: .85rem;
  border-top: 1px solid var(--line-soft);
  padding-top: 1.5rem;
  text-align: center;
}
.chat-mic-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
}
.chat-voice-row .chat-mic-btn-lg {
  width: 76px;
  height: 76px;
  font-size: 1.6rem;
  border-width: 2px;
  border-color: var(--gold);
  color: var(--gold-2);
}
.chat-voice-row .chat-mic-btn-lg:hover { background: rgba(217, 164, 65, .1); }
.chat-mic-cancel-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.chat-mic-cancel-btn:hover { color: #fff; border-color: #d1495b; background: #d1495b; }
.chat-voice-status {
  color: var(--muted);
  font-size: .85rem;
  max-width: 320px;
  margin: 0;
}

/* "Close Chat?" / "End Session?" prompts — layered over the live chat
   panel (not the whole modal) when the modal is dismissed mid-session, so
   the visitor can't lose an active session to a stray Esc/backdrop click. */
.chat-confirm-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(12, 11, 15, .82);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  padding: 1.5rem;
  border-radius: inherit;
  z-index: 5;
}
.chat-confirm-card {
  width: 100%;
  max-width: 300px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 1.5rem 1.25rem;
  box-shadow: var(--shadow);
}
.chat-confirm-title {
  font-family: var(--f-serif);
  color: var(--gold-2);
  font-size: 1.3rem;
  margin-bottom: .6rem;
}
.chat-confirm-text {
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.5;
  margin-bottom: 1.1rem;
}
.chat-confirm-actions { display: flex; gap: .6rem; justify-content: center; }
.chat-confirm-actions .btn { flex: 1 1 0; padding: .55rem 1rem; font-size: .7rem; }

/* WhatsApp-style voice message player — a dedicated chat-only component
   (public/assets/js/chat.js buildVoiceMessage()), not the shared .aplayer
   used elsewhere on the site (main.js window.initAudioPlayer, untouched).
   Waveform + tap-to-seek + 1x/1.5x/2x speed, sized to fit more messages
   in the same visible height than a generic wide progress bar would. */
.chat-bubble:has(.voice-msg) { padding: .6rem .75rem; }
.voice-msg {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 232px;
}
.voice-msg-play {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  background: linear-gradient(155deg, #221f27, var(--ink));
  color: var(--gold-2);
  box-shadow: 0 3px 10px -4px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .06);
  transition: transform .15s ease, box-shadow .15s ease;
}
/* Optical nudge — a play glyph looks off-center in a perfect circle
   unless it's shifted slightly toward the direction it "points". */
.voice-msg-play i.bi-play-fill { margin-left: 2px; }
.voice-msg-play:hover { transform: scale(1.06); }
.voice-msg.playing .voice-msg-play { box-shadow: 0 0 0 3px rgba(217, 164, 65, .25); }

.voice-msg-mid { flex: 1 1 auto; min-width: 0; }
.voice-msg-wave {
  position: relative;
  height: 26px;
  cursor: pointer;
  outline: none;
  border-radius: 4px;
}
.voice-msg-wave-bars {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 2.5px;
}
.voice-msg-bar {
  flex: 1 1 0;
  min-width: 2.5px;
  max-width: 3.5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .24);
  transition: background-color .1s linear;
}
/* Bars are recolored in place as playback crosses them (chat.js
   applyProgress()) — a single row of elements, never a second row
   layered/clipped on top, so there's nothing that can drift out of sync
   with itself. */
.voice-msg-bar.played { background: var(--gold-2); }
.voice-msg-wave:focus-visible { box-shadow: 0 0 0 2px var(--gold); }

/* Elapsed/duration and the speed pill sit inline with the play button and
   waveform (see buildVoiceMessage() in chat.js) — one content row, with
   the calendar timestamp as the only line below it, same as text bubbles. */
.voice-msg-time {
  flex: 0 0 auto;
  font-size: .68rem;
  color: var(--muted);
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.voice-msg-speed {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1;
  padding: .32rem .5rem;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.voice-msg-speed:hover { color: var(--gold-2); border-color: var(--gold); background: rgba(217, 164, 65, .08); }

/* Gold user bubble needs the inverse of the dark-bubble default — ink is
   already the documented "bars, buttons text-on-gold" token elsewhere. */
.chat-bubble-user .voice-msg-play {
  background: linear-gradient(155deg, #1a181d, var(--ink));
  box-shadow: 0 3px 10px -4px rgba(12, 11, 15, .55), inset 0 1px 0 rgba(255, 255, 255, .05);
}
.chat-bubble-user .voice-msg-bar { background: rgba(12, 11, 15, .3); }
.chat-bubble-user .voice-msg-bar.played { background: var(--ink); }
.chat-bubble-user .voice-msg-time { color: rgba(12, 11, 15, .68); }
.chat-bubble-user .voice-msg-speed { border-color: rgba(12, 11, 15, .35); color: rgba(12, 11, 15, .68); }
.chat-bubble-user .voice-msg-speed:hover { color: var(--ink); border-color: var(--ink); background: rgba(12, 11, 15, .08); }

.chat-error-panel { padding: 1.5rem 0; }
.chat-error-icon { font-size: 2.5rem; color: var(--gold); margin-bottom: 1rem; display: block; }
.chat-error-actions { display: flex; gap: .6rem; justify-content: center; margin-top: 1rem; }
.chat-error-actions .btn { flex: 1 1 0; max-width: 200px; }
.chat-error-message { color: var(--text); margin-bottom: 1.25rem; }

@media (max-width: 575px) {
  .chat-agent-head { margin-bottom: 1rem; }
  .chat-messages { min-height: 180px; }
}
