/* ── Chat panel ──────────────────────────────────────── */
#chat-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 0% 0%, rgba(160,10,36,0.18), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(160,10,36,0.18), transparent 35%);
  pointer-events: none;
  z-index: 0;
  will-change: opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translateZ(0);
  animation: gradientPulse 10s ease-in-out infinite;
}

[data-theme="light"] #chat-panel::before {
  background:
    radial-gradient(circle at 0% 0%, rgba(140,20,50,0.13), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(140,20,50,0.13), transparent 35%);
}

/* Gentle breathing pulse */
@keyframes gradientPulse {
  0%   { opacity: 0.4; }
  25%  { opacity: 0.58; }
  50%  { opacity: 0.8; }
  75%  { opacity: 0.58; }
  100% { opacity: 0.4; }
}

/* ── Messages ────────────────────────────────────────── */
#messages {
  position: relative; z-index: 1; flex: 1; overflow-y: auto;
  padding: 24px 32px; display: flex; flex-direction: column; gap: 20px;
}
#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--mac-mid); border-radius: 3px; }

.msg { display: flex; gap: 12px; max-width: var(--chat-max); }
.msg.user { flex-direction: row-reverse; align-self: flex-end; }
.msg.bot  { align-self: flex-start; }

.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; flex-shrink: 0; border: 1px solid var(--mac-border);
}
.msg.bot  .msg-avatar { background: linear-gradient(135deg, #c8102e, #8b0a1e); }
.msg.user .msg-avatar { background: linear-gradient(135deg, var(--mac-gold), var(--mac-nude)); }

.msg-body { flex: 1; min-width: 0; }
.msg-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.msg.user .msg-meta { flex-direction: row-reverse; }
.msg-sender { font-size: 12px; font-weight: 500; color: var(--text-secondary); }

.msg-agent-tag {
  font-size: 10px; padding: 2px 7px; border-radius: 10px;
  letter-spacing: 0.5px; text-transform: uppercase; font-weight: 500;
}
.tag-sales   { background: rgba(200,16,46,0.2);   color: #ff6b7a; border: 1px solid rgba(200,16,46,0.3); }
.tag-support { background: rgba(232,160,180,0.2); color: var(--mac-pink-lt); border: 1px solid rgba(232,160,180,0.3); }
.tag-beauty  { background: rgba(167,139,250,0.2); color: #c4b5fd; border: 1px solid rgba(167,139,250,0.3); }
.tag-hub     { background: rgba(201,169,110,0.2); color: var(--mac-gold-lt); border: 1px solid rgba(201,169,110,0.3); }

.msg-bubble {
  padding: 14px 18px; border-radius: var(--radius);
  font-size: 14px; line-height: 1.65; word-break: break-word;
  color: var(--mac-cream);
}
.msg.bot .msg-bubble {
  background: var(--mac-dark); border: 1px solid var(--mac-border);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, #c8102e, #9a0d24);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  color: #fff; box-shadow: 0 4px 20px var(--mac-red-glow);
}

.msg-bubble strong { color: var(--mac-gold-lt); font-weight: 600; }
.msg.user .msg-bubble strong { color: rgba(255,255,255,0.9); }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { font-family: 'Cormorant Garamond', serif; font-weight: 500; color: var(--mac-gold); margin: 12px 0 6px; }
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; }
.msg-bubble h3 { font-size: 14px; }
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 4px 0 8px 0; padding-left: 20px; }
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble li:last-child { margin-bottom: 0; }
.msg-bubble a { color: var(--mac-gold-lt); text-decoration: underline; text-underline-offset: 2px; }
.msg-bubble a:hover { color: var(--mac-gold); }
.msg-bubble .product-mention { font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; text-decoration-color: var(--mac-gold-lt); }
.msg-bubble code { background: rgba(255,255,255,0.07); padding: 2px 5px; border-radius: 4px; font-size: 0.9em; font-family: 'SF Mono', 'Fira Code', monospace; }
.msg-bubble pre { background: rgba(255,255,255,0.05); border-radius: 6px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble blockquote { border-left: 3px solid var(--mac-gold, #c8a86e); margin: 8px 0; padding: 4px 12px; opacity: 0.85; }
.msg-bubble hr { border: none; border-top: 1px solid rgba(255,255,255,0.1); margin: 10px 0; }
[data-theme="light"] .msg-bubble code { background: rgba(0,0,0,0.06); }
[data-theme="light"] .msg-bubble pre { background: rgba(0,0,0,0.04); }
[data-theme="light"] .msg-bubble hr { border-top-color: rgba(0,0,0,0.1); }

/* Chat tables */
.chat-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; line-height: 1.5; }
/* Expand bubble when it contains a table so columns aren't cramped */
.msg:has(.chat-table) { max-width: 95%; }
.chat-table th { text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--mac-gold, #c8a86e); color: var(--mac-gold-lt, #d4b87a); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.chat-table td { padding: 7px 10px; border-bottom: 1px solid rgba(255,255,255,0.08); vertical-align: top; }
.chat-table tbody tr:last-child td { border-bottom: none; }
.chat-table tbody tr:hover td { background: rgba(255,255,255,0.04); }
[data-theme="light"] .chat-table td { border-bottom-color: rgba(0,0,0,0.08); }
[data-theme="light"] .chat-table tbody tr:hover td { background: rgba(0,0,0,0.03); }

/* Typing */
.typing-bubble { display: flex; gap: 5px; align-items: center; padding: 14px 18px; }
.typing-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mac-gold); animation: bounce 1.2s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.6; } 30% { transform: translateY(-6px); opacity: 1; } }

/* Thinking indicator */
.thinking-indicator { display: flex; align-items: center; gap: 10px; padding: 14px 18px; animation: fadeIn 0.3s ease; }
.thinking-spinner { width: 16px; height: 16px; border: 2px solid var(--mac-border); border-top-color: var(--mac-gold); border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0; }
.thinking-text { font-size: 13px; color: var(--text-secondary); font-style: italic; }
.thinking-steps { display: flex; flex-direction: column; gap: 4px; padding: 10px 18px 14px; animation: fadeIn 0.3s ease; }
.thinking-step { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); animation: slideIn 0.3s ease; }
.thinking-step.active { color: var(--mac-gold); }
.thinking-step-icon { font-size: 13px; width: 18px; text-align: center; }
.thinking-step-check { color: #4ade80; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* ── Welcome screen ──────────────────────────────────── */
#welcome {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; z-index: 2;
  padding: 40px 32px; text-align: center; pointer-events: none; transition: opacity 0.4s ease;
}
#welcome.hidden { opacity: 0; pointer-events: none; }
.welcome-icon { font-size: 48px; margin-bottom: 20px; filter: drop-shadow(0 4px 12px var(--mac-red-glow)); }
.welcome-title { font-family: 'Cormorant Garamond', serif; font-size: 36px; font-weight: 300; letter-spacing: 2px; color: var(--mac-white); margin-bottom: 12px; }
.welcome-sub { font-size: 14px; color: var(--text-muted); max-width: 400px; margin-bottom: 32px; line-height: 1.7; }
.welcome-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 500px; pointer-events: all; }
.welcome-chip { background: var(--mac-glass); border: 1px solid var(--mac-border); color: var(--text-secondary); font-size: 13px; padding: 8px 14px; border-radius: 20px; cursor: pointer; transition: all var(--transition); }
.welcome-chip:hover { background: var(--mac-glass-h); color: var(--mac-white); border-color: rgba(255,255,255,0.15); transform: translateY(-1px); }

