:root {
  --tea-brown: #8B4513;
  --tea-amber: #D4A054;
  --tea-amber-light: #E8C07A;
  --tea-bg: #FFF8F0;
  --tea-bg-dark: #F5E6D3;
  --tea-text: #3D2B1F;
  --tea-text-light: #7A5C47;
  --tea-white: #FFFFFF;
  --shadow: 0 4px 24px rgba(139, 69, 19, 0.2);
  --radius: 16px;
  --radius-sm: 8px;
}

#teahouse-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--tea-text);
}

/* Toggle Button */
#teahouse-toggle-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--tea-brown), var(--tea-amber));
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

#teahouse-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 30px rgba(139, 69, 19, 0.35);
}

#teahouse-toggle-btn svg {
  width: 28px;
  height: 28px;
  fill: var(--tea-white);
  transition: opacity 0.2s;
}

#teahouse-toggle-btn .icon-close {
  display: none;
}

#teahouse-toggle-btn.open .icon-chat {
  display: none;
}

#teahouse-toggle-btn.open .icon-close {
  display: block;
}

/* Unread badge */
#teahouse-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #E53935;
  color: #fff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

#teahouse-badge.visible {
  display: flex;
}

/* Chat Window */
#teahouse-chat-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  height: 1010px;
  max-height: calc(100vh - 110px);
  background: var(--tea-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
  pointer-events: none;
}

#teahouse-chat-window.open {
  transform: scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Header */
#teahouse-header {
  background: linear-gradient(135deg, var(--tea-brown), #A0522D);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

#teahouse-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tea-amber);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

#teahouse-header-info {
  flex: 1;
}

#teahouse-header-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--tea-white);
}

#teahouse-header-status {
  font-size: 12px;
  color: var(--tea-amber-light);
  margin-top: 2px;
}

/* Messages */
#teahouse-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

#teahouse-messages::-webkit-scrollbar {
  width: 4px;
}

#teahouse-messages::-webkit-scrollbar-track {
  background: transparent;
}

#teahouse-messages::-webkit-scrollbar-thumb {
  background: var(--tea-amber);
  border-radius: 2px;
}

.th-message {
  max-width: 82%;
  animation: fadeInUp 0.2s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.th-message.bot {
  align-self: flex-start;
}

.th-message.user {
  align-self: flex-end;
}

.th-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  word-break: break-word;
}

.th-message.bot .th-bubble {
  background: var(--tea-white);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  color: var(--tea-text);
}

