/* Asistent Imobiliar AI — page layout approved by the owner (CLAUDE.md 14.0). Colors only here. */

:root {
  --accent: #2f6f6a;
  --accent-strong: #24564f;
  --accent-soft: #e3efed;
  --accent-ring: rgba(47, 111, 106, 0.2);
  --accent-contrast: #ffffff;
  --plane-shade: #d5e4e2;
  --bg-top: #eef2f4;
  --bg-bottom: #dde4e8;
  --surface: #ffffff;
  --surface-muted: #f3f6f8;
  --text: #1c2630;
  --text-muted: #5b6875;
  --border: #d6dde3;
  --edge: #d3dbe1;
  --edge-strong: #a9b5be;
  --bar-line: #e2e7eb;
  --window-edge: rgba(255, 255, 255, 0.7);
  --bubble-user: var(--accent);
  --bubble-user-text: #ffffff;
  --bubble-bot: #f1f4f6;
  --notice-bg: #fff7e8;
  --notice-border: #ecd5a6;
  --shadow: 0 18px 50px rgba(28, 38, 48, 0.16);
  --radius-chat: 22px;
  --radius-card: 14px;
  --side: clamp(16px, 5vw, 96px);
  --spare: max(0px, calc(var(--side) - 16px));
  --wide-extra: min(60px, var(--spare));
  --wide-shift: min(48px, max(0px, calc(var(--spare) - var(--wide-extra))));
  --page-zoom: 1;
  --transition: 0.35s ease;
  --appear: 0.22s ease-out;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;
}

/* Read by screen readers, invisible on screen. */
.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* "scale", not "transform": buttons positioned with a transform (gallery arrows) keep their place. */
button { font: inherit; cursor: pointer; transition: scale 0.1s ease; }
button:active:not(:disabled) { scale: 0.96; }
a { color: var(--accent-strong); }

/* ---------- Desktop layout ---------- */

.page { zoom: var(--page-zoom); }

.layout {
  max-width: 1560px;
  margin: 0 auto;
  padding-inline: var(--side);
  min-height: calc(100vh / var(--page-zoom));
  display: grid;
  grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr);
  align-items: center;
  column-gap: clamp(24px, 3vw, 56px);
}

.intro {
  transform: translate(calc(-1 * min(3vw, 60px)), calc(-1 * min(2.5vh, 28px)));
  max-width: 520px;
}

.intro-title { font-size: clamp(22px, 1.8vw, 27px); margin: 0 0 12px; letter-spacing: -0.01em; }
.intro-lead { font-size: 15px; line-height: 1.55; color: var(--text-muted); margin: 0 0 18px; }

.stats { list-style: none; display: flex; gap: 22px; padding: 0; margin: 0 0 18px; }
.stats li { display: flex; flex-direction: column; }
.stats strong { font-size: 18px; color: var(--accent-strong); }
.stats span { font-size: 12px; color: var(--text-muted); }

.intro-list { font-size: 13px; line-height: 1.7; margin: 0 0 18px; padding-left: 18px; color: var(--text); }

.notice {
  font-size: 12px;
  line-height: 1.5;
  background: var(--notice-bg);
  border: 1px solid var(--notice-border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
}
.notice-title { display: block; margin-bottom: 2px; }
.notice-text { margin: 0; }

/* ---------- Chat window ---------- */

.chat {
  justify-self: end;
  width: 460px;
  height: min(700px, calc((100vh - 140px) / var(--page-zoom)));
  margin-right: max(0px, calc((100% - 460px) / 2));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface);
  border-radius: var(--radius-chat);
  /* The thin white edge sits inside the window (chosen by the owner: 1 px, 70%). */
  box-shadow: var(--shadow), inset 0 0 0 1px var(--window-edge);
  overflow: hidden;
  transition: width var(--transition), height var(--transition), margin var(--transition), transform var(--transition);
  animation: chat-in 0.25s ease-out;
}

.chat--wide {
  width: calc(100% + var(--wide-extra));
  height: min(780px, calc((100vh - 140px) / var(--page-zoom)));
  margin-right: calc(-1 * var(--wide-extra));
  transform: translateX(var(--wide-shift));
}

.chat[hidden] { display: none; }
.chat--closing { animation: chat-out 0.2s ease-in forwards; }
@keyframes chat-in { from { opacity: 0; translate: 0 16px; scale: 0.98; } to { opacity: 1; translate: none; scale: none; } }
@keyframes chat-out { to { opacity: 0; translate: 0 16px; scale: 0.98; } }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-identity { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  display: grid;
  place-items: center;
}
.chat-title { margin: 0; font-weight: 600; font-size: 15px; }
.chat-subtitle { margin: 0; font-size: 12px; color: var(--text-muted); }
.chat-actions { display: flex; gap: 4px; }

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  transition: background-color 0.15s ease, color 0.15s ease, scale 0.1s ease;
}
.icon-button:hover, .icon-button:focus-visible { background: var(--surface-muted); color: var(--text); }
.icon-button:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-body { position: relative; display: flex; min-height: 0; }

