/* TopDstore AI Chatbot — Chat CSS v2.2 */
:root {
  --topd-gold: #C9A84C;
  --topd-gold-dark: #8B6914;
  --topd-dark:  #111111;
  --topd-dark2: #1A1A1A;
  --topd-dark3: #222222;
  --topd-border: rgba(201,168,76,0.25);
  --topd-text:  #F0EAD6;
  --topd-muted: #8A8070;
  --topd-red:   #E05252;
  --topd-green: #52C378;
  --topd-blue:  #5299E0;
  --topd-z: 999999;
}

/* ── Wrapper ─────────────────────────────────── */
#topd-chatbot {
  position: fixed;
  bottom: 24px;
  z-index: var(--topd-z);
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
}
#topd-chatbot.topd-pos-right { right: 24px; }
#topd-chatbot.topd-pos-left  { left:  24px; }

/* ── Bubble ──────────────────────────────────── */
#topd-bubble {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--topd-gold-dark), var(--topd-gold));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  box-shadow: 0 6px 28px rgba(201,168,76,0.55);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: topd-pulse 3s ease-in-out infinite;
  position: relative;
}
#topd-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 10px 36px rgba(201,168,76,0.7);
  animation: none;
}
@keyframes topd-pulse {
  0%,100% { box-shadow: 0 6px 28px rgba(201,168,76,0.55), 0 0 0 0 rgba(201,168,76,0.35); }
  50%      { box-shadow: 0 6px 28px rgba(201,168,76,0.55), 0 0 0 14px rgba(201,168,76,0); }
}

#topd-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 22px;
  height: 22px;
  background: var(--topd-red);
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  font-family: inherit;
}

