/* Chat Widget — Kim Phụng Spa */
@keyframes spa-chat-attention {
  0%,
  100% {
    transform: translateY(0) scale(1);
    box-shadow:
      0 10px 24px rgba(60, 35, 15, 0.28),
      0 0 0 0 rgba(201, 162, 39, 0.5);
  }
  50% {
    transform: translateY(-4px) scale(1.05);
    box-shadow:
      0 14px 30px rgba(60, 35, 15, 0.34),
      0 0 0 10px rgba(201, 162, 39, 0);
  }
}

.spa-chat-toggle {
  position: fixed;
  right: 1.25rem;
  bottom: 2rem;
  z-index: 1200;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.9rem 1.15rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #8b5a2b 0%, #c9a227 100%);
  color: #fff;
  font-family: var(--font-body, "Plus Jakarta Sans", sans-serif);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 12px 28px rgba(60, 35, 15, 0.28);
  cursor: pointer;
  animation: spa-chat-attention 2.4s ease-in-out infinite;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, visibility 0.2s;
}

.spa-chat-toggle:hover {
  animation: none;
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 16px 32px rgba(60, 35, 15, 0.38);
}

.spa-chat-toggle:active {
  transform: translateY(-1px) scale(1.02);
}

.spa-chat-toggle[aria-expanded="true"] {
  animation: none;
}

.spa-chat-toggle i {
  font-size: 1.15rem;
}

@media (prefers-reduced-motion: reduce) {
  .spa-chat-toggle {
    animation: none;
  }

  .spa-chat-avatar--pulse {
    animation: none;
  }

  .spa-chat-dots span {
    animation: none;
  }
}

.spa-chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 6.25rem;
  z-index: 1201;
  width: min(380px, calc(100vw - 2rem));
  height: min(520px, calc(100vh - 11rem));
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  background: #fffdf9;
  border: 1px solid rgba(139, 90, 43, 0.18);
  box-shadow: 0 24px 48px rgba(35, 22, 10, 0.22);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
  overflow: hidden;
}

.spa-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.spa-chat-header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "main close";
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  padding-top: max(0.9rem, env(safe-area-inset-top, 0px));
  flex-shrink: 0;
  background: linear-gradient(135deg, #6d4522 0%, #a67c3d 100%);
  color: #fff;
}

.spa-chat-header__main {
  grid-area: main;
  min-width: 0;
  text-align: left;
}

.spa-chat-header-btn {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
}

.spa-chat-expand {
  grid-area: expand;
  display: none;
}

.spa-chat-close {
  grid-area: close;
  display: inline-flex;
}

.spa-chat-expand:hover,
.spa-chat-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.spa-chat-expand i {
  font-size: 0.95rem;
}

.spa-chat-header h4 {
  margin: 0;
  font-family: var(--font-display, "Playfair Display", serif);
  font-size: 1.05rem;
  font-weight: 600;
}

.spa-chat-header p {
  margin: 0.15rem 0 0;
  font-size: 0.72rem;
  color: #fff;
  opacity: 1;
}

.spa-chat-header-phone {
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.spa-chat-header-phone:hover {
  text-decoration: underline;
}

.spa-chat-close {
  font-size: 1.35rem;
  line-height: 1;
}

/* Desktop: mở rộng chat full trang */
@media (min-width: 769px) {
  .spa-chat-header {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "expand main close";
  }

  .spa-chat-header__main {
    text-align: center;
  }

  .spa-chat-expand:not([hidden]) {
    display: inline-flex;
  }

  html.spa-chat-expanded,
  body.spa-chat-expanded {
    overflow: hidden;
  }

  body.spa-chat-expanded .spa-chat-toggle {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .spa-chat-panel.is-open.is-expanded {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
    z-index: 2500;
    transform: none;
  }

  .spa-chat-panel.is-open.is-expanded .spa-chat-inner {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
    box-sizing: border-box;
  }
}

.spa-chat-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

.spa-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: #faf6f0;
  -webkit-overflow-scrolling: touch;
}

.spa-chat-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 100%;
}