/* ── Input area ──────────────────────────────────────── */
#input-area { position: relative; z-index: 1; padding: 16px 24px 20px; border-top: 1px solid var(--mac-border); flex-shrink: 0; }
.input-wrapper { display: flex; align-items: center; gap: 10px; max-width: var(--chat-max); margin: 0 auto; background: var(--mac-dark); border: 1px solid var(--mac-border); border-radius: var(--radius); padding: 12px 14px; transition: border-color var(--transition); }
.input-wrapper:focus-within { border-color: rgba(200,16,46,0.4); box-shadow: 0 0 0 3px rgba(200,16,46,0.08); }
#msg-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text-primary); font-family: 'Inter', sans-serif; font-size: 16px; line-height: 1.5; resize: none; max-height: 120px; overflow-y: auto; }
#msg-input::placeholder { color: var(--text-muted); }
#msg-input::-webkit-scrollbar { width: 3px; }
#msg-input::-webkit-scrollbar-thumb { background: var(--mac-mid); }

.send-btn { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--mac-red), #9a0d24); border: none; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all var(--transition); font-size: 15px; }
.send-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 16px var(--mac-red-glow); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.mic-btn { width: 36px; height: 36px; border-radius: 10px; background: var(--mac-glass); border: 1px solid var(--mac-border); color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all var(--transition); font-size: 16px; }
.mic-btn:hover { background: var(--mac-glass-h); color: var(--mac-white); }
.mic-btn.recording { background: var(--mac-red); border-color: var(--mac-red); color: white; animation: mic-pulse 1s infinite; }
@keyframes mic-pulse { 0%, 100% { box-shadow: 0 0 0 0 var(--mac-red-glow); } 50% { box-shadow: 0 0 0 8px transparent; } }

