/* ============================================================
   Luna's Properties — AI chat widget
   Uses the site's palette vars from styles.css, with fallbacks.
   ============================================================ */

.lp-chat-btn {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 500;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--gold, #b0894a);
  color: #fff;
  box-shadow: 0 6px 20px rgba(23, 24, 26, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.2s ease;
}
.lp-chat-btn:hover {
  background: var(--gold-dark, #96713a);
  transform: translateY(-2px);
}
.lp-chat-btn svg {
  width: 26px;
  height: 26px;
  fill: #fff8ec;
  stroke: none;
}

/* ---- Luna's greeting bubble (appears a few seconds after load) ---- */
.lp-teaser {
  position: fixed;
  bottom: 92px;
  right: 22px;
  z-index: 499;
  display: none;
  max-width: 244px;
  padding: 13px 16px;
  background: #fff;
  color: var(--ink, #17181a);
  border: 1px solid var(--line, #e4ddd0);
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 10px 28px rgba(23, 24, 26, 0.22);
  font-size: 0.87rem;
  line-height: 1.45;
  cursor: pointer;
}
.lp-teaser.lp-teaser-show { display: block; animation: lp-teaser-rise 0.45s ease both; }
.lp-teaser strong { display: block; font-weight: 600; margin-bottom: 2px; }
.lp-teaser span { color: var(--ink-soft, #4b4d52); }
.lp-teaser:hover { border-color: var(--gold, #b0894a); }

.lp-teaser-x {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--ink, #17181a);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.lp-teaser-x:hover { background: var(--gold-dark, #96713a); }

@keyframes lp-teaser-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* Never show the greeting while the chat panel is open */
.lp-chat-open .lp-teaser { display: none; }
.lp-chat-btn .lp-close-icon { display: none; font-size: 1.6rem; line-height: 1; }
.lp-chat-open .lp-chat-btn .lp-chat-icon { display: none; }
.lp-chat-open .lp-chat-btn .lp-close-icon { display: block; }

.lp-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 22px;
  z-index: 500;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 480px;
  max-height: calc(100vh - 120px);
  background: var(--cream, #faf8f4);
  border: 1px solid var(--line, #e4ddd0);
  border-radius: 16px;
  box-shadow: 0 22px 60px rgba(23, 24, 26, 0.25);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.lp-chat-open .lp-chat-panel { display: flex; }

.lp-chat-header {
  flex-shrink: 0;
  background: var(--ink, #17181a);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.lp-chat-header .lp-moon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--gold, #b0894a);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.lp-chat-header .lp-moon svg { width: 19px; height: 19px; fill: #fff8ec; }
.lp-chat-header .lp-head-text { flex: 1; min-width: 0; }
/* In-header close button — only used on the mobile full-screen sheet, where the
   floating round button is hidden behind the panel. */
.lp-chat-header .lp-head-x {
  display: none;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.lp-chat-header h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: 1.05rem;
  margin: 0;
}
.lp-chat-header p {
  margin: 0;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.6);
}

.lp-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lp-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.lp-msg-bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line, #e4ddd0);
  color: var(--ink, #17181a);
  border-bottom-left-radius: 4px;
}
.lp-msg-user {
  align-self: flex-end;
  background: var(--gold, #b0894a);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.lp-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line, #e4ddd0);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
}
.lp-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold, #b0894a);
  animation: lp-bounce 1.2s infinite ease-in-out;
}
.lp-typing span:nth-child(2) { animation-delay: 0.15s; }
.lp-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes lp-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.lp-chat-form {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line, #e4ddd0);
  background: #fff;
}
.lp-chat-form input {
  flex: 1;
  border: 1.5px solid var(--line, #e4ddd0);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--cream, #faf8f4);
  color: var(--ink, #17181a);
}
.lp-chat-form input:focus {
  outline: none;
  border-color: var(--gold, #b0894a);
  background: #fff;
}
.lp-chat-form button {
  border: none;
  border-radius: 999px;
  background: var(--gold, #b0894a);
  color: #fff;
  padding: 0 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}
.lp-chat-form button:hover:not(:disabled) { background: var(--gold-dark, #96713a); }
.lp-chat-form button:disabled { opacity: 0.5; cursor: default; }

.lp-chat-note {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: var(--ink-soft, #4b4d52);
  text-align: center;
  padding: 0 12px 10px;
  background: #fff;
  margin: 0;
}

/* ============================================================
   iOS auto-zoom guard
   Safari zooms the whole page when a focused form control has a
   computed font-size below 16px. Any touch device gets exactly 16px
   on the chat input so focusing it never rescales the page.
   Desktop keeps the smaller 0.9rem type.
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
  .lp-chat-form input {
    font-size: 16px;
    line-height: 1.25;
  }
}

/* ============================================================
   Phones — full-screen sheet
   The panel is pinned to the VISUAL viewport (not the layout
   viewport) via --lp-vh / --lp-vv-top, which chat-widget.js keeps in
   sync with window.visualViewport. That is what stops the on-screen
   keyboard from pushing the composer off-screen. 100dvh / 100vh are
   the fallbacks when the API is unavailable.
   ============================================================ */
@media (max-width: 600px) {
  .lp-chat-panel {
    top: var(--lp-vv-top, 0px);
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    height: var(--lp-vh, 100dvh);
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .lp-chat-header {
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
  }
  .lp-chat-header .lp-head-x { display: block; }

  /* The floating round button sits under the sheet on mobile, so the
     in-header X becomes the only close affordance. */
  .lp-chat-open .lp-chat-btn { display: none; }

  .lp-chat-btn { bottom: 16px; right: 16px; }
  .lp-teaser { bottom: 86px; right: 16px; max-width: calc(100vw - 60px); }

  .lp-msg { max-width: 88%; }
}

/* Freeze the page behind the sheet so the background can't scroll or
   rubber-band while the chat is open. */
html.lp-chat-locked,
body.lp-chat-locked {
  overflow: hidden;
  overscroll-behavior: none;
}
