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

:root {
  --cream:        #F5F2EC;
  --cream2:       #EDE9E0;
  --cream3:       #E2DDD3;
  --ink:          #1A1814;
  --ink2:         #3D3A34;
  --ink3:         #6B6760;
  --copper:       #B85C2C;
  --copper-light: #F0E4DA;
  --copper-mid:   #D4784A;
  --copper-dark:  #8A3F1A;
  --border:       #D8D3C8;
  --white:        #FFFFFF;
  --green:        #2D7A4F;
  --green-light:  #E0F0E8;
  --red:          #B23A3A;
  --serif:        'Instrument Serif', Georgia, serif;
  --sans:         'Geist', system-ui, -apple-system, sans-serif;
  --r-sm:         6px;
  --r-md:         10px;
  --r-lg:         14px;
  --r-xl:         20px;
  --shadow-sm:    0 1px 4px rgba(26,24,20,.06);
  --shadow-md:    0 4px 24px rgba(26,24,20,.10);
  --shadow-lg:    0 12px 48px rgba(26,24,20,.15);
  --header-h:     58px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
  --safe-top:     env(safe-area-inset-top, 0px);
}

html { scroll-behavior: smooth; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

button { font-family: inherit; cursor: pointer; }
a { color: var(--copper); text-decoration: none; }
a:hover { color: var(--copper-dark); }

/* ─── App shell ──────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--safe-top);
}

/* ─── Header ─────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: rgba(245,242,236,.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
}
.brand {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.brand span.dot { color: var(--copper); }
.brand-status {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-family: var(--sans);
  font-style: normal;
  font-size: 11px;
  color: var(--ink3);
  letter-spacing: .04em;
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
.status-dot.offline { background: var(--red); animation: none; }
@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .4; transform: scale(.7); }
}
.header-actions { display: flex; gap: .5rem; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink2);
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.icon-btn:hover { background: var(--cream2); border-color: var(--ink3); }

/* ─── Hero ───────────────────────────────────────── */
.hero {
  padding: 2.5rem 1.5rem 1.25rem;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  text-align: center;
  transition: opacity .35s ease, transform .35s ease, max-height .45s ease, padding .35s ease;
}
.hero.collapsed {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
}
.hero-overline {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--copper);
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
}
.hero-overline .pulse-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--copper);
  animation: pulse 2s infinite;
}
.hero h1 {
  font-family: var(--serif);
  font-size: 2.25rem;
  line-height: 1.1;
  letter-spacing: -.02em;
  margin-bottom: .75rem;
}
.hero h1 em { font-style: italic; color: var(--copper); }
.hero p {
  font-size: 14px;
  color: var(--ink3);
  font-weight: 300;
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.65;
}

/* ─── Chat stream ────────────────────────────────── */
.chat {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem 8.5rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}

.msg-row {
  display: flex;
  gap: .55rem;
  align-items: flex-end;
  animation: bubbleIn .25s ease both;
}
.msg-row.user { flex-direction: row-reverse; }
.msg-row.with-cards { flex-direction: column; align-items: stretch; }

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: #fff;
  background: var(--copper);
  box-shadow: 0 1px 3px rgba(26,24,20,.15);
}
.msg-row.user .avatar {
  background: var(--cream3);
  color: var(--ink2);
  border: 1px solid var(--border);
}

.bubble {
  padding: .65rem .9rem;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.5;
  max-width: 78%;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble.bot {
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--ink2);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}
.bubble.user {
  background: var(--ink);
  color: var(--cream);
  border-bottom-right-radius: 4px;
}
.bubble.user a { color: var(--copper-mid); }
.bubble.error { background: #fbf3ef; border-color: #d6a08a; color: var(--copper-dark); }

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

/* ─── Typing indicator ───────────────────────────── */
.typing {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: .75rem 1rem;
  display: inline-flex;
  gap: 4px;
  align-items: center;
  box-shadow: var(--shadow-sm);
}
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink3);
  animation: typingPulse 1.2s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes typingPulse {
  0%,80%,100% { transform: scale(.7); opacity: .4; }
  40%          { transform: scale(1); opacity: 1; }
}

