/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --primary:      #E8671B;
  --primary-dk:   #C4501A;
  --bg:           #F2F2F6;
  --white:        #FFFFFF;
  --text:         #1C1C1E;
  --text-soft:    #6E6E73;
  --border:       #E0E0E5;
  --shadow:       0 1px 4px rgba(0,0,0,0.10);
  --radius:       18px;
  --radius-sm:    8px;
  --ease:         0.18s ease;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ── App shell ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;           /* dynamic viewport — avoids mobile browser chrome */
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--primary);
  color: var(--white);
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  z-index: 10;
}

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

.app-icon {
  font-size: 26px;
  flex-shrink: 0;
  line-height: 1;
}

.header-info { min-width: 0; }
.header-info h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
}
#status-text {
  font-size: 11px;
  opacity: 0.82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  display: block;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#lang-select {
  background: rgba(255,255,255,0.18);
  border: 1.5px solid rgba(255,255,255,0.35);
  color: white;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  min-width: 48px;
}
#lang-select option { background: #333; color: white; }

.header-btn {
  background: rgba(255,255,255,0.18);
  border: 1.5px solid rgba(255,255,255,0.35);
  color: white;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ease);
  flex-shrink: 0;
}
.header-btn:hover   { background: rgba(255,255,255,0.28); }
.header-btn:active  { background: rgba(255,255,255,0.38); }
.header-btn.active  { background: rgba(255,255,255,0.30); box-shadow: 0 0 0 2px rgba(255,255,255,0.55); }

/* ── Messages ────────────────────────────────────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* hide scrollbar on mobile */
#messages::-webkit-scrollbar { width: 0; }

.msg {
  display: flex;
  max-width: 82%;
  animation: pop-in 0.22s ease;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.msg.no-anim { animation: none; }

.msg--user      { align-self: flex-end; }
.msg--assistant { align-self: flex-start; }
.msg--error     { align-self: center; max-width: 90%; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}

.msg--user .bubble {
  background: var(--primary);
  color: var(--white);
  border-bottom-right-radius: 4px;
}
.msg--user .bubble strong { color: var(--white); }

.msg--assistant .bubble {
  background: var(--white);
  color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

.msg--error .bubble {
  background: #FFF3CD;
  color: #7D5A00;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.bubble p         { margin-bottom: 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong    { font-weight: 700; }
.bubble em        { font-style: italic; }

.chat-img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 12px;
  object-fit: cover;
}

/* Typing indicator */
.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
}
.typing span {
  width: 7px;
  height: 7px;
  background: #B0B0B8;
  border-radius: 50%;
  animation: bounce 1.1s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0);  }
  30%           { transform: translateY(-7px); }
}

/* ── Input area ──────────────────────────────────────────────────────────────── */
#input-area {
  flex-shrink: 0;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ease), transform var(--ease);
}
.icon-btn:active { transform: scale(0.88); }
.icon-btn.active { background: rgba(232,103,27,0.15); }

.input-wrap {
  flex: 1;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 9px 14px;
  transition: border-color var(--ease);
  display: flex;
  align-items: flex-end;
}
.input-wrap:focus-within { border-color: var(--primary); }

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  min-height: 22px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.45;
}
#message-input::placeholder { color: var(--text-soft); }

.send-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ease), transform var(--ease), opacity var(--ease);
}
.send-btn:active   { transform: scale(0.88); background: var(--primary-dk); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Location permission modal ───────────────────────────────────────────────── */
.loc-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0 0 env(safe-area-inset-bottom);
  animation: fade-in 0.2s ease;
}
.loc-modal[hidden] { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.loc-modal__card {
  background: var(--white);
  border-radius: 24px 24px 0 0;
  padding: 32px 28px 36px;
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: slide-up 0.28s ease;
}

@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.loc-modal__icon {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 4px;
}

.loc-modal__title {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  letter-spacing: -0.3px;
}

.loc-modal__body {
  font-size: 15px;
  line-height: 1.55;
  text-align: center;
  color: var(--text-soft);
  max-width: 320px;
}

.loc-modal__allow {
  margin-top: 8px;
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--ease), transform var(--ease);
}
.loc-modal__allow:active { background: var(--primary-dk); transform: scale(0.98); }

.loc-modal__skip {
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
}
.loc-modal__skip:active { opacity: 0.6; }

/* ── Scrollbar (desktop) ────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  #messages::-webkit-scrollbar       { width: 4px; }
  #messages::-webkit-scrollbar-track { background: transparent; }
  #messages::-webkit-scrollbar-thumb { background: #CCC; border-radius: 4px; }
}
