/* ============================================
   Ninh Bình travel chatbot — webview UI
   Palette: #4CAF50 (mạ non)
   ============================================ */

:root {
  --primary:        #4CAF50;
  --primary-dark:   #388E3C;
  --primary-light:  #C8E6C9;
  --primary-bg:     #F1F8E9;
  --text:           #1B2D1F;
  --text-muted:     #6B7C70;
  --border:         #E0E5E1;
  --user-bg:        #4CAF50;
  --user-text:      #FFFFFF;
  --assistant-bg:   #FFFFFF;
  --bg:             #FAFCF9;
  --shadow:         0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --radius-lg:      18px;
  --radius-md:      12px;
  --radius-sm:      8px;
  --safe-bottom:    env(safe-area-inset-bottom, 0px);
  --safe-top:       env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ============================================
   LAYOUT
   ============================================ */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

/* ============================================
   HEADER
   ============================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 10;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.18);
  border-radius: 12px;
  font-size: 22px;
  flex-shrink: 0;
}
.title-block { min-width: 0; }
.header h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtitle {
  font-size: 12px;
  margin: 2px 0 0 0;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(255,255,255,0.12);
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-icon:hover { background: rgba(255,255,255,0.22); }
.btn-icon:active { background: rgba(255,255,255,0.30); }

/* ============================================
   MESSAGES
   ============================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Welcome */
.welcome {
  text-align: center;
  padding: 24px 8px 0;
  max-width: 520px;
  margin: 0 auto;
}
.welcome-icon {
  font-size: 48px;
  margin-bottom: 8px;
}
.welcome h2 {
  font-size: 22px;
  margin: 0 0 8px 0;
  color: var(--primary-dark);
}
.welcome p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.55;
  margin: 0 0 20px 0;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.chip {
  padding: 10px 14px;
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  transition: all 0.15s;
  text-align: left;
}
.chip:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
  transform: translateY(-1px);
}
.chip:active { transform: translateY(0); }

/* Message bubble */
.msg {
  display: flex;
  margin-bottom: 12px;
  animation: fadeIn 0.2s ease;
}
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: var(--shadow);
}
.msg.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: var(--assistant-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Markdown trong assistant message */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { color: var(--primary-dark); font-weight: 600; }
.bubble ol, .bubble ul { padding-left: 22px; margin: 6px 0; }
.bubble li { margin-bottom: 4px; }
.bubble h3 {
  font-size: 15px;
  margin: 10px 0 6px;
  color: var(--primary-dark);
  font-weight: 600;
}
.bubble em { color: var(--text-muted); }

/* Place cards grid (sources với ảnh) */
.place-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.place-card {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}
.place-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(76,175,80,0.15);
  border-color: var(--primary-light);
}
.place-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--primary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.place-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.place-thumb--icon {
  font-size: 32px;
  color: var(--primary);
}
.place-body {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.place-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
.place-meta {
  font-size: 11.5px;
  color: var(--primary-dark);
  font-weight: 500;
}
.place-addr {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
}
.place-rating {
  font-size: 11.5px;
  color: #B8860B;
  margin-top: 2px;
}

@media (max-width: 480px) {
  .place-grid { grid-template-columns: 1fr; }
  .place-thumb { aspect-ratio: 16 / 9; }
}

/* Typing dots */
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Error state */
.error-toast {
  background: #FFE5E5;
  color: #B00020;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin: 8px 0;
}

/* ============================================
   COMPOSER
   ============================================ */
.composer {
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
}
.composer-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 6px 6px 6px 14px;
  transition: border-color 0.15s;
}
.composer-form:focus-within {
  border-color: var(--primary);
}
.input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  resize: none;
  padding: 6px 0;
  line-height: 1.4;
  max-height: 120px;
}
.input::placeholder { color: var(--text-muted); }
.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--primary-dark); }
.btn-send:active:not(:disabled) { transform: scale(0.92); }
.btn-send:disabled {
  background: var(--border);
  cursor: not-allowed;
}
.btn-send svg { transform: translateX(1px); }

.composer-foot {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
  .header h1 { font-size: 15px; }
  .subtitle { font-size: 11px; }
  .messages { padding: 12px; }
  .bubble { max-width: 92%; font-size: 14px; }
  .welcome h2 { font-size: 19px; }
  .chip { font-size: 12.5px; padding: 9px 12px; }
}

/* Scrollbar */
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12);
  border-radius: 3px;
}
.messages::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.22); }