/* ─── Property cards ─────────────────────────────── */
.cards-stack {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  margin: .4rem 0 .25rem 38px;
  max-width: calc(100% - 38px);
}
@media (max-width: 480px) {
  .cards-stack { margin-left: 0; max-width: 100%; }
}

.prop-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .2s, border-color .2s;
}
.prop-card:hover { box-shadow: var(--shadow-md); border-color: var(--ink3); transform: translateY(-1px); }

.prop-img {
  height: 156px;
  position: relative;
  background: linear-gradient(135deg, var(--copper-light) 0%, var(--cream3) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 2rem;
  color: var(--copper);
  overflow: hidden;
}
.prop-img::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(184,92,44,.12), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(26,24,20,.08), transparent 40%);
}
.prop-img-emoji {
  position: relative; z-index: 1;
  font-style: normal; font-size: 2.5rem;
  filter: drop-shadow(0 2px 4px rgba(26,24,20,.18));
}
.prop-img-photo {
  position: absolute; inset: 0; z-index: 2;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.prop-source {
  position: absolute; top: .6rem; left: .6rem;
  background: rgba(26,24,20,.78);
  backdrop-filter: blur(4px);
  color: #ddd;
  font-size: 9.5px;
  letter-spacing: .06em;
  padding: .22rem .55rem;
  border-radius: 100px;
  text-transform: uppercase;
  font-weight: 500;
  z-index: 1;
}
.prop-match {
  position: absolute; top: .6rem; right: .6rem;
  background: var(--cream);
  color: var(--ink2);
  font-size: 10.5px;
  letter-spacing: .02em;
  padding: .25rem .55rem;
  border-radius: 100px;
  font-weight: 500;
  z-index: 1;
}
.prop-match.high { background: var(--green); color: var(--cream); }

.prop-body { padding: .85rem 1rem .55rem; }
.prop-price-row {
  display: flex; align-items: baseline; gap: .4rem;
  margin-bottom: .15rem;
}
.prop-price {
  font-family: var(--serif);
  font-size: 1.45rem;
  color: var(--ink);
  line-height: 1;
}
.prop-price-unit { font-size: 11px; color: var(--ink3); }
.prop-comuna { font-size: 13px; color: var(--ink2); margin-bottom: .55rem; }
.prop-comuna strong { font-weight: 500; }
.prop-specs {
  display: flex; flex-wrap: wrap; gap: .8rem; margin-bottom: .55rem;
}
.prop-spec {
  display: flex; align-items: center; gap: .25rem;
  font-size: 12px; color: var(--ink3);
}
.prop-spec-icon { font-size: 13px; }

.prop-link {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .35rem;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--copper);
  text-decoration: none;
  background: var(--copper-light);
  border: 1px solid var(--copper);
  border-radius: var(--r-sm);
  padding: .45rem .7rem;
  margin-top: .25rem;
  transition: background .15s, color .15s, transform .1s;
}
.prop-link:hover {
  background: var(--copper);
  color: var(--white);
  text-decoration: none;
}
.prop-link:active { transform: scale(.98); }

