/* Storefront support chat: floating launcher plus the conversation panel it
   opens. Surfaces and radii follow the cart dialog in components.css so the
   widget reads as part of the same storefront, not a bolted-on plugin. */

.site-chat {
  position: fixed;
  inset-block-end: 32px;
  inset-inline-end: 36px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  pointer-events: none;
}

.site-chat > * {
  pointer-events: auto;
}

/* --- launcher --- */

.site-chat__launcher {
  position: relative;
  display: grid;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 2px solid var(--site-accent);
  /* Rounded square, same radius-to-size ratio as the send button, so the
     launcher belongs to the squared panel rather than floating as a circle. */
  border-radius: 16px;
  /* Centred under the send button: its centre sits 1px border + 14px form
     padding + 22px half-width = 37px in from the panel edge, ours at 28px.
     On phones 1 + 12 + 22 = 35 against 26 - the same 9px. */
  margin-inline-end: 9px;
  background: #0f1216;
  color: var(--site-accent);
  cursor: pointer;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .32);
  transition: border-color 280ms var(--site-ease), background-color 280ms var(--site-ease), color 280ms var(--site-ease), transform 140ms var(--site-ease), box-shadow 280ms var(--site-ease);
  place-items: center;
}

.site-chat__launcher:hover {
  border-color: var(--site-accent-hover);
  background: var(--site-surface);
  color: var(--site-accent-hover);
  box-shadow: 0 16px 38px rgba(0, 0, 0, .38);
}

.site-chat__launcher:active {
  transform: scale(.96);
}

.site-chat__launcher svg {
  grid-area: 1 / 1;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 220ms var(--site-ease), transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* One button, two glyphs: the close cross fades in over the speech bubble
   while the panel is open, so the control never jumps or changes size. */
.site-chat__launcher-close {
  opacity: 0;
  transform: rotate(-90deg) scale(.6);
}

.site-chat__launcher.is-open .site-chat__launcher-icon {
  opacity: 0;
  transform: rotate(90deg) scale(.6);
}

/* Open state: a solid "minimise" control that reads as part of the panel
   above it, not a second copy of the header's close button. */
.site-chat__launcher.is-open {
  border-color: var(--site-accent);
  background: var(--site-accent);
  color: var(--site-accent-contrast);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .3);
}

.site-chat__launcher.is-open:hover {
  border-color: var(--site-accent-hover);
  background: var(--site-accent-hover);
  color: var(--site-accent-contrast);
}

.site-chat__launcher.is-open .site-chat__launcher-close {
  opacity: 1;
  transform: rotate(0deg);
}

.site-chat__launcher .site-chat__launcher-icon {
  width: 26px;
  height: 26px;
}

.site-chat__launcher-count {
  position: absolute;
  inset-block-start: -6px;
  inset-inline-end: -6px;
  display: grid;
  min-width: 23px;
  height: 23px;
  padding-inline: 5px;
  border: 2px solid #0f1216;
  border-radius: 999px;
  background: #ff3b3f;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  opacity: 0;
  transform: scale(.78);
  transition: opacity 140ms var(--site-ease), transform 140ms var(--site-ease);
  pointer-events: none;
  place-items: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .28);
}

.site-chat__launcher.is-unread:not(.is-open) .site-chat__launcher-icon {
  opacity: 1;
  transform: none;
}

.site-chat__launcher.is-unread:not(.is-open) .site-chat__launcher-count {
  opacity: 1;
  transform: scale(1);
}

/* --- panel --- */

.site-chat__panel {
  display: flex;
  width: min(392px, calc(100vw - 72px));
  height: min(560px, calc(100dvh - 168px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--site-border-strong);
  border-radius: var(--site-radius-lg);
  background: #0f1216;
  box-shadow: 0 26px 70px rgba(0, 0, 0, .48);
}

.site-chat__panel[hidden] {
  display: none;
}

/* Grows out of the launcher corner on open and shrinks back on close. */
.site-chat__panel:not([hidden]) {
  transform-origin: right bottom;
  animation: site-chat-panel-in 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.site-chat__panel.is-closing {
  pointer-events: none;
  animation: site-chat-panel-out 240ms cubic-bezier(0.4, 0, 1, 1) both;
}

@keyframes site-chat-panel-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(.9);
  }
}

@keyframes site-chat-panel-out {
  to {
    opacity: 0;
    transform: translateY(18px) scale(.94);
  }
}

.site-chat__header {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px 12px 18px;
  border-block-end: 1px solid var(--site-border);
}

.site-chat__title {
  display: grid;
  gap: 3px;
}

.site-chat__title strong {
  font-size: 16px;
  font-weight: 750;
}

.site-chat__title span {
  color: var(--site-text-muted);
  font-size: 12px;
}

.site-chat__close {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--site-border);
  border-radius: 10px;
  background: transparent;
  color: var(--site-text-muted);
  cursor: pointer;
  transition: border-color 120ms var(--site-ease), background-color 120ms var(--site-ease), color 120ms var(--site-ease);
  place-items: center;
}

