/**
 * Ask Glen — Residential Discovery drawer + floating launcher (Visual V2).
 * Discovery + homepage floating launcher; no portal redesign.
 * Identity chrome mirrors approved Agent Portal S2-J CTA
 * (css/propglen-premium-header.css). Conversation architecture unchanged.
 */
:root {
  --ask-pg-navy: #062b5b;
  --ask-pg-navy-deep: #041f42;
  --ask-pg-emerald: #0ba360;
  --ask-pg-ink: #142033;
  --ask-pg-muted: #5b6b7c;
  --ask-pg-line: #d7dee8;
  --ask-pg-paper: #f4f7fb;
  --ask-pg-drawer: 500px;
  /* Agent Portal S2-J — reuse only, do not invent stops */
  --ask-pg-agent-cta: linear-gradient(110deg, #087b4d 0%, #086878 48%, #062b5b 100%);
  --ask-pg-agent-cta-hover: linear-gradient(110deg, #076f45 0%, #075a68 48%, #041f42 100%);
  --ask-pg-agent-cta-border: #062b5b;
  --ask-pg-agent-cta-border-hover: #041f42;
  --ask-pg-fab-z: 2880;
  --ask-pg-drawer-z: 3120;
  --ask-pg-backdrop-z: 3110;
}

/* —— Floating Ask Glen launcher —— */
.askglen-fab {
  position: fixed;
  right: 18px;
  bottom: 24px;
  z-index: var(--ask-pg-fab-z);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  border: 1px solid var(--ask-pg-agent-cta-border);
  border-radius: 999px;
  background: var(--ask-pg-agent-cta);
  color: #fff;
  box-shadow: none;
  cursor: pointer;
  font: inherit;
  transition: filter 120ms ease, border-color 120ms ease;
}
.askglen-fab[hidden] { display: none !important; }
.askglen-fab:hover,
.askglen-fab:focus-visible {
  background: var(--ask-pg-agent-cta-hover);
  border-color: var(--ask-pg-agent-cta-border-hover);
  filter: brightness(1.04);
}
.askglen-fab:focus-visible {
  outline: 2px solid var(--ask-pg-agent-cta-border);
  outline-offset: 2px;
}
.askglen-fab__mark {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: #ffffff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}
.askglen-fab__mark img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
}
.askglen-fab__copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  padding-right: 4px;
}
.askglen-fab__copy strong {
  font-size: 0.86rem;
  font-weight: 750;
}
.askglen-fab__copy em {
  font-style: normal;
  font-size: 0.62rem;
  opacity: 0.72;
  font-weight: 600;
  letter-spacing: 0.02em;
}

html.ask-drawer-open .askglen-fab,
html.ask-drawer-open .askglen-fab-dock {
  display: none !important;
}

.askglen-fab-dock {
  display: none;
}

/* Desktop: clear sticky Saved/Enquire cluster when present */
@media (min-width: 901px) {
  body.listings-page .askglen-fab {
    bottom: 72px;
    right: 18px;
  }
}

/* Mobile: reserved dock above app nav; compact circular launcher */
@media (max-width: 900px) {
  .askglen-fab-dock {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    /* Sit above Filters/Sort bar + app nav so FAB never covers either control */
    bottom: calc(
      var(--mobile-listings-bottom-stack, calc(var(--mobile-nav-clearance, 80px) + 52px))
    );
    height: 56px;
    align-items: center;
    justify-content: flex-end;
    padding: 0 14px;
    background: transparent;
    pointer-events: none;
    z-index: var(--ask-pg-fab-z);
  }
  .askglen-fab-dock .askglen-fab,
  body.listings-page .askglen-fab {
    position: relative;
    right: auto;
    bottom: auto;
    width: 46px;
    height: 46px;
    padding: 0;
    gap: 0;
    border-radius: 50%;
    justify-content: center;
    align-items: center;
    margin-left: auto;
    pointer-events: auto;
  }
  body.listings-page .askglen-fab__copy { display: none; }
  body.listings-page .askglen-fab__mark {
    width: 34px;
    height: 34px;
    box-shadow: none;
  }
  body.listings-page .askglen-fab__mark img {
    width: 26px;
    height: 26px;
  }
  /* Keep last listing cards clear of FAB + filter/nav stack */
  body.listings-page .bayut-serp__results,
  body.listings-page .bayut-serp__main {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }
}

/* Retire sidebar AI entry from customer UI (FAB is sole entry). */
body.listings-page .rv-ai-sidebar,
body.listings-page [data-ai-sidebar] {
  display: none !important;
}

/* Legacy float remains suppressed */
body.listings-page .rv-ai-float,
body.listings-page [data-ai-float] {
  display: none !important;
}

/* —— Drawer —— */
.ask-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 32, 0.28);
  z-index: var(--ask-pg-backdrop-z);
}
.ask-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(var(--ask-pg-drawer), 100vw);
  height: 100vh;
  height: 100dvh;
  background: #fff;
  z-index: var(--ask-pg-drawer-z);
  display: flex;
  flex-direction: column;
  box-shadow: -14px 0 36px rgba(6, 43, 91, 0.16);
  overscroll-behavior: contain;
}
html.ask-drawer-open,
html.ask-drawer-open body {
  overflow: hidden;
  touch-action: none;
}
html.ask-drawer-open body {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
}
.ask-drawer[hidden], .ask-backdrop[hidden] { display: none !important; }

