/* ERSAG AI Chat Assistant Widget */
:root {
  --ersag-chat-primary: #008855;
  --ersag-chat-primary-dark: #006b43;
  --ersag-chat-primary-light: #e6f5ee;
  --ersag-chat-bg: #f8faf9;
  --ersag-chat-text: #1e293b;
  --ersag-chat-text-muted: #64748b;
  --ersag-chat-radius: 20px;
}

/* Floating Launcher Button */
.ersag-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 12px;
  background: linear-gradient(135deg, #008855 0%, #006640 100%);
  color: #ffffff;
  border: none;
  border-radius: 50px;
  box-shadow: 0 8px 24px rgba(0, 136, 85, 0.35), 0 2px 6px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.ersag-chat-launcher:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 28px rgba(0, 136, 85, 0.45), 0 4px 10px rgba(0, 0, 0, 0.15);
}

.ersag-chat-launcher--hidden {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: translateY(16px) scale(0.9) !important;
}

.ersag-chat-window--open ~ .ersag-chat-launcher,
body:has(.ersag-chat-window--open) .ersag-chat-launcher {
  display: none !important;
}

.ersag-chat-launcher__avatar {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #008855;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.ersag-chat-launcher__pulse {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  background: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.ersag-chat-launcher__pulse::after {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  opacity: 0.6;
  animation: ersagPulse 2s infinite;
}

@keyframes ersagPulse {
  0% { transform: scale(1); opacity: 0.6; }
  70% { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}

.ersag-chat-launcher__text {
  display: flex;
  flex-direction: column;
  text-align: left;
  line-height: 1.2;
}

.ersag-chat-launcher__title {
  font-size: 13.5px;
  font-weight: 700;
}

.ersag-chat-launcher__sub {
  font-size: 11px;
  opacity: 0.88;
  font-weight: 400;
}

/* Chat Window Modal */
.ersag-chat-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9995;
  width: 385px;
  height: 590px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 105px);
  background: #ffffff;
  border-radius: var(--ersag-chat-radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.16), 0 4px 16px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 136, 85, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.96);
  transform-origin: bottom right;
  transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: inherit;
}

.ersag-chat-window--open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.ersag-chat-header {
  background: linear-gradient(135deg, #008855 0%, #006640 100%);
  color: #ffffff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ersag-chat-header__info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ersag-chat-header__avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}

.ersag-chat-header__status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.ersag-chat-header__name {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.2;
}

.ersag-chat-header__badge {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 4px;
}

.ersag-chat-header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ersag-chat-header__btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.ersag-chat-header__btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Body / Messages Stream */
.ersag-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--ersag-chat-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ersag-chat-body::-webkit-scrollbar {
  width: 5px;
}

.ersag-chat-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 10px;
}

/* Message Rows */
.ersag-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: ersagFadeIn 0.22s ease-out;
}

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

.ersag-chat-msg--assistant {
  align-self: flex-start;
}

.ersag-chat-msg--assistant.ersag-chat-msg--has-card,
.ersag-chat-msg--assistant:has(.ersag-chat-inline-product) {
  max-width: 96%;
  width: 96%;
}

.ersag-chat-msg--assistant.ersag-chat-msg--has-card .ersag-chat-msg__bubble,
.ersag-chat-msg--assistant:has(.ersag-chat-inline-product) .ersag-chat-msg__bubble {
  width: 100%;
  box-sizing: border-box;
}

.ersag-chat-msg--user {
  align-self: flex-end;
}

.ersag-chat-msg__bubble {
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.48;
  word-break: break-word;
}