.th-message.user .th-bubble {
  background: linear-gradient(135deg, var(--tea-brown), #A0522D);
  border-bottom-right-radius: 4px;
  color: var(--tea-white);
}

/* Product image */
.th-product-img {
  display: block;
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 12px;
  margin: 10px auto 8px;
  background: var(--tea-bg-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.th-product-img:not([src]) {
  display: none;
}

/* Product link wrapper */
.th-product-link {
  display: block;
  text-decoration: none;
  border-radius: 12px;
  overflow: hidden;
  transition: opacity 0.2s, transform 0.2s;
}

.th-product-link:hover {
  opacity: 0.88;
  transform: scale(1.01);
}

/* Cart button inside message */
.th-cart-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  margin: 12px auto 2px;
  padding: 12px 18px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.35), rgba(255,255,255,0) 42%),
    linear-gradient(135deg, #f6c944 0%, #e8ad18 100%);
  color: #005f43;
  border: 1px solid rgba(0, 95, 67, 0.12);
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.035em;
  text-transform: uppercase;
  text-align: center;
  box-shadow:
    0 10px 22px rgba(232, 173, 24, 0.22),
    0 2px 6px rgba(0, 95, 67, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
  text-decoration: none;
}

.th-cart-btn:hover {
  transform: translateY(-1px);
  filter: saturate(1.05);
  box-shadow:
    0 14px 28px rgba(232, 173, 24, 0.28),
    0 4px 10px rgba(0, 95, 67, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.th-cart-btn:active {
  transform: translateY(0);
  box-shadow:
    0 7px 16px rgba(232, 173, 24, 0.2),
    inset 0 1px 2px rgba(0, 95, 67, 0.12);
}

.th-cart-btn:disabled {
  cursor: default;
  opacity: 0.72;
  transform: none;
  filter: grayscale(0.08);
}

/* View product button */
.th-view-btn {
  display: block;
  width: 100%;
  margin: 8px auto 0;
  padding: 10px 18px;
  background: transparent;
  color: #c8960c;
  border: 2px solid #c8960c;
  border-radius: 50px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  transition: background 0.18s, color 0.18s;
  text-decoration: none;
}

.th-view-btn:hover {
  background: #c8960c;
  color: #ffffff;
}

/* Variation picker */
.th-variation-picker {
  margin-top: 4px;
}

.th-variation-label {
  font-size: 12px;
  color: var(--tea-text-light);
  margin-bottom: 8px;
}

.th-variation-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.th-variation-btn {
  padding: 7px 14px;
  background: var(--tea-white);
  color: var(--tea-brown);
  border: 1.5px solid var(--tea-amber);
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.th-variation-btn:hover {
  background: var(--tea-amber);
  color: var(--tea-white);
}

/* Typing indicator */
.th-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--tea-white);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.th-typing span {
  width: 7px;
  height: 7px;
  background: var(--tea-amber);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.th-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.th-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-6px);
  }
}

/* Input area */
#teahouse-input-area {
  padding: 14px 14px 16px;
  background:
    linear-gradient(180deg, rgba(255, 248, 240, 0.72), rgba(245, 230, 211, 0.96));
  border-top: 1px solid rgba(139, 69, 19, 0.08);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: 0 -12px 26px rgba(61, 43, 31, 0.06);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#teahouse-input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  min-height: 48px;
  height: 48px;
  max-height: 110px;
  border: 1px solid rgba(139, 69, 19, 0.12);
  border-radius: 24px;
  padding: 13px 16px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--tea-text);
  font-size: 14px;
  outline: none;
  resize: none;
  overflow-y: auto;
  line-height: 1.45;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  font-family: inherit;
  box-sizing: border-box;
  box-shadow:
    0 10px 26px rgba(61, 43, 31, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

#teahouse-input:focus {
  border-color: rgba(212, 160, 84, 0.78);
  background: #ffffff;
  box-shadow:
    0 12px 30px rgba(61, 43, 31, 0.10),
    0 0 0 4px rgba(212, 160, 84, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

#teahouse-input::placeholder {
  color: rgba(122, 92, 71, 0.72);
}

#teahouse-send-btn {
  position: static;
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  margin: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--tea-brown), #B5682B 62%, var(--tea-amber));
  border: 1px solid rgba(255, 255, 255, 0.58);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
  box-shadow:
    0 12px 24px rgba(139, 69, 19, 0.30),
    0 3px 8px rgba(61, 43, 31, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

#teahouse-send-btn:hover {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.05);
  box-shadow:
    0 16px 30px rgba(139, 69, 19, 0.36),
    0 5px 12px rgba(61, 43, 31, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.38);
}

#teahouse-send-btn:active {
  transform: translateY(0) scale(0.98);
}

#teahouse-send-btn:disabled {
  background: linear-gradient(135deg, #d4c6ba, #b8a89a);
  cursor: not-allowed;
  transform: none;
  filter: none;
  box-shadow: 0 7px 16px rgba(61, 43, 31, 0.12);
  opacity: 0.78;
}

#teahouse-send-btn svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--tea-white);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: translateX(1px);
  filter: drop-shadow(0 2px 4px rgba(61, 43, 31, 0.28));
}

/* Mobile */
@media (max-width: 480px) {
  #teahouse-chat-window {
    width: calc(100vw - 24px);
    height: 85vh;
    bottom: 72px;
    right: -12px;
  }

  #teahouse-chat-widget {
    right: 16px;
    bottom: 16px;
  }
}