.messages {
  list-style: none;
  margin: 0;
  padding: 16px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* The page decides where the list goes (follow.js); the browser must not shift it by itself. */
  overflow-anchor: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  animation: message-in var(--appear);
}
@keyframes message-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: none; } }
.message p { margin: 0; }
.message ul { margin: 0; padding-left: 20px; list-style: disc; }
.message--bot { align-self: flex-start; background: var(--bubble-bot); border: 1px solid var(--edge); border-bottom-left-radius: 6px; }
.message--user { align-self: flex-end; background: var(--bubble-user); color: var(--bubble-user-text); border-bottom-right-radius: 6px; }
.message--welcome { max-width: 100%; }
.chat:not(.chat--wide) .messages > .message:first-child { margin-top: 20px; }
.message-note { margin-top: 6px !important; font-size: 13px; color: var(--text-muted); }
.message a[href^="tel:"] { font-weight: 600; text-decoration: none; }

.quick-replies { display: flex; flex-wrap: nowrap; gap: 8px; margin-top: 10px; }
.quick-reply {
  flex: 1 1 auto;
  white-space: nowrap;
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 14px;
  transition: background-color 0.15s ease, scale 0.1s ease;
}
.quick-reply:hover, .quick-reply:focus-visible { background: var(--accent-soft); }
/* One row while the chat is compact (approved); beside the panel the column is narrower. */
.chat--wide .quick-replies { flex-wrap: wrap; }

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- Composer ---------- */

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 26px 18px 44px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer textarea {
  flex: 1 1 auto;
  resize: none;
  height: auto;
  padding: 14px;
  font: inherit;
  font-size: 17px;
  line-height: 24px;
  border: 1.5px solid var(--edge-strong);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.send-button {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.send-button:disabled { opacity: 0.45; cursor: not-allowed; }
.plane-top { fill: var(--accent-contrast); }
.plane-bottom { fill: var(--plane-shade); }
.send-button--flying .plane { animation: plane-flight 0.45s ease-in-out; }
@keyframes plane-flight {
  0% { translate: 0 0; opacity: 1; }
  45% { translate: 26px -26px; opacity: 0; }
  55% { translate: -26px 26px; opacity: 0; }
  100% { translate: 0 0; opacity: 1; }
}

/* ---------- Floating button ---------- */

.reopen-button {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow);
  font-weight: 600;
  animation: rise 0.3s ease;
  z-index: 10;
}
.reopen-button[hidden] { display: none; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Phone and tablet: the open chat is the whole visible screen ---------- */

@media (max-width: 979.98px) {
  html, body { height: auto; }
  html { min-height: 100%; }
  html.chat-open, html.chat-open body { overflow: hidden; }
  html.chat-open .intro { display: none; }
  .layout { display: block; padding: 0; min-height: 0; }
  .intro {
    transform: none;
    max-width: none;
    padding: calc(24px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  }
  /* --app-height / --app-top: the visible part of the screen, measured by layout.js (keyboard included). */
  .chat, .chat--wide {
    position: fixed;
    left: 0;
    right: 0;
    top: var(--app-top, 0px);
    width: auto;
    height: var(--app-height, 100dvh);
    margin: 0;
    padding-top: env(safe-area-inset-top);
    border-radius: 0;
    box-shadow: none;
    transform: none;
    transition: none;
    z-index: 5;
  }
  .chat-header { padding-inline: calc(12px + env(safe-area-inset-left)) calc(12px + env(safe-area-inset-right)); }
  .messages { padding: 12px calc(12px + env(safe-area-inset-right)) 12px calc(12px + env(safe-area-inset-left)); }
  .message { font-size: 15px; }

  /* Bottom bar, exact values approved by the owner: 1 px line 16 px above the field, 4 px (or the
     phone's own bottom bar) under it; the spacing never changes with focus or the keyboard. */
  .composer {
    gap: 10px;
    padding: 16px calc(10px + env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
    border-top: 1px solid var(--bar-line);
  }
  .composer textarea {
    height: 44px;
    min-height: 44px;
    max-height: 120px;
    padding: 8.5px 12px;
    font-size: 16px;
    line-height: 1.4;
    border-radius: 14px;
    overflow-y: auto;
  }
  .send-button { width: 44px; height: 44px; }
  .send-button .plane { width: 21px; height: 21px; }

  /* The three welcome buttons stay on one row on every phone; a long label breaks inside its button. */
  .quick-replies { gap: 6px; }
  .quick-reply { flex: 1 1 0; min-width: 0; min-height: 38px; white-space: normal; line-height: 1.2; padding: 5px 6px; font-size: 13px; }
}

@media (max-width: 979.98px) and (max-height: 500px) {
  .composer { padding-top: 6px; }
  .chat-header { padding-block: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
