/* Bud AI Skin Advisor — Frontend Widget Styles */

/* ── CSS Variables (overridden by inline style injected from admin settings) ── */
:root {
  --bud-primary:       #2d5a3d;
  --bud-accent:        #c9a84c;
  --bud-bg:            #faf9f6;
  --bud-text:          #1a1a1a;
  --bud-muted:         #6b7280;
  --bud-border:        rgba(0,0,0,0.08);
  --bud-shadow:        0 8px 40px rgba(0,0,0,0.18);
  --bud-radius:        16px;
  --bud-ease:          cubic-bezier(0.23, 1, 0.32, 1);
  /* Bubble customisation — overridden by injectStyles() from admin settings */
  --bud-bubble-size:   56px;
  --bud-bubble-shadow: 0 4px 16px rgba(0,0,0,0.20);
  --bud-offset-bottom: 24px;
  --bud-offset-side:   24px;
}

/* ── Widget container ────────────────────────────────────────────────────────── */
.bud-widget {
  position: fixed;
  bottom: var(--bud-offset-bottom);
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.bud-widget--right { right: var(--bud-offset-side); }
.bud-widget--left  { left: var(--bud-offset-side); }

/* ── Toggle button ───────────────────────────────────────────────────────────── */
.bud-toggle {
  width: var(--bud-bubble-size);
  height: var(--bud-bubble-size);
  border-radius: 50%;
  background: var(--bud-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--bud-bubble-shadow);
  transition: transform 200ms var(--bud-ease), box-shadow 200ms var(--bud-ease);
  position: relative;
  z-index: 2;
}

.bud-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(201,168,76,0.55);
}

.bud-toggle:active {
  transform: scale(0.95);
}

.bud-toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 150ms ease;
}

/* ── Chat window ─────────────────────────────────────────────────────────────── */
.bud-chat-window {
  position: absolute;
  bottom: 70px;
  width: 360px;
  /* Use viewport-relative height so the window never gets crushed on short screens.
     min() keeps it at most 620px but never taller than 85% of the viewport. */
  height: min(620px, calc(85vh - 80px));
  max-height: min(620px, calc(85vh - 80px));
  background: var(--bud-bg);
  border-radius: var(--bud-radius);
  box-shadow: var(--bud-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.95) translateY(8px);
  transition: opacity 250ms var(--bud-ease), transform 250ms var(--bud-ease);
  pointer-events: none;
}

.bud-widget--right .bud-chat-window { right: 0; transform-origin: bottom right; }
.bud-widget--left  .bud-chat-window { left: 0;  transform-origin: bottom left; }

