/* ═══════════════════════════════════════════════════════════════
   Alex — Chatbot pedido.miami
   Aesthetic: Clean light theme, magenta accent
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700&family=DM+Sans:wght@300;400;500&display=swap');

/* ── Variables ──────────────────────────────────────────────── */
:root {
  --bg:          #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #f8f9fa;
  --surface-3:   #eef0f3;
  --border:      rgba(0,0,0,0.08);
  --border-2:    rgba(0,0,0,0.13);

  --accent:      #c2185b;
  --accent-dim:  rgba(194,24,91,0.08);
  --accent-glow: rgba(194,24,91,0.18);

  --txt:         #1a1d26;
  --txt-2:       #5f6577;
  --txt-3:       #9ba1b0;

  --user-bg:     #fce4ec;
  --user-border: rgba(194,24,91,0.25);

  --alex-bg:     #f0f1f4;
  --alex-border: rgba(0,0,0,0.06);

  --error:       #dc3545;
  --error-bg:    rgba(220,53,69,0.08);
  --success:     #c2185b;

  --radius:      14px;
  --radius-sm:   8px;
  --font-ui:     'Syne', sans-serif;
  --font-body:   'DM Sans', sans-serif;
  --shadow:      0 8px 32px rgba(0,0,0,0.1);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Layout ─────────────────────────────────────────────────── */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  position: relative;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────── */
.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #1a1d26;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  position: relative;
  z-index: 10;
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, #e91e63, #ad1457);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.header-name {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}
.header-sep {
  font-size: 12px;
  color: rgba(255,255,255,0.3);
}
.header-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  font-weight: 400;
  letter-spacing: 0.3px;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34,197,94,0.4);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(0.85); }
}

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

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 2px;
}

/* ── Date separator ─────────────────────────────────────────── */
.date-sep {
  text-align: center;
  font-size: 10px;
  color: var(--txt-3);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 8px 0;
  display: flex; align-items: center; gap: 10px;
}
.date-sep::before, .date-sep::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ── Message rows ───────────────────────────────────────────── */
.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: msg-in 0.25s ease-out forwards;
  opacity: 0;
  transform: translateY(8px);
}

@keyframes msg-in {
  to { opacity: 1; transform: translateY(0); }
}

.msg-row.user { flex-direction: row-reverse; }
.msg-row.user > div { max-width: 78%; }
.msg-row.alex > div:last-child { max-width: 78%; }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #e91e63, #ad1457);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.msg-bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.65;
  word-break: break-word;
  position: relative;
}

/* Alex bubble */
.msg-row.alex .msg-bubble {
  background: var(--alex-bg);
  border: 1px solid var(--alex-border);
  border-bottom-left-radius: 4px;
  color: var(--txt);
}

/* User bubble */
.msg-row.user .msg-bubble {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-bottom-right-radius: 4px;
  color: var(--txt);
}

.msg-bubble p { margin: 0; }
.msg-bubble p + p { margin-top: 8px; }
.msg-bubble ul, .msg-bubble ol {
  padding-left: 18px;
  margin: 6px 0;
}
.msg-bubble li { margin: 3px 0; }
.msg-bubble strong { color: var(--accent); font-weight: 500; }
.msg-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.msg-time {
  font-size: 10px;
  color: var(--txt-3);
  margin-top: 4px;
  text-align: right;
  padding: 0 2px;
}
.msg-row.alex .msg-time { text-align: left; }

/* ── Quick replies (welcome state) ─────────────────────────── */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.quick-btn {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--txt-2);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}
.quick-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Handoff card (talk-to-human escalation) ──────────────── */
.handoff-card {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.handoff-btn {
  flex: 1 1 calc(50% - 4px);
  min-width: 140px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--txt);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.18s ease;
}
.handoff-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.handoff-whatsapp {
  background: #25d366;
  border-color: #1ebe5b;
  color: #fff;
}
.handoff-whatsapp:hover {
  background: #1ebe5b;
  box-shadow: 0 4px 14px rgba(37,211,102,0.35);
}

.handoff-form {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.handoff-form:hover {
  background: #e91e63;
  box-shadow: 0 4px 14px var(--accent-glow);
}

/* ── Typing indicator ───────────────────────────────────────── */
.typing-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: msg-in 0.2s ease-out forwards;
  opacity: 0;
  transform: translateY(8px);
}
.typing-bubble {
  background: var(--alex-bg);
  border: 1px solid var(--alex-border);
  border-bottom-left-radius: 4px;
  padding: 13px 16px;
  border-radius: var(--radius);
  display: flex;
  gap: 5px;
  align-items: center;
}
.typing-bubble span {
  width: 7px; height: 7px;
  background: var(--txt-3);
  border-radius: 50%;
  display: block;
  animation: bounce 1.2s ease-in-out infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.3s;  }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.5; }
  30%            { transform: translateY(-6px); opacity: 1;   }
}

