/*
 * WooCommerce AI Chatbot Widget — Styles
 * @package WC_AI_Chatbot
 */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&display=swap');

:root {
  --cb-font: 'DM Sans', system-ui, sans-serif;
  --cb-r: 24px;

  /* Bot mode palette — dark slate */
  --cb-bot-bg:         #0d1117;
  --cb-bot-header:     linear-gradient(135deg, #1a1f2e 0%, #0d1117 100%);
  --cb-bot-accent:     #4f8ef7;
  --cb-bot-msg-bg:     #1a1f2e;
  --cb-bot-msg-border: rgba(255,255,255,0.07);
  --cb-bot-text:       #e8eaf0;
  --cb-bot-muted:      rgba(232,234,240,0.45);
  --cb-bot-user-bg:    linear-gradient(135deg, #4f8ef7 0%, #3b6fd4 100%);

  /* Human/agent mode palette — bright blue */
  --cb-hu-bg:           #f0f6ff;
  --cb-hu-header:       linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  --cb-hu-accent:       #1d4ed8;
  --cb-hu-msg-bg:       #ffffff;
  --cb-hu-msg-border:   #dbeafe;
  --cb-hu-text:         #1e293b;
  --cb-hu-muted:        #94a3b8;
  --cb-hu-user-bg:      linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  --cb-hu-agent-bg:     #eff6ff;
  --cb-hu-agent-border: #bfdbfe;
  --cb-hu-agent-text:   #1e3a8a;

  --cb-green:  #10b981;
  --cb-red:    #ef4444;
  --cb-shadow: 0 32px 80px rgba(0,0,0,0.28), 0 8px 24px rgba(0,0,0,0.14);
}

#cb-w,
#cb-w * {
  box-sizing: border-box;
  margin: 0;
  font-family: var(--cb-font);
}

/* ── Launcher button ── */
#cb-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #1a1f2e 0%, #0d1117 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35), 0 0 0 1px rgba(79,142,247,0.25);
  transition: transform .25s cubic-bezier(.34,1.5,.64,1), box-shadow .2s ease;
}

#cb-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 10px 32px rgba(0,0,0,.4), 0 0 0 2px rgba(79,142,247,0.4);
}

#cb-btn .i {
  position: absolute;
  transition: opacity .22s, transform .25s cubic-bezier(.34,1.5,.64,1);
}

#cb-btn .i-msg { opacity: 1; transform: scale(1) rotate(0deg); }
#cb-btn .i-x   { opacity: 0; transform: scale(.3) rotate(-90deg); }
#cb-btn.open .i-msg { opacity: 0; transform: scale(.3) rotate(90deg); }
#cb-btn.open .i-x   { opacity: 1; transform: scale(1) rotate(0deg); }

/* Pulse ring */
#cb-btn::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(79,142,247,0.35);
  animation: cbPulse 2.5s ease-in-out infinite;
}

@keyframes cbPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%       { opacity: 0;   transform: scale(1.25); }
}

#cb-btn.open::after { display: none; }

#cb-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  background: var(--cb-red);
  border-radius: 10px;
  border: 2px solid #fff;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Chat window ── */
#cb-win {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 99998;
  width: 388px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 116px);
  border-radius: var(--cb-r);
  box-shadow: var(--cb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(.94);
  pointer-events: none;
  transition: opacity .26s ease, transform .3s cubic-bezier(.34,1.5,.64,1);
  background: var(--cb-bot-bg);
  border: 1px solid rgba(255,255,255,0.06);
}

#cb-win.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ── */
#cb-head {
  padding: 16px 18px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: var(--cb-bot-header);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--cb-r) var(--cb-r) 0 0;
  transition: background .45s ease;
  position: relative;
  overflow: hidden;
}

#cb-head::before {
  content: '';
  position: absolute;
  top: -30px;
  right: -20px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(79,142,247,0.18) 0%, transparent 70%);
  transition: background .45s ease;
}

#cb-head.human-mode {
  background: var(--cb-hu-header);
  border-bottom-color: rgba(255,255,255,0.1);
}

#cb-head.human-mode::before {
  background: radial-gradient(circle, rgba(255,255,255,0.12) 0%, transparent 70%);
}

/* Avatar */
#cb-av {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255,255,255,0.18);
  position: relative;
}

#cb-av-status {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cb-green);
  border: 2px solid #1a1f2e;
  transition: background .3s, border-color .3s;
}

#cb-head.human-mode #cb-av-status {
  border-color: #1d4ed8;
  background: #fff;
}

#cb-info    { flex: 1; min-width: 0; }
#cb-name    { font-size: 15px; font-weight: 600; color: #fff; letter-spacing: -.01em; }
#cb-status  { font-size: 11px; color: rgba(255,255,255,0.6); margin-top: 2px; display: flex; align-items: center; gap: 4px; }