/* ── Window ──────────────────────────────────── */
#topd-window {
  position: absolute;
  bottom: 78px;
  width: 360px;
  height: 560px;
  background: var(--topd-dark2);
  border: 1px solid var(--topd-border);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), 0 0 0 1px rgba(201,168,76,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: topd-slideUp 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

/* Position window on correct side */
#topd-chatbot.topd-pos-right #topd-window { right: 0; }
#topd-chatbot.topd-pos-left  #topd-window { left: 0; }

@keyframes topd-slideUp {
  from { opacity:0; transform:translateY(16px) scale(0.96); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}

/* ── Header ──────────────────────────────────── */
.topd-win-header {
  background: linear-gradient(135deg, #0D0D0D 0%, #1A1500 100%);
  border-bottom: 1px solid var(--topd-border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.topd-win-header::before {
  content:'';
  position:absolute;
  inset:0;
  background:radial-gradient(ellipse 70% 100% at 50% 0%, rgba(201,168,76,0.1), transparent 70%);
  pointer-events:none;
}
.topd-win-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.topd-win-avatar {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--topd-gold-dark), var(--topd-gold));
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(201,168,76,0.35);
}
.topd-win-name {
  font-size: 15px;
  font-weight: 700;
  color: #E8C97A;
}
.topd-win-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--topd-muted);
  margin-top: 2px;
}
.topd-online-dot {
  width: 6px;
  height: 6px;
  background: var(--topd-green);
  border-radius: 50%;
  animation: topd-blink 2s infinite;
  flex-shrink: 0;
}
@keyframes topd-blink {
  0%,100% { opacity:1; }
  50%      { opacity:0.35; }
}
.topd-win-actions { display:flex; gap:6px; position:relative; }
.topd-lang-btn {
  background: rgba(201,168,76,0.1);
  border: 1px solid var(--topd-border);
  color: var(--topd-gold);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.2s;
  font-family: inherit;
}
.topd-lang-btn:hover { background:rgba(201,168,76,0.2); }
.topd-close-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--topd-muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.topd-close-btn:hover { background:rgba(224,82,82,0.15); color:var(--topd-red); border-color:rgba(224,82,82,0.3); }

/* ── Messages ────────────────────────────────── */
.topd-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.topd-messages::-webkit-scrollbar { width: 3px; }
.topd-messages::-webkit-scrollbar-thumb { background: var(--topd-border); border-radius: 4px; }

.topd-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: topd-msgIn 0.25s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes topd-msgIn {
  from { opacity:0; transform:translateY(8px) scale(0.96); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
.topd-msg.topd-bot  { align-self: flex-end; }
.topd-msg.topd-user { flex-direction:row-reverse; align-self:flex-start; margin-left:auto; }

.topd-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  align-self: flex-end;
}
.topd-bot  .topd-msg-avatar { background:linear-gradient(135deg, var(--topd-gold-dark), var(--topd-gold)); color:#000; }
.topd-user .topd-msg-avatar { background:var(--topd-dark3); border:1px solid var(--topd-border); color:var(--topd-muted); font-size:12px; }

.topd-msg-inner { display:flex; flex-direction:column; gap:3px; }

.topd-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.7;
}
.topd-bot  .topd-bubble { background:var(--topd-dark3); border:1px solid rgba(201,168,76,0.15); border-bottom-right-radius:4px; color:var(--topd-text); }
.topd-user .topd-bubble { background:linear-gradient(135deg,#1A1200,#2A1E00); border:1px solid rgba(201,168,76,0.3); border-bottom-left-radius:4px; color:var(--topd-text); }

.topd-msg-time { font-size:10px; color:var(--topd-muted); padding:0 4px; }
.topd-user .topd-msg-time { text-align:right; }

/* Quick replies */
.topd-quick-replies { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.topd-quick-btn {
  background: none;
  border: 1px solid var(--topd-border);
  color: #E8C97A;
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.18s;
}
.topd-quick-btn:hover { background:rgba(201,168,76,0.1); border-color:var(--topd-gold); transform:translateY(-1px); }

/* Product cards */
.topd-products-wrap { display:flex; gap:8px; flex-wrap:wrap; margin-top:8px; }
.topd-product-card {
  background: var(--topd-dark3);
  border: 1px solid var(--topd-border);
  border-radius: 12px;
  overflow: hidden;
  width: 160px;
  transition: all 0.2s;
}
.topd-product-card:hover { border-color:var(--topd-gold); transform:translateY(-2px); box-shadow:0 6px 20px rgba(201,168,76,0.15); }
.topd-product-img {
  width: 100%;
  height: 90px;
  background: linear-gradient(135deg,#1A1400,#2A2000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  overflow: hidden;
}
.topd-product-img img { width:100%; height:100%; object-fit:cover; }
.topd-product-info { padding: 9px; }
.topd-product-name  { font-size:12px; font-weight:700; color:var(--topd-text); margin-bottom:3px; line-height:1.4; }
.topd-product-price { font-size:13px; font-weight:900; color:var(--topd-gold); margin-bottom:7px; }
.topd-product-btn {
  display: block;
  width: 100%;
  background: linear-gradient(135deg, var(--topd-gold-dark), var(--topd-gold));
  color: #000;
  text-align: center;
  padding: 6px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.2s;
}
.topd-product-btn:hover { opacity:0.88; }

/* Order card */
.topd-order-card { background:var(--topd-dark3); border:1px solid var(--topd-border); border-radius:12px; padding:12px; margin-top:6px; }
.topd-order-id   { font-size:12px; color:var(--topd-gold); font-weight:700; margin-bottom:8px; letter-spacing:0.5px; }
.topd-order-row  { display:flex; align-items:center; gap:7px; margin-bottom:4px; font-size:12px; color:var(--topd-text); }
.topd-order-items { font-size:11px; color:var(--topd-muted); margin:6px 0; padding:6px 8px; background:rgba(255,255,255,0.03); border-radius:6px; line-height:1.8; }
.topd-order-note { font-size:11px; color:var(--topd-muted); margin-top:8px; line-height:1.6; }
.topd-badge { padding:2px 8px; border-radius:20px; font-size:10px; font-weight:700; }
.topd-badge-processing { background:rgba(82,153,224,0.2);  color:var(--topd-blue);  border:1px solid rgba(82,153,224,0.3); }
.topd-badge-shipped    { background:rgba(201,168,76,0.15); color:var(--topd-gold);  border:1px solid rgba(201,168,76,0.3); }
.topd-badge-completed  { background:rgba(82,195,120,0.15); color:var(--topd-green); border:1px solid rgba(82,195,120,0.3); }
.topd-badge-pending    { background:rgba(224,82,82,0.15);  color:var(--topd-red);   border:1px solid rgba(224,82,82,0.3); }
.topd-badge-cancelled  { background:rgba(255,255,255,0.07);color:var(--topd-muted); border:1px solid rgba(255,255,255,0.15); }

/* Escalation */
.topd-escalation { background:rgba(224,82,82,0.06); border:1px solid rgba(224,82,82,0.25); border-radius:12px; padding:11px; margin-top:7px; display:flex; align-items:center; gap:9px; }
.topd-escalation-icon { font-size:18px; flex-shrink:0; }
.topd-escalation-text { flex:1; }
.topd-escalation-text strong { display:block; color:var(--topd-red); font-size:12px; margin-bottom:3px; }
.topd-escalation-text span   { font-size:11px; color:var(--topd-muted); }
.topd-wa-btn { background:#25D366; color:#fff; border:none; padding:7px 11px; border-radius:8px; font-size:11px; font-weight:700; cursor:pointer; white-space:nowrap; font-family:inherit; transition:background 0.2s; }
.topd-wa-btn:hover { background:#1fb855; }

/* Typing */
.topd-typing { display:flex; gap:4px; padding:10px 14px; background:var(--topd-dark3); border:1px solid rgba(201,168,76,0.15); border-radius:14px; border-bottom-right-radius:4px; width:fit-content; }
.topd-typing-dot { width:6px; height:6px; background:var(--topd-gold); border-radius:50%; opacity:0.45; }
.topd-typing-dot:nth-child(1) { animation:topd-bounce 1.2s 0s   infinite; }
.topd-typing-dot:nth-child(2) { animation:topd-bounce 1.2s 0.2s infinite; }
.topd-typing-dot:nth-child(3) { animation:topd-bounce 1.2s 0.4s infinite; }
@keyframes topd-bounce {
  0%,60%,100% { transform:translateY(0); opacity:0.35; }
  30%          { transform:translateY(-5px); opacity:1; }
}

/* ── Input ───────────────────────────────────── */
.topd-input-area { border-top:1px solid var(--topd-border); background:var(--topd-dark3); padding:11px 13px 9px; flex-shrink:0; }
.topd-input-row  { display:flex; gap:8px; align-items:flex-end; }
.topd-input {
  flex: 1;
  background: var(--topd-dark2);
  border: 1px solid var(--topd-border);
  border-radius: 12px;
  color: var(--topd-text);
  font-family: inherit;
  font-size: 13px;
  padding: 10px 13px;
  outline: none;
  resize: none;
  min-height: 42px;
  max-height: 100px;
  transition: border-color 0.2s;
}
.topd-input:focus { border-color:var(--topd-gold); box-shadow:0 0 0 3px rgba(201,168,76,0.08); }
.topd-input::placeholder { color:var(--topd-muted); }

.topd-send-btn {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--topd-gold-dark), var(--topd-gold));
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 3px 12px rgba(201,168,76,0.3);
  transition: all 0.2s;
}
.topd-send-btn:hover   { transform:scale(1.06); box-shadow:0 5px 18px rgba(201,168,76,0.45); }
.topd-send-btn:disabled { opacity:0.45; cursor:not-allowed; transform:none; }

.topd-input-footer { display:flex; justify-content:flex-end; font-size:9px; color:var(--topd-muted); margin-top:5px; letter-spacing:0.5px; }

/* ── Mobile ──────────────────────────────────── */
@media (max-width: 440px) {
  #topd-window {
    width: calc(100vw - 20px);
    height: calc(100svh - 96px);
    bottom: 74px;
    border-radius: 16px;
  }
  #topd-chatbot.topd-pos-right #topd-window { right: 0; }
  #topd-chatbot.topd-pos-left  #topd-window { left:  0; }
}