/* ── Streaming cursor ───────────────────────────────────────── */
.cursor {
  display: inline-block;
  width: 2px; height: 14px;
  background: var(--accent);
  margin-left: 2px;
  border-radius: 1px;
  vertical-align: middle;
  animation: blink 0.8s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ── Input area ─────────────────────────────────────────────── */
.chat-input-wrap {
  flex-shrink: 0;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  padding: 12px 16px 10px;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px 8px 14px;
  transition: border-color 0.2s;
}
.input-row:focus-within {
  border-color: rgba(0,212,160,0.4);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#msg-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--txt);
  font-family: var(--font-body);
  font-size: 16px;
  resize: none;
  max-height: 100px;
  line-height: 1.55;
  padding: 2px 0;
}
#msg-input::placeholder { color: var(--txt-3); }

.send-btn {
  width: 34px; height: 34px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.18s ease;
  color: #fff;
}
.send-btn:hover:not(:disabled) {
  background: #e91e63;
  transform: scale(1.05);
  box-shadow: 0 4px 14px var(--accent-glow);
}
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; }

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding: 0 2px;
}
.char-count { font-size: 10px; color: var(--txt-3); }
.char-count.warn { color: #f0a020; }
.char-count.error { color: var(--error); }

/* ── Action bar ─────────────────────────────────────────────── */
.action-bar {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 8px 16px 14px;
  background: var(--surface-2);
}

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--txt-2);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
  letter-spacing: 0.2px;
}
.action-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-2);
  color: var(--txt);
}
.action-btn.primary {
  border-color: rgba(0,212,160,0.3);
  color: var(--accent);
}
.action-btn.primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.action-btn svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── Modal overlay ──────────────────────────────────────────── */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  width: 100%;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 0 0 20px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  max-height: 92dvh;
  overflow-y: auto;
}
.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 36px; height: 4px;
  background: var(--border-2);
  border-radius: 2px;
  margin: 14px auto 18px;
}

.modal-header {
  padding: 0 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 700;
  color: var(--txt);
}
.modal-close {
  width: 32px; height: 32px;
  border: none;
  background: var(--surface-3);
  border-radius: 8px;
  cursor: pointer;
  color: var(--txt-2);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--border-2); color: var(--txt); }
.modal-close svg { width: 16px; height: 16px; }

/* ── Form ───────────────────────────────────────────────────── */
.contact-form {
  padding: 20px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--txt-2);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.field-required { color: var(--accent); margin-left: 2px; }

.field-input, .field-textarea {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  color: var(--txt);
  font-family: var(--font-body);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}
.field-input:focus, .field-textarea:focus {
  border-color: rgba(0,212,160,0.4);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.field-input.invalid, .field-textarea.invalid {
  border-color: var(--error);
}
.field-input::placeholder, .field-textarea::placeholder { color: var(--txt-3); }
.field-textarea { resize: none; height: 90px; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-error {
  font-size: 11px;
  color: var(--error);
  margin-top: 2px;
  min-height: 14px;
}
.form-global-error {
  background: var(--error-bg);
  border: 1px solid rgba(255,92,92,0.2);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 12.5px;
  color: var(--error);
  display: none;
}
.form-global-error.show { display: block; }

/* ── Turnstile wrapper ──────────────────────────────────────── */
.turnstile-wrap {
  display: flex;
  align-items: center;
  min-height: 65px;
}

/* ── Submit button ──────────────────────────────────────────── */
.submit-btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: all 0.2s ease;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 4px;
}
.submit-btn:hover:not(:disabled) {
  background: #e91e63;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
.submit-btn.loading .spinner { display: block; }
.submit-btn.loading .btn-text { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Success state ──────────────────────────────────────────── */
.success-panel {
  padding: 40px 20px;
  text-align: center;
  display: none;
}
.success-panel.show { display: block; }
.success-icon {
  width: 56px; height: 56px;
  background: rgba(0,212,160,0.1);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  color: var(--accent);
}
.success-icon svg { width: 28px; height: 28px; }
.success-title {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 700;
  color: var(--txt);
  margin-bottom: 8px;
}
.success-sub { font-size: 13px; color: var(--txt-2); }

.close-success-btn {
  margin-top: 20px;
  padding: 10px 24px;
  border: 1px solid var(--border-2);
  background: transparent;
  border-radius: 10px;
  color: var(--txt-2);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.18s;
}
.close-success-btn:hover { background: var(--surface-3); color: var(--txt); }

/* ── Error toast ────────────────────────────────────────────── */
.toast {
  position: absolute;
  top: 70px; left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 12.5px;
  color: var(--txt);
  z-index: 200;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  max-width: 90%;
  white-space: normal;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: rgba(255,92,92,0.3); color: var(--error); }
.toast.success { border-color: rgba(0,212,160,0.3); color: var(--accent); }

/* ── Embed mode (loaded inside iframe via ?mode=embed) ─────── */
body.embed-mode .chat-shell {
  max-width: 100%;
  height: 100dvh;
  border-radius: 0;
}
body.embed-mode .avatar,
body.embed-mode .header-name,
body.embed-mode .header-sep { display: none; }
body.embed-mode .header-sub { font-size: 13px; }

/* ── Mobile tweaks ──────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-messages { padding: 14px 12px; }
  .msg-row.user > div, .msg-row.alex > div:last-child { max-width: 88%; }
  .row-2 { grid-template-columns: 1fr; }
}
