.chat-widget {
  --chat-bottom: 1.5rem;
  --chat-right: 1.5rem;
  --chat-launcher: 58px;

  position: fixed;
  right: var(--chat-right);
  bottom: var(--chat-bottom);
  z-index: 950;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.875rem;
  font-family: var(--font-body);
}

.chat-widget[hidden],
.chat-panel[hidden],
.chat-badge[hidden],
.chat-note[hidden],
.chat-widget.is-live,
.cookie-notice:not([hidden]) ~ .chat-widget {
  display: none;
}

/* Launcher */

.chat-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--chat-launcher);
  height: var(--chat-launcher);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  box-shadow:
    0 6px 18px rgba(16, 128, 60, 0.32),
    0 2px 6px rgba(16, 24, 20, 0.12);
  cursor: pointer;
  transition:
    background 0.2s,
    transform 0.2s;
  animation: chat-in 0.35s ease-out;
}

.chat-launcher:hover {
  background: var(--color-primary-dark);
  transform: translateY(-2px);
}

.chat-launcher:focus-visible,
.chat-close:focus-visible {
  outline: 3px solid rgba(16, 128, 60, 0.35);
  outline-offset: 3px;
}

.chat-launcher-icon {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.chat-launcher-close,
.chat-widget.is-open .chat-launcher-open {
  opacity: 0;
  transform: rotate(-60deg) scale(0.6);
}

.chat-widget.is-open .chat-launcher-close {
  opacity: 1;
  transform: none;
}

.chat-launcher .chat-status-dot {
  position: absolute;
  top: 3px;
  right: 3px;
}

.chat-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 2px solid #fff;
  border-radius: 11px;
  background: var(--color-accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 18px;
}

.chat-status-dot {
  display: none;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #9aa5a0;
}

.chat-widget[data-status] .chat-status-dot {
  display: block;
}

.chat-widget[data-status="online"] .chat-status-dot {
  background: #3ddc7c;
}

.chat-widget[data-status="away"] .chat-status-dot {
  background: #f2b33d;
}

/* Panel */

.chat-panel {
  width: min(360px, calc(100vw - 2 * var(--chat-right)));
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: var(--box-shadow-lg);
  transform-origin: bottom right;
  animation: chat-panel-in 0.22s ease-out;
}

.chat-panel-head {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1.125rem 1rem 1.125rem 1.25rem;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #fff;
}

.chat-avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
}

.chat-avatar .chat-status-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  border-color: var(--color-primary-dark);
}

.chat-panel-heading {
  flex: 1;
  min-width: 0;
}

.chat-panel-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.0625rem;
  font-weight: 700;
  color: #fff;
}

.chat-panel-status {
  margin: 0.125rem 0 0;
  font-size: 0.8125rem;
  opacity: 0.88;
}

.chat-close {
  display: grid;
  place-items: center;
  align-self: flex-start;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.14);
}

.chat-panel-body {
  padding: 1.25rem;
}

.chat-panel-intro {
  margin: 0 0 1rem;
  color: var(--color-text);
  font-size: 0.9063rem;
  line-height: 1.55;
}

.chat-start {
  width: 100%;
}

.chat-start .icon {
  transition: transform 0.2s;
}

.chat-start:hover .icon {
  transform: translateX(3px);
}

.chat-start.is-loading {
  pointer-events: none;
  opacity: 0.75;
}

.chat-start.is-loading .icon {
  display: none;
}

.chat-note {
  margin: 0.625rem 0 0;
  color: var(--color-text-light);
  font-size: 0.75rem;
  line-height: 1.5;
}

.chat-note a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-note-error {
  color: var(--color-accent);
  font-weight: 500;
}

.chat-alt {
  display: grid;
  gap: 0.125rem;
  margin-top: 1.125rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.chat-alt-label {
  margin: 0 0 0.375rem;
  color: var(--color-text-light);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-alt-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 -0.5rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--color-secondary);
  font-size: 0.9375rem;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}

.chat-alt-link .icon {
  color: var(--color-primary);
}

.chat-alt-link:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

@keyframes chat-in {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}

@keyframes chat-panel-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

#ast-scroll-top.ast-scroll-to-top-right {
  right: auto;
  left: 30px;
}


@media (max-width: 768px) {
  .chat-widget {
    --chat-right: 1rem;
    --chat-bottom: calc(64px + env(safe-area-inset-bottom) + 0.75rem);
    --chat-launcher: 52px;
  }

  body.woocommerce-cart .chat-widget,
  body.woocommerce-checkout .chat-widget {
    display: none;
  }
  #ast-scroll-top.ast-scroll-to-top-right {
    left: 1rem;
    bottom: calc(64px + env(safe-area-inset-bottom) + 0.75rem);
  }

}

@media (prefers-reduced-motion: reduce) {
  .chat-widget *,
  .chat-launcher {
    animation: none !important;
    transition: none !important;
  }
}