.ask-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ask-pg-agent-cta);
  color: #fff;
  border-bottom: 1px solid var(--ask-pg-agent-cta-border);
  flex-shrink: 0;
}
.ask-drawer__brand { display: flex; gap: 11px; align-items: center; min-width: 0; }
.ask-drawer__mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #ffffff;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
  color: transparent;
  font-size: 0;
}
.ask-drawer__mark img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
}
/*
 * Beat Discovery heading rule `.bayut-serp-page:not(.home-page) h2`
 * (specificity 0,2,1 via :not(.home-page)) so Ask Glen title stays white
 * on the S2-J Agent Portal gradient.
 */
body.pg-public.listings-page.bayut-serp-page .ask-drawer__head,
body.listings-page.bayut-serp-page .ask-drawer__head {
  color: #ffffff;
}
body.pg-public.listings-page.bayut-serp-page .ask-drawer__head h2,
body.pg-public.listings-page.bayut-serp-page .ask-drawer__head #ask-title,
body.listings-page.bayut-serp-page .ask-drawer__head h2,
body.listings-page.bayut-serp-page .ask-drawer__head #ask-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 750;
  line-height: 1.2;
  color: #ffffff;
}
body.pg-public.listings-page.bayut-serp-page .ask-drawer__head p,
body.listings-page.bayut-serp-page .ask-drawer__head p {
  margin: 2px 0 0;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.86);
  opacity: 1;
}
.ask-drawer__actions { display: inline-flex; gap: 4px; flex-shrink: 0; }
.ask-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.ask-icon-btn:hover { background: rgba(255,255,255,0.16); }
.ask-icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.ask-drawer__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-anchor: none;
  padding: 14px;
  background: var(--ask-pg-paper);
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  --ask-scroll-pad: 0px;
}
/* Dynamic spacer: sized in JS so a new short reply can rise to the top. */
.ask-drawer__body::after {
  content: "";
  flex: 0 0 var(--ask-scroll-pad);
  pointer-events: none;
}
.ask-turn {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 auto;
  scroll-margin-top: 8px;
}

.ask-welcome {
  background: #fff;
  border: 1px solid var(--ask-pg-line);
  border-top: 3px solid var(--ask-pg-navy);
  border-radius: 14px;
  padding: 14px;
}
.ask-welcome h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  color: var(--ask-pg-navy);
}
.ask-welcome p {
  margin: 0 0 8px;
  font-size: 0.88rem;
  color: var(--ask-pg-muted);
  line-height: 1.45;
}
.ask-welcome__ai {
  margin: 0 0 12px !important;
  font-size: 0.78rem !important;
  font-weight: 700;
  color: var(--ask-pg-navy) !important;
}