.ersag-chat-msg--assistant .ersag-chat-msg__bubble {
  background: #ffffff;
  color: var(--ersag-chat-text);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ersag-chat-msg--user .ersag-chat-msg__bubble {
  background: linear-gradient(135deg, #008855 0%, #00774a 100%);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 136, 85, 0.2);
}

.ersag-chat-msg__time {
  font-size: 10.5px;
  color: var(--ersag-chat-text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.ersag-chat-msg--user .ersag-chat-msg__time {
  text-align: right;
}

/* Quick Suggestion Chips */
.ersag-chat-chips {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
  margin-bottom: 4px;
}

.ersag-chat-chip {
  align-self: flex-start;
  padding: 8px 12px;
  background: #ffffff;
  color: #00774a;
  border: 1px solid rgba(0, 136, 85, 0.25);
  border-radius: 16px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: left;
  line-height: 1.3;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.ersag-chat-chip:hover {
  background: #e6f5ee;
  border-color: #008855;
  transform: translateX(3px);
}

/* Thinking Indicator */
.ersag-chat-thinking {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  padding: 10px 14px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.ersag-chat-thinking__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ersag-chat-text-muted);
}

.ersag-chat-thinking__dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ersag-chat-thinking__dot {
  width: 6px;
  height: 6px;
  background: #008855;
  border-radius: 50%;
  animation: ersagBounce 1.4s infinite ease-in-out both;
}

.ersag-chat-thinking__dot:nth-child(1) { animation-delay: -0.32s; }
.ersag-chat-thinking__dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes ersagBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Product Cards in Chat */
/* Inline Product Card embedded directly in message speech */
.ersag-chat-inline-product {
  display: block;
  margin: 6px 0;
  clear: both;
}

.ersag-chat-inline-product .ersag-chat-product-card,
.ersag-chat-products .ersag-chat-product-card {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.ersag-chat-products {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.ersag-chat-product-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background: #ffffff;
  border: 1.5px solid rgba(0, 136, 85, 0.22);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s ease;
  box-sizing: border-box;
  width: 100%;
}

.ersag-chat-product-card:hover {
  background: #fbfdfc;
  border-color: #008855;
  box-shadow: 0 3px 10px rgba(0, 136, 85, 0.1);
}

.ersag-chat-product-card__header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.ersag-chat-product-card__thumb-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 66px;
  min-width: 66px;
  height: 80px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  padding: 3px;
  box-sizing: border-box;
  flex-shrink: 0;
  overflow: hidden;
  text-decoration: none;
}

.ersag-chat-product-card__thumb {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  transition: transform 0.2s ease;
}

.ersag-chat-product-card:hover .ersag-chat-product-card__thumb {
  transform: scale(1.04);
}

.ersag-chat-product-card__info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  box-sizing: border-box;
}

.ersag-chat-product-card__title {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
  text-decoration: none;
  line-height: 1.25;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: normal;
  transition: color 0.15s ease;
}

.ersag-chat-product-card__title:hover {
  color: #008855;
}

.ersag-chat-product-card__prices {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-wrap: wrap;
  margin: 0;
}

.ersag-chat-product-card__club-price {
  font-size: 14px;
  font-weight: 700;
  color: #008855;
  white-space: nowrap;
  flex-shrink: 0;
  word-break: keep-all;
  line-height: 1.2;
}

.ersag-chat-product-card__old-price {
  font-size: 11.5px;
  color: #94a3b8;
  text-decoration: line-through;
  white-space: nowrap;
  flex-shrink: 0;
  word-break: keep-all;
  line-height: 1.2;
}

.ersag-chat-product-card__points {
  font-size: 10.5px;
  color: #00774a;
  background: #e6f6ee;
  padding: 1.5px 6px;
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  word-break: keep-all;
  line-height: 1.2;
}

.ersag-chat-product-card__actions {
  display: flex;
  align-items: stretch;
  gap: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  padding-top: 6px;
  margin-top: 0;
  width: 100%;
  box-sizing: border-box;
}

.ersag-chat-product-card__btn-view {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 34px;
  font-size: 12px;
  font-weight: 500;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  text-decoration: none;
  padding: 0 8px;
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  transition: all 0.15s ease;
  white-space: nowrap;
  line-height: normal;
}

.ersag-chat-product-card__btn-view:hover {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #94a3b8;
}

.ersag-chat-product-card__btn-cart {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 34px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  background: #008855;
  border: 1px solid #008855;
  padding: 0 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
  gap: 4px;
  flex: 1.25;
  min-width: 0;
  box-sizing: border-box;
  line-height: normal;
  margin: 0;
}

.ersag-chat-product-card__btn-cart:hover {
  background: #006b43;
  border-color: #006b43;
}

.ersag-chat-product-card__btn-cart--added {
  background: #e6f5ee;
  color: #00774a;
  border-color: rgba(0, 136, 85, 0.4);
}

.ersag-chat-product-card__btn-cart--added:hover {
  background: #d1fae5;
  color: #005a36;
}

/* In-Chat Cart Addition Alert Banner */
.ersag-chat-cart-alert {
  align-self: flex-start;
  margin: 6px 0;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 12px;
  padding: 8px 12px;
  animation: ersagFadeIn 0.2s ease-out;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.08);
}

.ersag-chat-cart-alert__content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ersag-chat-cart-alert__icon {
  font-size: 18px;
  line-height: 1;
}

.ersag-chat-cart-alert__body {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ersag-chat-cart-alert__title {
  font-size: 12.5px;
  color: #065f46;
  line-height: 1.3;
}

.ersag-chat-cart-alert__btn {
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: #008855;
  background: #ffffff;
  border: 1px solid rgba(0, 136, 85, 0.35);
  border-radius: 14px;
  padding: 3px 10px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.ersag-chat-cart-alert__btn:hover {
  background: #008855;
  color: #ffffff;
  border-color: #008855;
}

/* Inline product link for products already introduced */
.ersag-chat-product-link {
  color: #008855;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s ease;
  word-break: normal;
  display: inline;
}

.ersag-chat-product-link:hover {
  color: #006b43;
  text-decoration: underline;
}

/* External markdown links and autolinks in message bubbles */
.ersag-chat-text-link {
  color: #008855;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  word-break: break-all;
  transition: color 0.15s ease;
}

.ersag-chat-text-link:hover {
  color: #006b43;
}

/* Inline clickable product badge inside message text */
.ersag-chat-inline-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #e6f5ee;
  color: #00774a;
  padding: 1px 7px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12.5px;
  text-decoration: none;
  border: 1px solid rgba(0, 136, 85, 0.25);
  transition: all 0.18s;
  vertical-align: baseline;
}

.ersag-chat-inline-badge:hover {
  background: #008855;
  color: #ffffff;
  border-color: #008855;
}

/* In-Chat Reset Confirmation Prompt */
.ersag-chat-reset-confirm {
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 14px;
  padding: 14px 16px;
  margin: 6px 0;
  text-align: center;
  box-shadow: 0 3px 12px rgba(0, 136, 85, 0.08);
  animation: ersagFadeIn 0.22s ease-out;
}

.ersag-chat-reset-confirm__title {
  font-size: 13.5px;
  font-weight: 600;
  color: #14532d;
  margin-bottom: 12px;
  line-height: 1.4;
}

.ersag-chat-reset-confirm__actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.ersag-chat-reset-confirm__btn {
  font-family: inherit;
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.18s ease;
  line-height: 1.2;
}

.ersag-chat-reset-confirm__btn--yes {
  background: #008855;
  color: #ffffff;
  border: none;
  box-shadow: 0 2px 6px rgba(0, 136, 85, 0.25);
}

.ersag-chat-reset-confirm__btn--yes:hover {
  background: #006b43;
  transform: translateY(-1px);
}

.ersag-chat-reset-confirm__btn--no {
  background: #ffffff;
  color: #4b5563;
  border: 1px solid #d1d5db;
}

.ersag-chat-reset-confirm__btn--no:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
  color: #1f2937;
}

/* Footer & Input */
.ersag-chat-footer {
  padding: 10px 14px 12px 14px;
  background: #ffffff;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.ersag-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8faf9;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 26px;
  padding: 4px 6px 4px 16px;
  min-height: 44px;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ersag-chat-input-row:focus-within {
  border-color: #008855;
  box-shadow: 0 0 0 3px rgba(0, 136, 85, 0.12);
  background: #ffffff;
}

.ersag-chat-textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 20px;
  height: 20px;
  max-height: 100px;
  padding: 0;
  margin: 0;
  outline: none;
  color: var(--ersag-chat-text);
  box-sizing: border-box;
  vertical-align: middle;
}

.ersag-chat-textarea::placeholder {
  color: #94a3b8;
  line-height: 20px;
}

.ersag-chat-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #008855;
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.18s;
  box-sizing: border-box;
  padding: 0;
}

.ersag-chat-send-btn svg {
  display: block;
  transform: translate(1.5px, 1.5px);
}

.ersag-chat-send-btn:hover {
  background: #006b43;
  transform: scale(1.05);
}

.ersag-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.ersag-chat-footnote {
  font-size: 10.5px;
  color: #94a3b8;
  text-align: center;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  .ersag-chat-launcher {
    bottom: 16px;
    right: 16px;
    padding: 10px 14px 10px 10px;
  }
  .ersag-chat-launcher__sub {
    display: none;
  }
  .ersag-chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }
}
