/* ============================================================
   CSS Variables & Reset
   ============================================================ */
:root {
  --accent: #D4577A;
  --accent-dark: #b8445f;
  --accent-light: #fdf2f5;
  --bg: #fef9f7;
  --surface: #ffffff;
  --border: #f0e4e0;
  --text-primary: #2d1f1f;
  --text-secondary: #8b6f6f;
  --bot-bubble: #ffffff;
  --user-bubble: #D4577A;
  --user-text: #ffffff;
  --shadow: 0 4px 24px rgba(180, 68, 95, 0.10);
  --radius: 16px;
  --radius-sm: 8px;
}

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

html {
  height: 100%;
}

body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-primary);
}

/* ============================================================
   Chat Container
   ============================================================ */
.chat-wrapper {
  width: 100%;
  max-width: 420px;
  height: 100%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============================================================
   Header
   ============================================================ */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 40px;
  height: 40px;
  background: var(--accent-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
}

.reset-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.reset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* ============================================================
   Messages Area
   ============================================================ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

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

/* ============================================================
   Message Bubbles
   ============================================================ */
.message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 3px;
  animation: messageIn 0.2s ease-out;
}

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

.bot-message {
  align-self: flex-start;
}

.user-message {
  align-self: flex-end;
  align-items: flex-end;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.bot-message .message-bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

.user-message .message-bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.message-bubble p + p {
  margin-top: 5px;
}

.secondary-text {
  color: var(--text-secondary);
  font-size: 13px;
}

.message-time {
  font-size: 10px;
  color: var(--text-secondary);
  padding: 0 4px;
}

/* Typing indicator */
.typing-indicator .message-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Error message */
.error-message .message-bubble {
  background: #fff5f5;
  border-color: #fed7d7;
  color: #c53030;
}

/* ============================================================
   Input Area
   ============================================================ */
.chat-input-area {
  padding: 10px 16px;
  padding-bottom: env(safe-area-inset-bottom, 10px);
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 6px 6px 6px 14px;
  transition: border-color 0.2s;
}

.input-row:focus-within {
  border-color: var(--accent);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px;
  color: var(--text-primary);
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  font-family: inherit;
  padding: 5px 0;
}

.chat-input::placeholder {
  color: var(--text-secondary);
}

.send-btn {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.send-btn:hover {
  background: var(--accent-dark);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  font-size: 10px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 6px;
}

/* ============================================================
   Desktop — centered phone frame
   ============================================================ */
@media (min-width: 480px) {
  body {
    padding: 20px;
    background: linear-gradient(135deg, #fef9f7 0%, #f8e8ec 100%);
  }

  .chat-wrapper {
    max-width: 390px;
    height: 90vh;
    max-height: 844px;
    border-radius: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 8px 40px rgba(180, 68, 95, 0.12);
  }

  .chat-header {
    border-radius: 24px 24px 0 0;
  }
}