.ask-bubble {
  max-width: 94%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.ask-bubble--assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--ask-pg-line);
  border-bottom-left-radius: 4px;
  color: var(--ask-pg-ink);
}
.ask-bubble--user {
  align-self: flex-end;
  background: var(--ask-pg-navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ask-bubble__meta {
  display: block;
  margin-bottom: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  opacity: 0.62;
}

.ask-suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.ask-chip {
  border: 1px solid rgba(11,163,96,0.35);
  background: #fff;
  color: var(--ask-pg-navy);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.76rem;
  cursor: pointer;
  text-align: left;
}
.ask-chip:hover { border-color: var(--ask-pg-emerald); color: var(--ask-pg-emerald); }
.ask-chip:focus-visible { outline: 2px solid var(--ask-pg-emerald); outline-offset: 2px; }

.ask-results-block { display: grid; gap: 8px; }
.ask-results-label {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ask-pg-navy);
}
.ask-results-label.is-alt {
  color: #6a5540;
  background: #fff7e8;
  border: 1px solid #f0e0c4;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 650;
  line-height: 1.35;
}
.ask-results { display: grid; gap: 8px; }
.ask-view-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 2px;
  border: 1px dashed rgba(6, 43, 91, 0.28);
  background: #fff;
  color: var(--ask-pg-navy);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.ask-view-more:hover { border-color: var(--ask-pg-emerald); color: var(--ask-pg-emerald); }
.ask-view-more:focus-visible { outline: 2px solid var(--ask-pg-emerald); outline-offset: 2px; }
.ask-result {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--ask-pg-line);
  color: inherit;
  min-width: 0;
  overflow: hidden;
  align-items: start;
}
.ask-result:hover { border-color: rgba(11,163,96,0.45); }
.ask-result__body { min-width: 0; overflow-wrap: anywhere; }
.ask-result__media {
  width: 76px;
  max-width: 100%;
  height: 76px;
  border-radius: 8px;
  object-fit: cover;
  background: #dfe6ef;
  display: block;
}
.ask-result__title { margin: 0; font-size: 0.8rem; font-weight: 700; color: var(--ask-pg-navy); line-height: 1.3; }
.ask-result__meta { margin: 4px 0 0; font-size: 0.72rem; color: var(--ask-pg-muted); }
.ask-result__price { margin: 4px 0 0; font-size: 0.84rem; font-weight: 750; color: var(--ask-pg-ink); }
.ask-result__link {
  display: inline-flex;
  margin-top: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ask-pg-emerald);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ask-result__link:focus-visible { outline: 2px solid var(--ask-pg-emerald); outline-offset: 2px; border-radius: 4px; }
.ask-trust { display: inline-flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.ask-trust span {
  font-size: 0.62rem; font-weight: 700;
  padding: 2px 6px; border-radius: 999px;
  background: #e7f4ee; color: #0a7a48;
}

.ask-empty {
  background: #fff;
  border: 1px dashed var(--ask-pg-line);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  color: var(--ask-pg-muted);
  font-size: 0.86rem;
}

.ask-cta-row { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-cta {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; padding: 9px 12px; font-weight: 700; font-size: 0.82rem;
  text-decoration: none; border: none; cursor: pointer;
}
.ask-cta--primary { background: var(--ask-pg-emerald); color: #fff; }
.ask-cta--ghost { background: #fff; color: var(--ask-pg-navy); border: 1px solid var(--ask-pg-line); }

.ask-drawer__foot {
  border-top: 1px solid var(--ask-pg-line);
  padding: 10px 12px 12px;
  background: #fff;
  flex-shrink: 0;
}
.ask-status {
  margin: 0 0 8px;
  font-size: 0.78rem;
  padding: 8px 10px;
  border-radius: 8px;
}
.ask-status.is-loading { background: #eef7f2; color: #0a7a48; }
.ask-status.is-error { background: #fdeeee; color: #8a1f1f; }

.ask-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: end;
}
.ask-composer textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--ask-pg-line);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  line-height: 1.4;
  min-height: 48px;
  background: #fff;
}
.ask-composer textarea:focus {
  outline: none;
  border-color: var(--ask-pg-emerald);
  box-shadow: 0 0 0 3px rgba(11,163,96,0.18);
}
.ask-composer textarea:disabled {
  background: var(--ask-pg-paper);
  color: var(--ask-pg-muted);
}
.ask-send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--ask-pg-navy);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.ask-send:hover { background: #0a3a6e; }
.ask-send:focus-visible { outline: 2px solid var(--ask-pg-emerald); outline-offset: 2px; }
.ask-send:disabled { opacity: 0.45; cursor: not-allowed; }

.ask-disclaimer { margin: 8px 0 0; font-size: 0.66rem; color: var(--ask-pg-muted); line-height: 1.35; }

/* Mobile sheet drawer — above app nav / filter bar */
@media (max-width: 720px) {
  .ask-drawer {
    width: 100vw;
    top: auto;
    bottom: 0;
    height: min(78vh, 640px);
    height: min(78dvh, 640px);
    border-radius: 18px 18px 0 0;
  }
  .ask-result {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }
  .ask-result__media {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 10;
    border-radius: 12px 12px 0 0;
  }
  .ask-result__body {
    padding: 10px 12px 12px;
  }
}


/* D9 homepage Ask Glen — clear mobile app nav; desktop uses default FAB */
@media (max-width: 900px) {
  body.home-page .askglen-fab-dock {
    bottom: var(--mobile-nav-clearance, 80px);
    height: 56px;
  }
  body.home-page .askglen-fab-dock .askglen-fab__copy { display: none; }
  body.home-page .askglen-fab-dock .askglen-fab__mark {
    width: 34px;
    height: 34px;
    box-shadow: none;
  }
  body.home-page .askglen-fab-dock .askglen-fab__mark img {
    width: 26px;
    height: 26px;
  }
}
@media (min-width: 901px) {
  body.home-page .askglen-fab {
    bottom: 24px;
    right: 18px;
  }
}