.prop-actions {
  display: flex; gap: .4rem;
  border-top: 1px solid var(--border);
  padding: .55rem .65rem;
  background: var(--cream);
}
.prop-btn {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: .5rem .75rem;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  transition: all .15s;
}
.prop-btn.see-more { background: var(--ink); color: var(--cream); }
.prop-btn.see-more:hover { background: var(--ink2); }
.prop-btn.dislike { background: var(--white); border-color: var(--border); }
.prop-btn.dislike:hover { background: #f6e7e2; border-color: #d6a08a; color: var(--copper-dark); }
.prop-btn.dislike.disliked {
  background: var(--cream3); color: var(--ink3); border-color: var(--border);
  pointer-events: none;
}

/* ─── Quick reply chips ──────────────────────────── */
.chips {
  display: flex; flex-wrap: wrap; gap: .4rem;
  margin: .25rem 0 .4rem 38px;
  max-width: calc(100% - 38px);
}
@media (max-width: 480px) { .chips { margin-left: 0; max-width: 100%; } }
.chip {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: .45rem .95rem;
  font-size: 12.5px;
  color: var(--ink2);
  transition: all .15s;
}
.chip:hover, .chip:active { border-color: var(--copper); color: var(--copper-dark); background: var(--copper-light); }

/* ─── Offline banner ─────────────────────────────── */
.offline-banner {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(7.5rem + var(--safe-bottom));
  background: var(--ink);
  color: var(--cream);
  padding: .55rem 1rem;
  border-radius: 100px;
  font-size: 12.5px;
  z-index: 60;
  box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: .4rem;
}
/* `display: flex` above stomps the UA-stylesheet's [hidden]{display:none}.
   Without this rule, setting `offlineBan.hidden = true` from JS does
   nothing — the banner stays visible forever. */
.offline-banner[hidden] { display: none !important; }

/* ─── Sticky composer ────────────────────────────── */
.composer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, rgba(245,242,236,0) 0%, rgba(245,242,236,.96) 24%);
  padding: 1.4rem 1rem calc(1rem + var(--safe-bottom));
  z-index: 40;
}
.composer-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  padding: .35rem .35rem .35rem .9rem;
  transition: border-color .15s;
}
.composer-inner:focus-within { border-color: var(--copper); }
.composer-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-family: var(--sans);
  font-size: 16px; /* iOS no-zoom */
  color: var(--ink);
  padding: .55rem 0;
  max-height: 140px;
  min-height: 24px;
  line-height: 1.45;
}
.composer-input::placeholder { color: var(--ink3); }

.send-btn {
  background: var(--ink);
  border: none;
  color: var(--cream);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all .15s;
}
.send-btn:hover:not(:disabled) { background: var(--copper); transform: translateY(-1px); }
.send-btn:disabled { background: var(--cream3); color: var(--ink3); cursor: not-allowed; }

.composer-hint {
  max-width: 720px;
  margin: .4rem auto 0;
  font-size: 10.5px;
  color: var(--ink3);
  text-align: center;
  letter-spacing: .03em;
}

/* ─── Install toast (iOS A2HS hint) ──────────────── */
.install-toast {
  position: fixed;
  left: 1rem; right: 1rem;
  bottom: calc(7.5rem + var(--safe-bottom));
  z-index: 70;
  animation: slideUp .35s ease both;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.install-toast-inner {
  max-width: 480px;
  margin: 0 auto;
  background: var(--ink);
  color: var(--cream);
  border-radius: var(--r-lg);
  padding: .85rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  box-shadow: var(--shadow-lg);
}
.install-toast-icon { font-size: 1.25rem; }
.install-toast-body { flex: 1; font-size: 13px; line-height: 1.4; }
.install-toast-body strong { display: block; font-weight: 500; margin-bottom: .15rem; }
.install-toast-body em { font-style: normal; color: var(--copper-mid); font-weight: 500; }
.install-toast-close {
  background: transparent;
  border: none;
  color: var(--cream);
  font-size: 14px;
  opacity: .65;
  padding: .25rem .5rem;
}
.install-toast-close:hover { opacity: 1; }

/* ─── Responsive ─────────────────────────────────── */
@media (min-width: 640px) {
  .hero h1 { font-size: 2.75rem; }
  .hero p { font-size: 15px; }
}

@media (max-width: 480px) {
  .header { padding: 0 1rem; }
  .brand { font-size: 1.25rem; }
  .brand-status { display: none; }
  .hero { padding: 1.75rem 1.25rem 1rem; }
  .hero h1 { font-size: 1.85rem; }
  .chat { padding: 0 .85rem 9rem; }
  .bubble { max-width: 84%; font-size: 14px; }
  .composer { padding: 1rem .75rem calc(.85rem + var(--safe-bottom)); }
  .composer-inner { padding: .3rem .3rem .3rem .8rem; }
  .send-btn { width: 36px; height: 36px; }
}

/* PWA standalone tweaks */
@media (display-mode: standalone) {
  .header { padding-top: 0; }
  body { background: var(--cream); }
}