.site-chat__close:hover {
  border-color: var(--site-border-strong);
  background: var(--site-surface-raised);
  color: var(--site-text);
}

.site-chat__close svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* --- messages --- */

.site-chat__list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 18px 14px;
}

/* Empty conversation: a greeting card plus quick-reply chips, so the first
   message is one tap away instead of a blank panel. */
.site-chat__empty {
  display: grid;
  gap: 10px;
  margin-block-end: auto;
  transform-origin: left bottom;
  animation: site-chat-greeting 260ms cubic-bezier(0.2, 0, 0, 1) 450ms both;
}

.site-chat__greeting {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--site-border-strong);
  border-radius: 13px;
  background: var(--site-surface-raised);
}

.site-chat__greeting-wave {
  flex: 0 0 auto;
  font-size: 26px;
  line-height: 1.1;
}

.site-chat__greeting strong {
  display: block;
  margin-block-end: 4px;
  font-size: 15px;
  font-weight: 750;
}

.site-chat__greeting p {
  margin: 0;
  color: var(--site-text-muted);
  font-size: 13px;
  line-height: 1.45;
  text-wrap: pretty;
}

.site-chat__templates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  /* Equal rows: a label that wraps on a narrow phone must not make its
     tile taller than its neighbours. */
  grid-auto-rows: 1fr;
  gap: 8px;
}

.site-chat__template {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border: 1px solid var(--site-border);
  border-radius: 12px;
  background: var(--site-surface);
  color: var(--site-text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  text-align: start;
  cursor: pointer;
  transition: border-color 120ms var(--site-ease), background-color 120ms var(--site-ease);
}

.site-chat__template:hover {
  border-color: var(--site-accent);
  background: var(--site-surface-raised);
}

.site-chat__template:focus-visible {
  outline: 2px solid var(--site-accent);
  outline-offset: 2px;
}

.site-chat__template svg {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  fill: none;
  stroke: var(--site-accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes site-chat-greeting {
  from {
    opacity: 0;
    transform: translateY(8px) scale(.94);
  }
}

.site-chat__message {
  display: grid;
  max-width: 80%;
  gap: 5px;
  padding: 10px 12px;
  border-radius: 13px;
}

/* New messages rise in from their own side; history renders still. */
.site-chat__message.is-entering {
  animation: site-chat-message-in 360ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.site-chat__message--client.is-entering {
  transform-origin: right bottom;
}

.site-chat__message--staff.is-entering {
  transform-origin: left bottom;
}

.site-chat__message.is-delayed {
  animation-delay: 450ms;
}

@keyframes site-chat-message-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(.92);
  }
}

.site-chat__message--client {
  align-self: flex-end;
  border-end-end-radius: 5px;
  background: var(--site-accent);
  color: var(--site-accent-contrast);
}

.site-chat__message--staff {
  align-self: flex-start;
  border-end-start-radius: 5px;
  border: 1px solid var(--site-border-strong);
  background: var(--site-surface-raised);
  color: var(--site-text);
}

.site-chat__text {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  /* Visitors paste part numbers and long model names; breaking them is far
     better than letting one token widen the whole bubble. */
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.site-chat__message.has-photo {
  padding: 4px 4px 8px;
}

.site-chat__message.has-photo .site-chat__text,
.site-chat__message.has-photo /* Canned answer: calm text plus one clear action to the info page. */
.site-chat__message--auto {
  gap: 10px;
  max-width: 88%;
}

.site-chat__message--auto .site-chat__text {
  color: var(--site-text-muted);
  font-size: 13px;
}

.site-chat__message .site-chat__auto-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 8px 10px 8px 12px;
  border: 1px solid var(--site-border-strong);
  border-radius: 10px;
  background: var(--site-surface);
  color: var(--site-text);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  transition: border-color 120ms var(--site-ease), background-color 120ms var(--site-ease);
}

.site-chat__message .site-chat__auto-link:hover {
  border-color: var(--site-accent);
  background: #0f1216;
}

.site-chat__message .site-chat__auto-link:focus-visible {
  outline: 2px solid var(--site-accent);
  outline-offset: 2px;
}

.site-chat__auto-link span {
  flex: 1;
}

.site-chat__auto-link svg {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  fill: none;
  stroke: var(--site-accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.site-chat__auto-link .site-chat__auto-link-arrow {
  stroke: var(--site-text-muted);
  transition: transform 120ms var(--site-ease), stroke 120ms var(--site-ease);
}

.site-chat__auto-link:hover .site-chat__auto-link-arrow {
  stroke: var(--site-accent);
  transform: translateX(2px);
}

.site-chat__meta {
  padding-inline: 8px;
}

.site-chat__photo {
  display: block;
  overflow: hidden;
  border-radius: 10px;
}

.site-chat__photo img {
  display: block;
  width: 100%;
  max-width: 240px;
  max-height: 260px;
  object-fit: cover;
}

.site-chat__photo:focus-visible {
  outline: 2px solid var(--site-accent);
  outline-offset: 2px;
}

.site-chat__meta {
  font-size: 11px;
  line-height: 1.2;
  opacity: .72;
}

.site-chat__status {
  margin: 0;
  padding: 0 16px 8px;
  color: var(--site-text-muted);
  font-size: 12px;
}

.site-chat__status.is-error {
  color: var(--site-danger);
}

/* --- composer --- */

.site-chat__form {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px 14px;
  border-block-start: 1px solid var(--site-border);
  background: #0f1216;
}

.site-chat__field {
  position: relative;
  display: flex;
  min-width: 0;
  flex: 1;
}

.site-chat__input {
  min-height: 44px;
  max-height: 120px;
  flex: 1;
  padding: 11px 42px 11px 13px;
  border: 1px solid var(--site-border-strong);
  border-radius: 11px;
  outline: 0;
  background: var(--site-surface);
  color: var(--site-text);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  transition: border-color 120ms var(--site-ease), background-color 120ms var(--site-ease), box-shadow 120ms var(--site-ease);
}

.site-chat__input:focus-visible {
  border-color: var(--site-accent);
  background: var(--site-surface-raised);
  box-shadow: 0 0 0 2px rgba(139, 200, 80, .14);
}

.site-chat__input::placeholder {
  color: var(--site-text-subtle);
}

.site-chat__attach {
  display: grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--site-border-strong);
  border-radius: 11px;
  background: var(--site-surface);
  color: var(--site-text-muted);
  cursor: pointer;
  transition: border-color 120ms var(--site-ease), background-color 120ms var(--site-ease), color 120ms var(--site-ease);
  place-items: center;
}

.site-chat__attach:hover {
  border-color: var(--site-accent);
  background: var(--site-surface-raised);
  color: var(--site-accent);
}

.site-chat__attach:focus-visible {
  outline: 2px solid var(--site-accent);
  outline-offset: 2px;
}

.site-chat__attach svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.site-chat__form.is-sending .site-chat__attach {
  pointer-events: none;
  opacity: .6;
}

.site-chat__emoji-toggle {
  position: absolute;
  inset-block-end: 6px;
  inset-inline-end: 6px;
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--site-text-muted);
  cursor: pointer;
  transition: color 120ms var(--site-ease), background-color 120ms var(--site-ease);
  place-items: center;
}

.site-chat__emoji-toggle:hover,
.site-chat__emoji-toggle.is-active {
  background: var(--site-surface-raised);
  color: var(--site-accent);
}

.site-chat__emoji-toggle:focus-visible {
  outline: 2px solid var(--site-accent);
  outline-offset: 1px;
}

.site-chat__emoji-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.site-chat__emoji {
  position: absolute;
  inset-block-end: calc(100% + 6px);
  inset-inline: 14px;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--site-border-strong);
  border-radius: 13px;
  background: var(--site-surface-raised);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .32);
}