.spa-chat-row--user {
  justify-content: flex-end;
}

.spa-chat-row--assistant {
  justify-content: flex-start;
}

.spa-chat-avatar {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  overflow: hidden;
  background: transparent;
}

.spa-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.spa-chat-avatar--pulse img {
  animation: spa-chat-logo-pulse 1.6s ease-in-out infinite;
}

@keyframes spa-chat-logo-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.spa-chat-bubble {
  max-width: calc(100% - 3.25rem);
  padding: 0.75rem 0.95rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}

.spa-chat-bubble--assistant {
  background: #fff;
  border: 1px solid rgba(139, 90, 43, 0.12);
  color: #3d2a1a;
  box-shadow: 0 2px 8px rgba(47, 35, 29, 0.06);
}

.spa-chat-bubble--loading {
  padding: 0.85rem 1.1rem;
}

.spa-chat-dots {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}

.spa-chat-dots span {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #a67c3d;
  animation: spa-chat-dot-bounce 1s ease-in-out infinite;
}

.spa-chat-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.spa-chat-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes spa-chat-dot-bounce {
  0%,
  80%,
  100% {
    transform: scale(0.65);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.spa-chat-bubble--user {
  background: linear-gradient(135deg, #8b5a2b 0%, #9a6b38 100%);
  color: #fff;
  white-space: pre-wrap;
}

.spa-chat-bubble__body {
  font-size: 0.9rem;
  line-height: 1.55;
}

/* Gõ chữ thuần — giữ xuống dòng; markdown render 1 lần khi xong */
.spa-chat-bubble__body--revealing {
  white-space: pre-wrap;
}

.spa-chat-bubble__body p {
  margin: 0 0 0.5rem;
  color: inherit;
}

.spa-chat-bubble__body p:last-child {
  margin-bottom: 0;
}

.spa-chat-bubble__body ul {
  margin: 0.35rem 0 0.5rem;
  padding-left: 1.15rem;
}

.spa-chat-bubble__body li {
  margin-bottom: 0.35rem;
}

.spa-chat-bubble__body li:last-child {
  margin-bottom: 0;
}

.spa-chat-bubble__body strong {
  font-weight: 700;
  color: #5c3d1e;
}

.spa-chat-bubble__body em {
  font-style: italic;
}

.spa-chat-bubble__body code {
  font-family: ui-monospace, monospace;
  font-size: 0.85em;
  background: rgba(139, 90, 43, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.spa-chat-bubble__body a {
  color: #8b5a2b;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.spa-chat-typing {
  opacity: 0.75;
  font-style: italic;
}

.spa-chat-footer {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(139, 90, 43, 0.12);
  background: #fffdf9;
  flex-shrink: 0;
}

.spa-chat-footer__row {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem 0.35rem;
  align-items: center;
}

.spa-chat-quick {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.4rem;
  padding: 0.4rem 0.65rem 0.25rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  mask-image: linear-gradient(90deg, #000 92%, transparent);
  -webkit-mask-image: linear-gradient(90deg, #000 92%, transparent);
}

.spa-chat-quick::-webkit-scrollbar {
  display: none;
}

.spa-chat-quick button {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid rgba(139, 90, 43, 0.2);
  background: #fff;
  color: #6d4522;
  border-radius: 999px;
  padding: 0.28rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  flex: 0 0 auto;
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.spa-chat-quick button i {
  font-size: 0.68rem;
  opacity: 0.85;
}

.spa-chat-quick button:hover {
  background: #faf3e8;
  border-color: rgba(166, 124, 61, 0.45);
}

.spa-chat-quick button:first-child {
  background: linear-gradient(135deg, rgba(139, 90, 43, 0.12), rgba(201, 162, 39, 0.15));
  border-color: rgba(139, 90, 43, 0.35);
}

.spa-chat-contact-card {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 3.25rem);
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: #fff;
  border: 1px solid rgba(139, 90, 43, 0.18);
  box-shadow: 0 2px 10px rgba(47, 35, 29, 0.08);
}

.spa-chat-contact-card__lead {
  margin: 0 0 0.65rem;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #3d2a1a;
}

.spa-chat-contact-card__actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.spa-chat-contact-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.spa-chat-contact-btn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.spa-chat-contact-btn--call {
  background: linear-gradient(135deg, #8b5a2b, #a67c3d);
}

.spa-chat-contact-btn--fb {
  background: #1877f2;
}

.spa-chat-contact-btn--map {
  background: #2d6a4f;
}

.spa-chat-booking {
  flex-shrink: 0;
  padding: 0.65rem 0.85rem;
  background: #fff;
  border-top: 1px solid rgba(139, 90, 43, 0.12);
}

.spa-chat-booking__label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: #5c4030;
  margin-bottom: 0.35rem;
}

.spa-chat-booking__field {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(139, 90, 43, 0.28);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  font-family: inherit;
  margin-bottom: 0.5rem;
  background: #fffdf9;
  color: #3d2a1a;
}

.spa-chat-booking__field:focus {
  outline: none;
  border-color: #a67c3d;
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.2);
}

.spa-chat-booking__field--area {
  resize: vertical;
  min-height: 2.5rem;
}

.spa-chat-booking__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.spa-chat-booking__btn {
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.spa-chat-booking__btn--primary {
  background: linear-gradient(135deg, #8b5a2b, #c9a227);
  color: #fff;
}

.spa-chat-booking__btn--ghost {
  background: transparent;
  color: #8b5a2b;
  border: 1px solid rgba(139, 90, 43, 0.35);
}

.spa-chat-footer--disabled {
  opacity: 0.45;
  pointer-events: none;
}

.spa-chat-image-preview {
  padding: 0.5rem 0.75rem 0;
  flex-shrink: 0;
}

.spa-chat-image-preview__inner {
  position: relative;
  display: inline-block;
}

.spa-chat-image-preview__inner img {
  max-height: 72px;
  max-width: 120px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid rgba(139, 90, 43, 0.2);
}

.spa-chat-image-preview__remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 1.35rem;
  height: 1.35rem;
  border: none;
  border-radius: 50%;
  background: #8b5a2b;
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.spa-chat-photo-offer {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 3.25rem);
}

.spa-chat-photo-offer__btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.9rem;
  border: 1px dashed rgba(139, 90, 43, 0.45);
  border-radius: 12px;
  background: #fff;
  color: #6d4522;
  font-size: 0.84rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.spa-chat-photo-offer__btn:hover {
  background: #faf3e8;
  border-color: #a67c3d;
}

.spa-chat-photo-offer__btn i {
  color: #a67c3d;
}

.spa-chat-bubble__img {
  display: block;
  max-width: 100%;
  max-height: 160px;
  border-radius: 10px;
  margin-bottom: 0.35rem;
}

.spa-chat-footer input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(139, 90, 43, 0.25);
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  background: #fff;
  color: #3d2a1a;
}

.spa-chat-footer input:focus {
  border-color: #a67c3d;
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.2);
}

.spa-chat-send {
  border: none;
  border-radius: 50%;
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
  background: #8b5a2b;
  color: #fff;
  cursor: pointer;
}

.spa-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mobile: full-screen chat */
@media (max-width: 768px) {
  html.spa-chat-open,
  body.spa-chat-open {
    overflow: hidden;
    height: 100%;
  }

  body.spa-chat-open {
    position: fixed;
    width: 100%;
    inset: 0;
  }

  body.spa-chat-open .spa-chat-toggle {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  body.spa-chat-open .mobile-floating-actions {
    display: none !important;
  }

  .spa-chat-toggle {
    bottom: calc(3.65rem + env(safe-area-inset-bottom, 0px));
    right: 1rem;
    width: 3.75rem;
    height: 3.75rem;
    padding: 0;
    border-radius: 50%;
  }

  .spa-chat-toggle span {
    display: none;
  }

  .spa-chat-toggle i {
    font-size: 1.45rem;
  }

  .spa-chat-panel {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
    z-index: 2500;
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease, visibility 0.2s;
  }

  .spa-chat-panel.is-open {
    transform: translateY(0);
  }

  .spa-chat-header {
    padding: 0.85rem 1rem;
    padding-top: max(0.85rem, env(safe-area-inset-top, 0px));
    grid-template-columns: 1fr auto;
    grid-template-areas: "main close";
  }

  .spa-chat-header__main {
    text-align: left;
  }

  .spa-chat-header h4 {
    font-size: 1.1rem;
  }

  .spa-chat-messages {
    padding: 1rem 0.85rem;
  }

  .spa-chat-bubble {
    max-width: 92%;
    font-size: 0.95rem;
  }

  .spa-chat-bubble__body {
    font-size: 0.95rem;
  }

  .spa-chat-footer input {
    font-size: 16px;
    padding: 0.7rem 1rem;
  }

  .spa-chat-quick {
    padding: 0.35rem 0.75rem 0.2rem;
  }

  .spa-chat-quick button {
    padding: 0.32rem 0.65rem;
    font-size: 0.74rem;
  }

  .spa-chat-footer__row {
    padding: 0.45rem 0.75rem 0.35rem;
  }
}

.spa-chat-product-figure {
  margin: 0.65rem 0 0.35rem;
  text-align: center;
}

.spa-chat-product-thumb {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: zoom-in;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
}

.spa-chat-product-thumb:focus-visible {
  outline: 2px solid var(--color-gold, #c9a227);
  outline-offset: 2px;
}

.spa-chat-product-img {
  display: block;
  max-width: 100%;
  width: min(240px, 100%);
  height: auto;
  margin: 0 auto;
  border-radius: 12px;
  border: 1px solid rgba(47, 35, 29, 0.1);
  background: #fff;
  object-fit: contain;
  transition: transform 0.2s ease;
}

.spa-chat-product-thumb:hover .spa-chat-product-img {
  transform: scale(1.02);
}

.spa-chat-product-thumb__overlay {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(35, 22, 10, 0.72);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  pointer-events: none;
}

.spa-chat-product-figure figcaption {
  font-size: 0.72rem;
  color: var(--color-text-muted, #6e5c53);
  margin-top: 0.35rem;
}

/* Lightbox gallery — xem ảnh SP trong chat */
.spa-chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  background: rgba(20, 12, 8, 0.88);
  backdrop-filter: blur(6px);
}

.spa-chat-lightbox[hidden] {
  display: none !important;
}

body.spa-chat-lightbox-open {
  overflow: hidden;
}

.spa-chat-lightbox__stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: min(520px, 100%);
  min-height: 0;
}

.spa-chat-lightbox__img {
  max-width: 100%;
  max-height: min(62vh, 480px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
}

.spa-chat-lightbox__caption {
  margin: 0.5rem 0 0;
  color: #f5ebe0;
  font-size: 0.85rem;
  text-align: center;
}

.spa-chat-lightbox__close {
  position: absolute;
  top: max(0.75rem, env(safe-area-inset-top));
  right: 0.75rem;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.spa-chat-lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  cursor: pointer;
}

.spa-chat-lightbox__nav--prev {
  left: 0.5rem;
}

.spa-chat-lightbox__nav--next {
  right: 0.5rem;
}

.spa-chat-lightbox__thumbs {
  display: flex;
  gap: 0.5rem;
  max-width: 100%;
  overflow-x: auto;
  padding: 0.25rem 0;
}

.spa-chat-lightbox__thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
}

.spa-chat-lightbox__thumb.is-active {
  border-color: var(--color-gold, #c9a227);
}

.spa-chat-lightbox__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