/* ── Selfie attachment preview (above the composer) ───── */
.attached-image-preview { display: flex; align-items: center; gap: 10px; max-width: var(--chat-max); margin: 0 auto 8px; padding: 8px 12px; background: var(--mac-dark); border: 1px solid var(--mac-border); border-radius: var(--radius); }
.attached-image-preview.hidden { display: none; }
.attached-image-preview img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid var(--mac-border); }
.attached-image-label { flex: 1; font-size: 12px; color: var(--text-muted); }
.attached-image-remove { width: 24px; height: 24px; border-radius: 50%; background: var(--mac-glass); border: 1px solid var(--mac-border); color: var(--text-muted); cursor: pointer; font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all var(--transition); }
.attached-image-remove:hover { background: var(--mac-red); color: white; border-color: var(--mac-red); }

/* Inline image inside a chat message bubble */
.msg-image { margin-bottom: 8px; }
.msg-image img { max-width: 220px; max-height: 220px; border-radius: 10px; object-fit: cover; border: 1px solid var(--mac-border); display: block; }

.input-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; padding: 0 4px; max-width: var(--chat-max); margin-left: auto; margin-right: auto; }
.input-hint { font-size: 11px; color: var(--text-muted); }
#char-count { font-size: 11px; color: var(--text-muted); }