.site-chat__emoji[hidden] {
  display: none;
}

.site-chat__emoji-item {
  display: grid;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  place-items: center;
}

.site-chat__emoji-item:hover {
  background: var(--site-surface);
}

.site-chat__emoji-item:focus-visible {
  outline: 2px solid var(--site-accent);
  outline-offset: -2px;
}

.site-chat__send {
  display: grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 11px;
  place-items: center;
}

.site-chat__send svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.site-chat__form.is-sending .site-chat__send {
  pointer-events: none;
  opacity: .6;
}

@media (max-width: 900px) {
  .site-chat {
    inset-block-end: 24px;
    inset-inline-end: 24px;
  }

  .site-chat__panel {
    width: min(380px, calc(100vw - 48px));
  }
}

@media (max-width: 620px) {
  .site-chat {
    inset-block-end: max(18px, env(safe-area-inset-bottom));
    inset-inline-end: 18px;
    gap: 12px;
  }

  .site-chat__panel {
    width: calc(100vw - 36px);
    height: min(68dvh, calc(100dvh - 112px));
    border-radius: 16px;
  }

  .site-chat__header {
    min-height: 60px;
    padding: 10px 12px 10px 16px;
  }

  .site-chat__list {
    padding: 16px 14px 12px;
  }

  .site-chat__message {
    max-width: 84%;
  }

  .site-chat__form {
    padding: 10px 12px 12px;
  }

  .site-chat__launcher {
    width: 52px;
    height: 52px;
  }

  .site-chat__launcher-count {
    inset-block-start: -5px;
    inset-inline-end: -5px;
    min-width: 22px;
    height: 22px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-chat__launcher,
  .site-chat__launcher svg {
    transition: none;
  }

  .site-chat__empty,
  .site-chat__panel:not([hidden]),
  .site-chat__panel.is-closing,
  .site-chat__message.is-entering {
    animation: none;
  }

}