.bud-chat-window--open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
.bud-header {
  background: var(--bud-primary);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.bud-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bud-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.bud-header-name {
  color: white;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
}

.bud-header-status {
  color: rgba(255,255,255,0.75);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

.bud-status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(74,222,128,0.3);
}

.bud-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.bud-header-action {
  background: rgba(255,255,255,0.12);
  border: none;
  color: white;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, opacity 150ms ease;
  flex-shrink: 0;
  padding: 0;
}

.bud-header-action:hover { background: rgba(255,255,255,0.22); }
.bud-header-action:focus-visible { outline: 2px solid white; outline-offset: 1px; }

/* Maintain legacy class for any external selectors */
.bud-header-close { background: rgba(255,255,255,0.12); }
.bud-header-close:hover { background: rgba(255,255,255,0.22); }

/* ── Messages ────────────────────────────────────────────────────────────────── */
.bud-messages {
  flex: 1;
  min-height: 0; /* required for flex children to scroll correctly */
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.bud-messages::-webkit-scrollbar { width: 4px; }
.bud-messages::-webkit-scrollbar-track { background: transparent; }
.bud-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 2px; }

.bud-msg {
  display: flex;
  animation: budMsgIn 200ms var(--bud-ease) both;
}

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

.bud-msg--user {
  justify-content: flex-end;
}

.bud-msg--assistant {
  justify-content: flex-start;
  flex-direction: column; /* stack product cards below the text bubble */
  align-items: flex-start;
}

.bud-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.bud-msg--user .bud-bubble {
  background: var(--bud-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.bud-msg--assistant .bud-bubble {
  background: white;
  color: var(--bud-text);
  border: 1px solid var(--bud-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* Markdown rendering inside assistant bubbles */
.bud-msg--assistant .bud-bubble p  { margin: 0 0 8px; }
.bud-msg--assistant .bud-bubble p:last-child { margin-bottom: 0; }
.bud-msg--assistant .bud-bubble ul,
.bud-msg--assistant .bud-bubble ol { margin: 6px 0 8px; padding-left: 18px; }
.bud-msg--assistant .bud-bubble li { margin-bottom: 3px; }
.bud-msg--assistant .bud-bubble strong { color: var(--bud-primary); font-weight: 600; }
.bud-msg--assistant .bud-bubble code {
  background: #f0f4f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  font-family: monospace;
}
.bud-msg--assistant .bud-bubble h3,
.bud-msg--assistant .bud-bubble h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 10px 0 4px;
  color: var(--bud-primary);
}

/* Product hyperlinks inside assistant bubbles */
.bud-msg--assistant .bud-bubble a {
  color: var(--bud-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
  word-break: break-word;
  transition: opacity 0.15s ease;
}
.bud-msg--assistant .bud-bubble a:hover {
  opacity: 0.75;
}
.bud-msg--assistant .bud-bubble a::after {
  content: ' \2197';
  font-size: 10px;
  vertical-align: super;
  opacity: 0.6;
}

/* ── Typing indicator ────────────────────────────────────────────────────────── */
.bud-msg--typing .bud-bubble {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.bud-dot {
  width: 7px;
  height: 7px;
  background: var(--bud-muted);
  border-radius: 50%;
  display: inline-block;
  animation: budDot 1.2s infinite ease-in-out;
}

.bud-dot:nth-child(2) { animation-delay: 0.2s; }
.bud-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes budDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Disclaimer ──────────────────────────────────────────────────────────────── */
.bud-disclaimer {
  background: #fef9ec;
  border-top: 1px solid rgba(201,168,76,0.2);
  padding: 7px 10px 7px 14px;
  font-size: 10.5px;
  color: #92763a;
  line-height: 1.4;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.bud-disclaimer-text {
  flex: 1;
}

.bud-disclaimer-close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #b89a4e;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  margin-top: 1px;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.bud-disclaimer-close:hover {
  opacity: 1;
}

/* ── Input area ──────────────────────────────────────────────────────────────── */
.bud-input-area {
  border-top: 1px solid var(--bud-border);
  background: white;
  flex-shrink: 0;
}

.bud-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
}

.bud-input {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  background: #f8f8f8;
  color: var(--bud-text);
  transition: border-color 150ms ease, background 150ms ease;
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
}

.bud-input:focus {
  border-color: var(--bud-primary);
  background: white;
}

.bud-input::placeholder { color: #aaa; }

.bud-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bud-primary);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.bud-send-btn:hover:not(:disabled) {
  background: #1a3d26;
  transform: scale(1.05);
}

.bud-send-btn:active:not(:disabled) {
  transform: scale(0.93);
}

.bud-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.bud-input-footer {
  text-align: center;
  font-size: 10px;
  color: #bbb;
  padding: 0 12px 8px;
  letter-spacing: 0.03em;
}

/* ── Mobile responsive ───────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .bud-widget--right { right: 16px; bottom: 16px; }
  .bud-widget--left  { left: 16px;  bottom: 16px; }

  .bud-chat-window {
    width: calc(100vw - 32px);
    max-height: 70vh;
  }

  .bud-widget--right .bud-chat-window { right: 0; }
  .bud-widget--left  .bud-chat-window { left: 0; }
}

/* ── Reduced motion ──────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .bud-chat-window,
  .bud-toggle,
  .bud-msg,
  .bud-dot {
    transition: none !important;
    animation: none !important;
  }
}

/* ── Suggested question chips ────────────────────────────────────────────────── */
.bud-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 4px 0 8px;
}

.bud-suggestion-chip {
  background: transparent;
  border: 1.5px solid var(--bud-primary);
  color: var(--bud-primary);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, transform 120ms ease;
  line-height: 1.3;
  text-align: left;
}

.bud-suggestion-chip:hover {
  background: var(--bud-primary);
  color: white;
  transform: translateY(-1px);
}

.bud-suggestion-chip:active {
  transform: scale(0.96);
}

/* ── Avatar — image variant ──────────────────────────────────────────────────── */
.bud-avatar--img {
  background: transparent;
  border: none;
  padding: 0;
}

.bud-avatar--img img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}

/* ── Proactive tooltip ───────────────────────────────────────────────────────── */
.bud-proactive-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  background: white;
  color: var(--bud-text);
  border: 1px solid var(--bud-border);
  border-left: 3px solid var(--bud-accent);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  max-width: 260px;
  white-space: normal;
  box-shadow: 0 4px 16px rgba(0,0,0,0.13);
  cursor: pointer;
  animation: budTooltipIn 300ms var(--bud-ease) both;
  z-index: 3;
}

.bud-widget--left .bud-proactive-tooltip {
  right: auto;
  left: 0;
}

.bud-proactive-tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 20px;
  width: 10px;
  height: 10px;
  background: white;
  border-right: 1px solid var(--bud-border);
  border-bottom: 1px solid var(--bud-border);
  transform: rotate(45deg);
}

.bud-widget--left .bud-proactive-tooltip::after {
  right: auto;
  left: 20px;
}

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

/* Pulse animation on the toggle bubble */
.bud-toggle--pulse {
  animation: budPulse 1.4s ease-in-out infinite;
}

@keyframes budPulse {
  0%   { box-shadow: 0 0 0 0 rgba(201,168,76,0.55); }
  60%  { box-shadow: 0 0 0 12px rgba(201,168,76,0); }
  100% { box-shadow: 0 0 0 0 rgba(201,168,76,0); }
}

/* ── Inline product cards ────────────────────────────────────────────────────── */
.bud-product-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  width: 82%; /* match assistant bubble max-width */
  max-width: 82%;
}

