.sc-chat {
  --sc-chat-shadow: 0 24px 70px rgba(41, 48, 43, 0.22);
  position: fixed;
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 230;
  font-family: "Manrope", sans-serif;
  color: var(--graphite, #3a3935);
  pointer-events: none;
}

.sc-chat *,
.sc-chat *::before,
.sc-chat *::after {
  box-sizing: border-box;
}

.sc-chat__launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--forest, #4a5f50);
  color: var(--white, #fff);
  box-shadow: 0 12px 32px rgba(58, 74, 63, 0.32);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.sc-chat__launcher:hover {
  background: var(--forest-dark, #3a4a3f);
  box-shadow: 0 15px 38px rgba(58, 74, 63, 0.38);
  transform: translateY(-2px);
}

.sc-chat__launcher:focus-visible,
.sc-chat__icon-button:focus-visible,
.sc-chat__send:focus-visible,
.sc-chat__retry:focus-visible {
  outline: 3px solid rgba(74, 95, 80, 0.45);
  outline-offset: 3px;
}

.sc-chat.is-open .sc-chat__launcher {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.sc-chat__launcher-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.sc-chat__launcher-icon .sc-chat__icon-fill,
.sc-chat__avatar .sc-chat__icon-fill {
  fill: currentColor;
  stroke: none;
}

.sc-chat__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  width: min(390px, calc(100vw - 32px));
  height: min(620px, calc(100dvh - 40px));
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(74, 95, 80, 0.16);
  border-radius: 24px;
  background: var(--cream, #f6f4ef);
  box-shadow: var(--sc-chat-shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px) scale(0.98);
  transform-origin: right bottom;
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms;
}

.sc-chat.is-open .sc-chat__panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.sc-chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 17px 16px 15px 18px;
  border-bottom: 1px solid rgba(74, 95, 80, 0.12);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(14px);
}

.sc-chat__avatar {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--forest, #4a5f50);
  color: var(--white, #fff);
}

.sc-chat__avatar svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.sc-chat__heading {
  min-width: 0;
  flex: 1;
}

.sc-chat__title {
  margin: 0;
  color: var(--forest-dark, #3a4a3f);
  font-family: "Cormorant Garamond", serif;
  font-size: 1.38rem;
  font-weight: 600;
  line-height: 1.05;
}

.sc-chat__subtitle {
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--muted, #6f6a62);
  font-size: 0.7rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sc-chat__header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sc-chat__icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--forest-dark, #3a4a3f);
  cursor: pointer;
  place-items: center;
  transition: background-color 160ms ease;
}

.sc-chat__icon-button:hover {
  background: var(--sand, #ebe6dc);
}

.sc-chat__icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.sc-chat__messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px;
  overscroll-behavior: contain;
  scrollbar-color: rgba(74, 95, 80, 0.28) transparent;
}

.sc-chat__message {
  max-width: 86%;
  padding: 11px 13px;
  border-radius: 16px;
  font-size: 0.84rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.sc-chat__message--assistant {
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  background: var(--white, #fff);
  box-shadow: 0 5px 16px rgba(58, 57, 53, 0.07);
}

.sc-chat__message--error {
  border: 1px solid rgba(156, 74, 58, 0.28);
  background: rgba(156, 74, 58, 0.08);
  color: #7a3a2e;
  box-shadow: none;
}

.sc-chat__error-row {
  display: flex;
  align-items: flex-start;
  align-self: flex-start;
  gap: 8px;
  max-width: 100%;
}

.sc-chat__error-row .sc-chat__message--error {
  max-width: calc(86% - 36px);
}

.sc-chat__message--with-contacts {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 92%;
}

.sc-chat__message-body {
  white-space: pre-wrap;
}

.sc-chat__contacts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  white-space: normal;
}

.sc-chat__contact {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 11px;
  border: 1px solid rgba(74, 95, 80, 0.22);
  border-radius: 10px;
  background: rgba(74, 95, 80, 0.06);
  color: var(--forest, #4a5f50);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background 160ms ease, border-color 160ms ease;
}

.sc-chat__contact:hover,
.sc-chat__contact:focus-visible {
  background: rgba(74, 95, 80, 0.12);
  border-color: rgba(74, 95, 80, 0.38);
  outline: none;
}

.sc-chat__message--user {
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  background: var(--forest, #4a5f50);
  color: var(--white, #fff);
}

.sc-chat__typing {
  display: inline-flex;
  align-self: flex-start;
  gap: 5px;
  padding: 13px 15px;
  border-radius: 16px 16px 16px 5px;
  background: var(--white, #fff);
  box-shadow: 0 5px 16px rgba(58, 57, 53, 0.07);
}

.sc-chat__typing[hidden] {
  display: none;
}

.sc-chat__typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warm, #8f735f);
  animation: sc-chat-pulse 1.2s infinite ease-in-out;
}

.sc-chat__typing-dot:nth-child(2) {
  animation-delay: 140ms;
}

.sc-chat__typing-dot:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes sc-chat-pulse {
  0%, 70%, 100% { opacity: 0.35; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}

.sc-chat__form {
  padding: 12px 14px 18px;
  border-top: 1px solid rgba(74, 95, 80, 0.12);
  background: rgba(255, 255, 255, 0.88);
}

.sc-chat__composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  min-height: 52px;
  padding: 6px 6px 6px 16px;
  border: 1px solid rgba(74, 95, 80, 0.22);
  border-radius: 26px;
  background: var(--white, #fff);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.sc-chat__composer:focus-within {
  border-color: rgba(74, 95, 80, 0.45);
  box-shadow: none;
}

.sc-chat__composer textarea {
  display: block;
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  min-height: 24px;
  max-height: 96px;
  margin: 0;
  padding: 10px 0;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: none;
  box-shadow: none;
  background: transparent;
  color: var(--graphite, #3a3935);
  font: inherit;
  font-size: 0.84rem;
  line-height: 1.4;
  -webkit-appearance: none;
  appearance: none;
}

.sc-chat__composer textarea:focus,
.sc-chat__composer textarea:focus-visible {
  outline: none;
  box-shadow: none;
  border: 0;
}

.sc-chat__composer textarea::placeholder {
  color: #8a857d;
}

.sc-chat__send {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--tent, #d87040);
  color: var(--white, #fff);
  cursor: pointer;
  place-items: center;
  line-height: 0;
  transition: background-color 160ms ease, transform 160ms ease;
}

.sc-chat__send:hover:not(:disabled) {
  background: var(--tent-dark, #c46238);
  transform: translateY(-1px);
}

.sc-chat__send:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.sc-chat__send svg {
  display: block;
  width: 18px;
  height: 18px;
  margin: 0;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.sc-chat__footer {
  display: flex;
  min-height: 0;
  align-items: center;
  gap: 8px;
  padding: 0 14px 12px;
  background: rgba(255, 255, 255, 0.88);
}

.sc-chat__footer[hidden] {
  display: none;
}

.sc-chat__status {
  min-width: 0;
  flex: 1;
  margin: 0;
  color: var(--muted, #6f6a62);
  font-size: 0.65rem;
  line-height: 1.3;
}

.sc-chat__status.is-error {
  color: #9f3f2f;
}

.sc-chat__retry {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-top: 6px;
  padding: 0;
  border: 1px solid rgba(156, 74, 58, 0.28);
  border-radius: 999px;
  background: rgba(156, 74, 58, 0.08);
  color: #7a3a2e;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.sc-chat__retry:hover {
  background: rgba(156, 74, 58, 0.14);
  border-color: rgba(156, 74, 58, 0.4);
}

.sc-chat__retry svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

body.mobile-menu-open .sc-chat,
body.map-fullscreen-open .sc-chat {
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 960px) {
  .sc-chat {
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .sc-chat__panel {
    width: min(400px, calc(100vw - 24px));
    height: min(610px, calc(100dvh - 24px));
  }
}

@media (max-width: 560px) {
  html.sc-chat-open,
  body.sc-chat-open {
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.sc-chat-open .header,
  body.sc-chat-open .sticky-cta,
  body.sc-chat-open .menu-toggle {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .sc-chat.is-open {
    inset: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 400;
  }

  .sc-chat__panel {
    position: fixed;
    top: var(--sc-vv-top, 0px);
    left: var(--sc-vv-left, 0px);
    right: auto;
    bottom: auto;
    width: var(--sc-vv-width, 100%);
    height: var(--sc-vv-height, 100dvh);
    max-width: none;
    max-height: none;
    padding-bottom: var(--sc-vv-pad-bottom, env(safe-area-inset-bottom, 0px));
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: var(--cream, #f6f4ef);
    overflow: hidden;
    overscroll-behavior: none;
    transform: translateY(18px);
    transform-origin: center bottom;
  }

  .sc-chat.is-open .sc-chat__panel {
    transform: translateY(0);
  }

  .sc-chat__header {
    flex: 0 0 auto;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    touch-action: manipulation;
  }

  .sc-chat__messages {
    padding: 15px;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  .sc-chat__form,
  .sc-chat__footer,
  .sc-chat__composer {
    flex: 0 0 auto;
    touch-action: manipulation;
    overscroll-behavior: none;
  }

  /* 16px prevents iOS Safari auto-zoom on focus */
  .sc-chat__composer textarea {
    font-size: 16px;
    touch-action: manipulation;
  }
}

@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  html.sc-chat-open,
  body.sc-chat-open {
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.sc-chat-open .header,
  body.sc-chat-open .sticky-cta,
  body.sc-chat-open .menu-toggle {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .sc-chat.is-open {
    inset: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 400;
  }

  .sc-chat__panel {
    position: fixed;
    top: var(--sc-vv-top, 0px);
    left: var(--sc-vv-left, 0px);
    right: auto;
    bottom: auto;
    width: var(--sc-vv-width, 100%);
    height: var(--sc-vv-height, 100dvh);
    max-width: none;
    max-height: none;
    padding-bottom: var(--sc-vv-pad-bottom, env(safe-area-inset-bottom, 0px));
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: var(--cream, #f6f4ef);
    overflow: hidden;
    overscroll-behavior: none;
    transform: translateY(12px);
    transform-origin: center center;
  }

  .sc-chat.is-open .sc-chat__panel {
    transform: translateY(0);
  }

  .sc-chat__header {
    flex: 0 0 auto;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px 12px;
    touch-action: manipulation;
  }

  .sc-chat__avatar {
    width: 34px;
    height: 34px;
  }

  .sc-chat__title {
    font-size: 1.14rem;
  }

  .sc-chat__subtitle {
    margin-top: 1px;
    font-size: 0.62rem;
  }

  .sc-chat__messages {
    gap: 8px;
    padding: 10px 12px;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  .sc-chat__message {
    padding: 8px 11px;
    font-size: 0.76rem;
    line-height: 1.35;
  }

  .sc-chat__form {
    flex: 0 0 auto;
    padding: 8px 10px 14px;
    touch-action: manipulation;
    overscroll-behavior: none;
  }

  .sc-chat__composer {
    min-height: 44px;
    gap: 8px;
    padding: 4px 4px 4px 12px;
    touch-action: manipulation;
  }

  .sc-chat__composer textarea {
    min-height: 22px;
    max-height: 54px;
    padding: 6px 0;
    font-size: 16px;
    touch-action: manipulation;
  }

  .sc-chat__send {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }

  .sc-chat__footer {
    flex: 0 0 auto;
    padding: 0 10px 8px;
    touch-action: manipulation;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sc-chat__launcher,
  .sc-chat__panel,
  .sc-chat__send {
    transition: none;
  }

  .sc-chat__typing-dot {
    animation: none;
    opacity: 0.65;
  }
}