#cb-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cb-green);
  flex-shrink: 0;
  transition: background .3s;
}

#cb-head.human-mode #cb-status-dot { background: rgba(255,255,255,0.8); }

/* ── Messages area ── */
#cb-msgs {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  transition: background .45s ease;
  background: var(--cb-bot-bg);
  min-width: 0;
  width: 100%;
}

#cb-win.human-chat #cb-msgs { background: var(--cb-hu-bg); }

#cb-msgs::-webkit-scrollbar       { width: 3px; }
#cb-msgs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
#cb-win.human-chat #cb-msgs::-webkit-scrollbar-thumb { background: #cbd5e1; }

/* ── Message bubbles ── */
.cb-m {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  min-width: 0;
  animation: cbIn .2s ease;
}

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

.cb-m.bot,
.cb-m.agent { align-self: flex-start; }
.cb-m.user  { align-self: flex-end; }

.cb-b {
  padding: 11px 15px;
  font-size: 13.5px;
  line-height: 1.65;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-line;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* Bot bubble — dark */
.cb-m.bot .cb-b {
  background: var(--cb-bot-msg-bg);
  color: var(--cb-bot-text);
  border: 1px solid var(--cb-bot-msg-border);
  border-radius: 5px 18px 18px 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Bot bubble — light (human chat) */
#cb-win.human-chat .cb-m.bot .cb-b {
  background: var(--cb-hu-msg-bg);
  color: var(--cb-hu-text);
  border-color: var(--cb-hu-msg-border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* Agent bubble */
.cb-m.agent .cb-b {
  background: var(--cb-hu-agent-bg);
  color: var(--cb-hu-agent-text);
  border: 1px solid var(--cb-hu-agent-border);
  border-radius: 5px 18px 18px 18px;
  box-shadow: 0 1px 4px rgba(29,78,216,0.1);
}

/* User bubble — dark */
.cb-m.user .cb-b {
  background: var(--cb-bot-user-bg);
  color: #fff;
  border-radius: 18px 5px 18px 18px;
  box-shadow: 0 2px 12px rgba(79,142,247,0.3);
}

/* User bubble — light (human chat) */
#cb-win.human-chat .cb-m.user .cb-b {
  background: var(--cb-hu-user-bg);
  box-shadow: 0 2px 12px rgba(29,78,216,0.25);
}

.cb-t { font-size: 10px; margin-top: 4px; color: var(--cb-bot-muted); }
.cb-m.user .cb-t { text-align: right; }
#cb-win.human-chat .cb-t { color: var(--cb-hu-muted); }

.cb-sender-label {
  font-size: 10px;
  font-weight: 600;
  color: #4f8ef7;
  margin-bottom: 3px;
  letter-spacing: .02em;
  text-transform: uppercase;
}

#cb-win.human-chat .cb-sender-label { color: #1d4ed8; }

/* ── Typing dots ── */
#cb-dots {
  display: none;
  align-self: flex-start;
  padding: 12px 16px;
  gap: 5px;
  align-items: center;
  background: var(--cb-bot-msg-bg);
  border: 1px solid var(--cb-bot-msg-border);
  border-radius: 5px 18px 18px 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#cb-dots.on { display: flex; }

#cb-win.human-chat #cb-dots {
  background: #fff;
  border-color: #e2e8f0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.cb-d {
  width: 6px;
  height: 6px;
  background: rgba(255,255,255,0.35);
  border-radius: 50%;
  animation: cbD 1.4s ease-in-out infinite;
}

#cb-win.human-chat .cb-d { background: #94a3b8; }

.cb-d:nth-child(2) { animation-delay: .2s; }
.cb-d:nth-child(3) { animation-delay: .4s; }

@keyframes cbD {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40%           { transform: scale(1);  opacity: 1; }
}

/* ── Product cards ── */
.cb-cards   { align-self: flex-start; width: 100%; animation: cbIn .22s ease; }
.cb-scroll  {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.cb-scroll::-webkit-scrollbar       { height: 3px; }
.cb-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

.cb-card {
  flex-shrink: 0;
  width: 145px;
  background: #1a1f2e;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  overflow: hidden;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  transition: box-shadow .18s, transform .18s;
}

.cb-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,.35); transform: translateY(-3px); }

.cb-card img {
  width: 100%;
  height: 108px;
  object-fit: cover;
  background: #0d1117;
  display: block;
}