.bud-product-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border: 1px solid var(--bud-border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  animation: budMsgIn 200ms var(--bud-ease) both;
  transition: box-shadow 150ms ease;
}

.bud-product-card:hover {
  box-shadow: 0 3px 12px rgba(0,0,0,0.10);
}

.bud-product-card__img-link {
  flex-shrink: 0;
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  background: #f4f4f2;
}

.bud-product-card__img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  display: block;
}

.bud-product-card__img-placeholder {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0ee;
}

.bud-product-card__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bud-product-card__name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--bud-text);
  text-decoration: none;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.bud-product-card__name:hover {
  color: var(--bud-primary);
}

.bud-product-card__price {
  font-size: 12px;
  color: var(--bud-primary);
  font-weight: 600;
}

.bud-product-card__price .woocommerce-Price-amount {
  color: var(--bud-primary);
}

.bud-product-card__atc {
  margin-top: 4px;
  background: var(--bud-primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, transform 100ms ease, opacity 150ms ease;
  letter-spacing: 0.01em;
  align-self: flex-start;
}

.bud-product-card__atc:hover:not(:disabled) {
  background: #1a3d26;
  transform: scale(1.02);
}

.bud-product-card__atc:active:not(:disabled) {
  transform: scale(0.97);
}

.bud-product-card__atc:disabled {
  opacity: 0.6;
  cursor: default;
}

.bud-product-card__atc--added {
  background: #4ade80 !important;
  color: #1a3d26 !important;
}

/* ── Skeleton loading state ──────────────────────────────────────────────────── */
@keyframes budShimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.bud-skeleton {
  background: linear-gradient(90deg, #f0f0ee 25%, #e8e8e6 50%, #f0f0ee 75%);
  background-size: 400px 100%;
  animation: budShimmer 1.4s infinite linear;
  border-radius: 4px;
}

.bud-skeleton--img {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  flex-shrink: 0;
}

.bud-skeleton--name {
  height: 12px;
  width: 90%;
  margin-bottom: 2px;
}

.bud-skeleton--price {
  height: 11px;
  width: 45%;
}

.bud-skeleton--btn {
  height: 24px;
  width: 80px;
  margin-top: 4px;
  border-radius: 6px;
}

.bud-product-card--skeleton {
  pointer-events: none;
}

/* ── Email capture prompt ────────────────────────────────────────────────────── */
.bud-capture-wrap {
  width: 82%;
  margin-top: 6px;
}

.bud-capture-prompt {
  background: linear-gradient(135deg, #faf9f6 0%, #fef9ec 100%);
  border: 1.5px solid rgba(201,168,76,0.35);
  border-radius: 12px;
  padding: 14px 16px;
}

.bud-capture-heading {
  margin: 0 0 3px;
  font-size: 13px;
  font-weight: 700;
  color: var(--bud-primary);
}

.bud-capture-sub {
  margin: 0 0 10px;
  font-size: 12px;
  color: #666;
  line-height: 1.4;
}

.bud-capture-row {
  display: flex;
  gap: 6px;
}

.bud-capture-input {
  flex: 1;
  border: 1.5px solid #ddd;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
  background: white;
  color: var(--bud-text);
  transition: border-color 150ms ease;
  min-width: 0;
}

.bud-capture-input:focus {
  border-color: var(--bud-accent);
}

.bud-capture-btn {
  flex-shrink: 0;
  background: var(--bud-accent);
  color: white;
  border: none;
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 150ms ease, transform 100ms ease;
}

.bud-capture-btn:hover:not(:disabled) {
  background: #b8942e;
  transform: scale(1.02);
}

.bud-capture-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.bud-capture-legal {
  margin: 8px 0 0;
  font-size: 10px;
  color: #aaa;
  line-height: 1.4;
}

/* Success state */
.bud-capture-success {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #f0faf4;
  border: 1.5px solid rgba(45,90,61,0.2);
  border-radius: 12px;
  padding: 12px 14px;
}

.bud-capture-tick {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: var(--bud-primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 1px;
}

.bud-capture-success-heading {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 700;
  color: var(--bud-primary);
}

.bud-capture-success-sub {
  margin: 0;
  font-size: 12px;
  color: #555;
  line-height: 1.4;
}

/* ── Conversation resume hint ───────────────────────────────────────────────── */
.bud-resume-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  color: #888;
  padding: 6px 12px;
  margin-bottom: 6px;
  text-align: center;
  letter-spacing: 0.02em;
  animation: budMsgIn 200ms var(--bud-ease) both;
}

.bud-resume-hint::before,
.bud-resume-hint::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.08), transparent);
  max-width: 60px;
}

.bud-resume-hint span {
  font-size: 13px;
  color: var(--bud-accent);
}

/* ── System note / error bubble variant ─────────────────────────────────────── */
/* Used when the AI couldn't respond — softer amber tint to signal "system note"
 * while keeping the warmth of Aura's voice. */
.bud-msg--system .bud-bubble {
  background: #fefaf0;
  border-left: 3px solid var(--bud-accent);
  color: #5a4010;
}

.bud-msg--system .bud-bubble strong {
  color: #5a4010;
  font-weight: 700;
}

.bud-msg--system .bud-bubble a {
  color: #b8942e;
  text-decoration: underline;
}