/* ── Metrics bar ─────────────────────────────────────── */
.msg-metrics { display: flex; align-items: center; gap: 12px; margin-top: 8px; padding: 6px 0; font-size: 11px; color: var(--text-muted); flex-wrap: wrap; }
.metric-item { display: flex; align-items: center; gap: 4px; }
.metric-item .metric-icon { font-size: 12px; opacity: 0.7; }
.metric-value { font-weight: 500; color: var(--text-secondary); }
.metric-agents { display: flex; align-items: center; gap: 4px; }
.metric-agent-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.metric-agent-dot.hub    { background: var(--mac-gold); }
.metric-agent-dot.sales  { background: var(--mac-red); }
.metric-agent-dot.support{ background: var(--mac-pink); }
.metric-agent-dot.beauty { background: #a78bfa; }
.metric-arrow { font-size: 10px; color: var(--text-muted); }

/* ── Chat product cards ──────────────────────────────── */
.chat-product-cards { display: flex; flex-wrap: nowrap; gap: 10px; margin-top: 14px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.chat-product-cards::-webkit-scrollbar { height: 5px; }
.chat-product-cards::-webkit-scrollbar-track { background: transparent; }
.chat-product-cards::-webkit-scrollbar-thumb { background: var(--mac-mid); border-radius: 3px; }
.chat-product-card {
  display: flex; flex-direction: column;
  background: var(--mac-charcoal); border: 1px solid var(--mac-border);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all var(--transition);
  min-width: 180px; max-width: 200px; flex: 0 0 auto; scroll-snap-align: start;
  overflow: hidden;
}
.chat-product-card:hover { border-color: rgba(200,16,46,0.3); background: var(--mac-dark); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }
.chat-product-card .cp-img {
  width: 100%; height: 120px; object-fit: cover;
  background: var(--mac-mid); display: block; cursor: pointer;
}
.chat-product-card .cp-img-placeholder {
  width: 100%; height: 120px; display: flex; align-items: center; justify-content: center;
  background: var(--mac-mid); color: var(--text-muted); cursor: pointer;
}
.chat-product-card .cp-body { padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.chat-product-card .cp-name { font-size: 12px; font-weight: 500; color: var(--mac-white); line-height: 1.3; }
.chat-product-card .cp-cat { font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: var(--mac-gold); }
.chat-product-card .cp-price { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.chat-product-card .cp-variants { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.chat-product-card .cp-variant-tag { font-size: 10px; padding: 2px 7px; border-radius: 10px; background: var(--mac-glass); border: 1px solid var(--mac-border); color: var(--text-secondary); white-space: nowrap; }
.chat-product-card .cp-shades { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; align-items: center; }
.cp-shade-chip {
  width: 20px; height: 20px; border-radius: 50%; overflow: hidden;
  border: 2px solid transparent; cursor: pointer; flex-shrink: 0;
  background-size: cover; background-position: center;
  transition: all 0.2s ease;
}
.cp-shade-chip:hover { border-color: var(--mac-white); transform: scale(1.15); }
.cp-shade-chip.recommended { border-color: var(--mac-gold); box-shadow: 0 0 6px rgba(201,169,110,0.5); }
.cp-shade-overflow { font-size: 10px; color: var(--text-muted); padding: 0 4px; white-space: nowrap; }
.chat-product-card .cp-footer { padding: 0 10px 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.cp-tryon-btn,
.cp-chroma-btn {
  all: unset; cursor: pointer; font-size: 11px; padding: 5px 0;
  border-radius: 6px; background: rgba(200,16,46,0.15); color: var(--mac-red, #c8102e);
  font-weight: 600; white-space: nowrap; text-align: center; width: 100%;
  display: block; transition: all var(--transition); flex: 1 1 74px;
}
.cp-chroma-btn { background: rgba(201,169,110,0.14); color: var(--mac-gold); }
.cp-tryon-btn:hover,
.cp-chroma-btn:hover { background: rgba(200,16,46,0.3); transform: scale(1.02); }
.cp-chroma-btn:hover { background: rgba(201,169,110,0.24); }
.cp-tryon-btn:disabled,
.cp-chroma-btn:disabled { opacity: 0.65; cursor: default; transform: none; }
.cp-chroma-preview { margin: 0 10px 8px; border-radius: 6px; overflow: hidden; background: var(--mac-mid); }
.cp-chroma-preview img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
.cp-chroma-loading { padding: 10px; font-size: 11px; color: var(--text-secondary); text-align: center; }

/* ── Avatar initial ──────────────────────────────────── */
.avatar-initial {
  font-family: 'Cormorant Garamond', serif;
  font-size: 15px; font-weight: 600; color: #fff;
  line-height: 1; user-select: none;
}

/* ── Metric label (replaces emoji icons) ─────────────── */
.metric-label { font-weight: 500; opacity: 0.6; }

/* ── In-chat selfie capture card ─────────────────────── */
.selfie-capture-card {
  margin-top: 12px; padding: 12px;
  border: 1px solid rgba(200,16,46,0.25);
  background: rgba(200,16,46,0.06);
  border-radius: 12px;
}
.selfie-capture-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.selfie-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid rgba(200,16,46,0.4);
  background: transparent; color: inherit;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all var(--transition);
}
.selfie-btn:hover { background: rgba(200,16,46,0.12); }
.selfie-btn-primary {
  background: var(--mac-red, #C8102E); color: #fff;
  border-color: var(--mac-red, #C8102E);
}
.selfie-btn-primary:hover { background: #a00a24; }
.selfie-capture-hint {
  margin: 8px 0 0; font-size: 12px; opacity: 0.7;
}

@media (max-width: 768px) {
  #messages { padding: 16px; gap: 16px; }
  .msg { max-width: 100%; gap: 10px; }
  .msg-avatar { width: 32px; height: 32px; }
  .msg-bubble { padding: 12px 14px; font-size: 14px; }
  #input-area { padding: 12px 16px max(16px, env(safe-area-inset-bottom)); }
  .input-wrapper { padding: 10px 12px; gap: 8px; }
  .send-btn, .mic-btn { width: 44px; height: 44px; }
  .attached-image-remove { width: 44px; height: 44px; }
  .selfie-btn { min-height: 44px; }
  .selfie-modal-card { margin: max(12px, env(safe-area-inset-top)) 12px 0; max-width: none; }
}

@media (max-width: 600px) {
  #messages { padding: 12px; }
  .msg { width: 100%; }
  .msg.user { padding-left: 44px; }
  .msg.bot { padding-right: 8px; }
  .input-footer { display: none; }
  .chat-product-cards { display: grid; grid-template-columns: 1fr; overflow: visible; gap: 10px; }
  .chat-product-card { min-width: 0; max-width: none; width: 100%; }
  .chat-product-card .cp-img,
  .chat-product-card .cp-img-placeholder { height: 160px; }
}

@media (max-width: 480px) {
  .welcome-title { font-size: 28px; }
  .welcome-sub { font-size: 13px; }
  .welcome-chips { display: none; }
  #input-area { padding-left: 12px; padding-right: 12px; }
  .msg-bubble { border-radius: 12px; }
  .chat-table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ── Selfie camera modal ─────────────────────────────── */
.selfie-modal { position: fixed; inset: 0; z-index: 9999; display: none; }
.selfie-modal.open { display: block; }
.selfie-modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.65);
}
.selfie-modal-card {
  position: relative; max-width: 480px; margin: 5vh auto 0;
  background: #1a1a1a; color: #fff; border-radius: 16px;
  padding: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.selfie-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; margin-bottom: 12px;
}
.selfie-modal-close {
  background: none; border: 0; color: #fff; font-size: 24px;
  cursor: pointer; line-height: 1; padding: 0 4px;
}
#selfie-video {
  width: 100%; max-height: 60vh; border-radius: 12px;
  background: #000; transform: scaleX(-1); /* mirror preview */
  display: block;
}
.selfie-modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px;
}
