* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #efeae2;
}

#phone-frame {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: #efeae2;
  position: relative;
  overflow: hidden;
}

#chat-app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- HEADER ---------- */
#chat-header {
  background: #075e54;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px max(14px, calc((100% - 720px) / 2));
  flex-shrink: 0;
  z-index: 10;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ccc center/cover no-repeat;
  flex-shrink: 0;
}

.header-info { flex: 1; min-width: 0; }
.header-name { font-weight: 600; font-size: 15px; }
.header-status { font-size: 12px; opacity: .8; }

.header-icons { display: flex; gap: 18px; }
.header-icons svg { width: 20px; height: 20px; color: #fff; }

/* ---------- CHAT WINDOW ---------- */
#chat-window {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background-color: #efeae2;
  background-image:
    linear-gradient(rgba(239,234,226,.92), rgba(239,234,226,.92)),
    repeating-linear-gradient(45deg, rgba(0,0,0,.03) 0 2px, transparent 2px 40px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.03) 0 2px, transparent 2px 40px);
  padding: 14px max(10px, calc((100% - 720px) / 2)) 20px;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 100%;
  width: 100%;
}

/* ---------- BUBBLES ---------- */
.bubble-row {
  display: flex;
  width: 100%;
  animation: fadeIn .25s ease;
}
.bubble-row.bot { justify-content: flex-start; }
.bubble-row.user { justify-content: flex-end; }

.bubble {
  max-width: 82%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.4;
  white-space: pre-line;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
}

.bubble.bot { background: #ffffff; color: #111; border-top-left-radius: 2px; }
.bubble.user { background: #d9fdd3; color: #111; border-top-right-radius: 2px; }

.bubble b, .bubble strong { font-weight: 700; }
.bubble em, .bubble i { font-style: italic; }

/* image bubble */
.bubble.image { padding: 4px; max-width: 78%; }
.bubble.image img {
  width: 100%;
  display: block;
  border-radius: 6px;
}
.bubble.image .caption {
  padding: 6px 4px 2px;
  font-size: 13px;
  color: #555;
}
.bubble.image .caption .tag {
  display: inline-block;
  background: rgba(0,0,0,.45);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}

/* typing indicator */
.bubble.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}
.bubble.typing span {
  width: 6px; height: 6px;
  background: #999;
  border-radius: 50%;
  display: inline-block;
  animation: blink 1.2s infinite ease-in-out;
}
.bubble.typing span:nth-child(2) { animation-delay: .2s; }
.bubble.typing span:nth-child(3) { animation-delay: .4s; }

/* ---------- BUTTONS ---------- */
.btn-row {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}
.chat-btn {
  background: #075e54;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .3px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  transition: filter .15s;
}
.chat-btn:hover { filter: brightness(0.92); }
.chat-btn:active { filter: brightness(0.8); }

.chat-btn.whatsapp-cta {
  background: #25d366;
  font-size: 15px;
  padding: 13px 24px;
}

/* ---------- INPUT STEP ---------- */
.input-row {
  display: flex;
  justify-content: flex-start;
  padding: 4px 0;
}
.input-bubble {
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  width: 82%;
}
.input-bubble input {
  flex: 1;
  border: none;
  border-bottom: 1px solid #ccc;
  padding: 8px 4px;
  font-size: 14px;
  outline: none;
  min-width: 0;
}
.input-bubble input:focus { border-bottom-color: #075e54; }
.input-bubble input.input-invalid {
  border-bottom-color: #e04848;
  animation: shake .3s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.input-bubble button {
  background: #075e54;
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------- ANIMATIONS ---------- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes blink {
  0%, 80%, 100% { opacity: .3; transform: scale(.85); }
  40% { opacity: 1; transform: scale(1); }
}

/* redirect overlay */
#redirect-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7,94,84,.97);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  padding: 30px;
  z-index: 999;
}
#redirect-overlay.show { display: flex; }
#redirect-overlay .spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