.cb-card-ph {
  width: 100%;
  height: 108px;
  background: #0d1117;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cb-card-body {
  padding: 9px 11px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.cb-card-name {
  font-size: 12px;
  font-weight: 600;
  color: #e8eaf0;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cb-card-prices {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 5px;
}

.cb-card-price { font-size: 13px; font-weight: 700; color: #4f8ef7; }
.cb-card-was   { font-size: 11px; color: rgba(232,234,240,0.4); text-decoration: line-through; }
.cb-card-sale  { font-size: 10px; font-weight: 700; color: #fff; background: #ef4444; padding: 1px 5px; border-radius: 4px; }

.cb-card-cta {
  display: block;
  margin: 0 9px 9px;
  padding: 6px 0;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  background: linear-gradient(135deg, #4f8ef7 0%, #3b6fd4 100%);
  color: #fff;
  border-radius: 9px;
  text-decoration: none;
  transition: opacity .15s;
}

.cb-card-cta:hover { opacity: .88; color: #fff; }

.cb-card.oos img,
.cb-card.oos .cb-card-ph { opacity: .45; filter: grayscale(50%); }
.cb-card.oos .cb-card-cta { background: rgba(255,255,255,.12); pointer-events: none; }

.cb-card-oos { font-size: 10px; color: rgba(232,234,240,0.4); text-align: center; margin: -3px 9px 5px; }

.cb-more {
  flex-shrink: 0;
  width: 54px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: rgba(232,234,240,0.55);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: var(--cb-font);
  transition: color .15s;
}

.cb-more:hover { color: #e8eaf0; }

.cb-more-ic {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: rgba(232,234,240,0.6);
  transition: background .15s;
}

.cb-more:hover .cb-more-ic { background: #4f8ef7; color: #fff; }

/* ── Error bar ── */
#cb-err {
  display: none;
  background: rgba(239,68,68,0.12);
  color: #f87171;
  font-size: 12px;
  padding: 8px 16px;
  text-align: center;
  border-top: 1px solid rgba(239,68,68,0.2);
  flex-shrink: 0;
}

#cb-win.human-chat #cb-err { background: #fef2f2; color: #ef4444; border-color: #fecaca; }

/* ── Footer input ── */
#cb-foot {
  padding: 12px 14px 14px;
  display: flex;
  gap: 9px;
  align-items: flex-end;
  flex-shrink: 0;
  transition: background .45s ease, border-color .45s ease;
  background: var(--cb-bot-bg);
  border-top: 1px solid rgba(255,255,255,0.07);
}

#cb-win.human-chat #cb-foot { background: #fff; border-top-color: #e2e8f0; }

#cb-inp {
  flex: 1;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 11px 14px;
  font-size: 14px;
  font-family: var(--cb-font);
  resize: none;
  outline: none;
  overflow: hidden;
  max-height: 120px;
  min-height: 48px;
  line-height: 1.6;
  color: #e8eaf0;
  background: rgba(255,255,255,0.06);
  display: block;
  width: 100%;
  transition: border-color .15s, background .45s ease, color .45s ease;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#cb-inp::-webkit-scrollbar { display: none; }

#cb-inp:focus {
  border-color: rgba(79,142,247,0.5);
  background: rgba(255,255,255,0.09);
}

#cb-inp::placeholder { color: rgba(232,234,240,0.3); }

#cb-win.human-chat #cb-inp { background: #f8fafc; border-color: #e2e8f0; color: #1e293b; }
#cb-win.human-chat #cb-inp:focus { border-color: #93c5fd; background: #fff; }
#cb-win.human-chat #cb-inp::placeholder { color: #94a3b8; }

#cb-snd {
  height: 48px;
  flex-shrink: 0;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #4f8ef7 0%, #3b6fd4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(79,142,247,0.35);
  transition: transform .15s, box-shadow .15s, background .45s ease;
  padding: 0 16px;
}

#cb-snd:hover  { transform: scale(1.08); box-shadow: 0 5px 16px rgba(79,142,247,0.45); }
#cb-snd:active { transform: scale(.93); }

#cb-snd:disabled { background: rgba(255,255,255,0.1); box-shadow: none; cursor: not-allowed; }

#cb-win.human-chat #cb-snd       { background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%); box-shadow: 0 3px 10px rgba(29,78,216,0.3); }
#cb-win.human-chat #cb-snd:hover { box-shadow: 0 5px 16px rgba(29,78,216,0.4); }

/* ── Human mode window ── */
#cb-win.human-chat { background: var(--cb-hu-bg); border-color: rgba(29,78,216,0.12); }

/* ── Mobile ── */
@media (max-width: 480px) {
  #cb-win {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 88vh;
    max-height: 88vh;
    border-radius: 24px 24px 0 0;
  }
  #cb-btn { bottom: 18px; right: 18px; }
}
