/* বাজার-বন্ধু AI চ্যাটবট v2.1 — Frontend Styles */
@import url('https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@400;500;600&display=swap');

:root {
  --bb-primary: #F58822;
  --bb-secondary: #D9534F;
  --bb-dark: #1A1A1A;
  --bb-radius: 20px;
  --bb-shadow: 0 8px 32px rgba(0,0,0,.18);
  --bb-font: 'Hind Siliguri', system-ui, sans-serif;
}

/* ── Bubble ── */
#bb-bubble {
  position: fixed; z-index: 99999; cursor: pointer;
  border: none; outline: none; border-radius: 50%;
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(245,136,34,.45);
  transition: transform .2s ease, box-shadow .2s ease;
  font-family: var(--bb-font);
}
#bb-bubble:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(245,136,34,.55); }
#bb-bubble.bb-size-small  { width: 48px; height: 48px; }
#bb-bubble.bb-size-medium { width: 56px; height: 56px; }
#bb-bubble.bb-size-large  { width: 64px; height: 64px; }
#bb-bubble.bb-pos-bottom-right { bottom: 24px; right: 24px; }
#bb-bubble.bb-pos-bottom-left  { bottom: 24px; left: 24px; }
#bb-bubble svg { width: 26px; height: 26px; fill: #fff; }
.bb-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--bb-secondary); color: #fff; border-radius: 50%;
  width: 18px; height: 18px; font-size: 11px;
  display: none; align-items: center; justify-content: center; font-weight: 700;
}

/* ── Chat Window ── */
#bb-window {
  position: fixed; z-index: 99998;
  width: 385px; max-width: calc(100vw - 32px);
  height: 620px; max-height: calc(100vh - 100px);
  border-radius: var(--bb-radius); background: #fff;
  box-shadow: var(--bb-shadow);
  display: flex; flex-direction: column; overflow: hidden;
  font-family: var(--bb-font);
  transition: opacity .25s ease, transform .25s ease;
}
#bb-window.bb-pos-bottom-right { bottom: 90px; right: 24px; }
#bb-window.bb-pos-bottom-left  { bottom: 90px; left: 24px; }
#bb-window.bb-hidden { opacity: 0; pointer-events: none; transform: translateY(14px) scale(.96); }

/* ── Header ── */
.bb-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 12px; flex-shrink: 0;
}
.bb-header-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 2px solid rgba(255,255,255,.3); }
.bb-header-avatar-default {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.bb-header-avatar-default svg { width: 20px; height: 20px; fill: #fff; }
.bb-header-info { flex: 1; min-width: 0; }
.bb-header-name { font-size: 15px; font-weight: 700; color: #fff; }
.bb-header-status {
  font-size: 11px; color: rgba(255,255,255,.9);
  display: flex; align-items: center; gap: 4px; margin-top: 1px;
}
.bb-status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #4ade80;
  animation: bb-pulse 2s ease infinite; flex-shrink: 0;
}
@keyframes bb-pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
.bb-header-close {
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.15); cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0; transition: background .15s;
}
.bb-header-close:hover { background: rgba(255,255,255,.25); }

/* ── Points Bar (ALWAYS VISIBLE) ── */
.bb-points-bar {
  padding: 7px 14px 6px; background: #f8fffe;
  border-bottom: 1px solid #e0f2f1; flex-shrink: 0;
  transition: background .3s;
}
.bb-points-bar.bb-points-warn  { background: #fffbeb; border-bottom-color: #fde68a; }
.bb-points-bar.bb-points-danger { background: #fff5f5; border-bottom-color: #fecaca; }

.bb-points-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 5px;
}
.bb-points-icon { font-size: 12px; }
.bb-points-label { font-size: 11px; color: #555; font-weight: 500; flex: 1; }
.bb-points-pct   { font-size: 11px; color: #999; font-weight: 600; }
.bb-points-track {
  height: 5px; background: #e5e7eb; border-radius: 5px; overflow: hidden;
}
.bb-points-fill {
  height: 100%; border-radius: 5px; background: #22c55e;
  transition: width .5s ease, background .4s ease;
}

/* ── Messages ── */
.bb-messages {
  flex: 1; overflow-y: auto; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 8px;
  scroll-behavior: smooth;
}
.bb-messages::-webkit-scrollbar { width: 4px; }
.bb-messages::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 4px; }

.bb-msg { display: flex; gap: 7px; align-items: flex-end; max-width: 90%; }
.bb-msg.bb-user { align-self: flex-end; flex-direction: row-reverse; }
.bb-msg.bb-bot  { align-self: flex-start; }
.bb-msg.bb-history-msg { opacity: .7; }

.bb-msg-body { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.bb-user .bb-msg-body { align-items: flex-end; }

.bb-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--bb-primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden;
}
.bb-msg-avatar img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.bb-msg-avatar svg { width: 14px; height: 14px; fill: #fff; }

.bb-bubble-msg {
  padding: 9px 13px; border-radius: 16px; font-size: 14px;
  line-height: 1.55; color: #222; max-width: 100%;
  word-break: break-word;
}
.bb-user .bb-bubble-msg { background: var(--bb-primary); color: #fff; border-bottom-right-radius: 4px; }
.bb-bot  .bb-bubble-msg { background: #f3f4f6; border-bottom-left-radius: 4px; }

/* ── Message Meta ── */
.bb-msg-meta {
  display: flex; align-items: center; gap: 4px; margin-top: 3px;
  opacity: 0; transition: opacity .15s;
}
.bb-msg:hover .bb-msg-meta { opacity: 1; }
.bb-user .bb-msg-meta { flex-direction: row-reverse; }
.bb-msg-time { font-size: 10px; color: #bbb; white-space: nowrap; }
.bb-reply-btn {
  background: none; border: 1px solid #e0e0e0; border-radius: 6px;
  font-size: 11px; color: #aaa; cursor: pointer; padding: 1px 6px; line-height: 1.4;
  transition: background .1s, color .1s;
}
.bb-reply-btn:hover { background: #f5f5f5; color: #555; }

/* ── Reply Bubble (inside message) ── */
.bb-reply-bubble {
  border-radius: 8px; padding: 5px 10px; margin-bottom: 4px;
  font-size: 12px; line-height: 1.4; border-left: 3px solid;
  max-width: 100%; word-break: break-word;
}
.bb-reply-user { background: rgba(245,136,34,.1); border-color: var(--bb-primary); color: #7a4a10; }
.bb-reply-bot  { background: #eeeeee; border-color: #bbb; color: #555; }

/* ── Reply Preview Bar ── */
.bb-reply-preview {
  padding: 7px 12px; background: #fff8f0; border-top: 1px solid #f0d0a0;
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.bb-reply-preview-inner { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.bb-reply-preview-icon  { font-size: 14px; color: var(--bb-primary); flex-shrink: 0; }
.bb-reply-preview-text  { font-size: 12px; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.bb-reply-cancel { background: none; border: none; color: #aaa; cursor: pointer; font-size: 16px; flex-shrink: 0; padding: 2px 4px; }
.bb-reply-cancel:hover { color: #555; }

/* ── History Divider ── */
.bb-history-divider { text-align: center; padding: 5px 0; margin: 2px 0; position: relative; }
.bb-history-divider::before { content: ''; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: #eee; }
.bb-history-divider span {
  font-size: 11px; color: #bbb; background: #fff;
  padding: 0 10px; position: relative; z-index: 1;
}

/* ── System Message ── */
.bb-system-msg {
  text-align: center; font-size: 12px; color: #d97706;
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px;
  padding: 7px 12px; margin: 2px 0; align-self: center; max-width: 90%;
}

/* ── Product Cards ── */
.bb-products { display: flex; flex-direction: column; gap: 7px; margin-top: 8px; }
.bb-product-card {
  display: flex; align-items: center; gap: 9px;
  background: #fff; border: 1px solid #e5e5e5; border-radius: 11px;
  padding: 9px; box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.bb-product-card img { width: 50px; height: 50px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.bb-product-img-ph { width: 50px; height: 50px; border-radius: 8px; background: #fff8f0; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.bb-product-info { flex: 1; min-width: 0; }
.bb-product-name  { font-size: 13px; font-weight: 600; color: #222; }
.bb-product-price { font-size: 13px; font-weight: 700; color: var(--bb-primary); }
.bb-product-cat   { font-size: 11px; color: #888; }
.bb-sale-badge    { font-size: 10px; background: #fef3c7; color: #92400e; padding: 1px 5px; border-radius: 4px; display: inline-block; margin-top: 2px; }
.bb-stock         { font-size: 10px; padding: 2px 6px; border-radius: 4px; display: inline-block; margin-top: 2px; }
.bb-in  { background: #e6f9ed; color: #1a7a38; }
.bb-out { background: #fde8e8; color: #b91c1c; }
.bb-add-btn {
  padding: 6px 10px; background: var(--bb-primary); color: #fff;
  border: none; border-radius: 8px; font-size: 12px; cursor: pointer;
  font-weight: 600; white-space: nowrap; font-family: var(--bb-font);
  flex-shrink: 0; transition: opacity .15s;
}
.bb-add-btn:hover { opacity: .88; }
.bb-add-btn:disabled { background: #ccc; cursor: default; }

/* ── AI Order Card ── */
.bb-order-card {
  background: #fff; border: 2px solid #22c55e; border-radius: 12px;
  padding: 14px; margin-top: 10px;
}
.bb-order-card-title {
  font-size: 14px; font-weight: 700; color: #1a7a38;
  margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid #e6f9ed;
}
.bb-order-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: 12px; }
.bb-order-table th { background: #f0fdf4; padding: 5px 8px; text-align: left; color: #555; font-weight: 600; }
.bb-order-table td { padding: 5px 8px; border-bottom: 1px solid #f0f0f0; color: #333; }
.bb-order-totals { font-size: 12px; color: #555; padding: 8px 0; border-top: 1px solid #e5e5e5; }
.bb-order-totals > div { display: flex; justify-content: space-between; margin-bottom: 3px; }
.bb-order-grand { font-size: 13px; font-weight: 700; color: #1a7a38; margin-top: 4px; }
.bb-order-info { font-size: 12px; color: #666; padding: 3px 0; }
.bb-order-actions { display: flex; gap: 8px; margin-top: 10px; }
.bb-order-confirm-btn {
  flex: 1; padding: 8px; background: #22c55e; color: #fff;
  border: none; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: var(--bb-font);
}
.bb-order-confirm-btn:hover { background: #16a34a; }
.bb-order-confirm-btn:disabled { background: #aaa; cursor: not-allowed; }
.bb-order-cancel-btn {
  padding: 8px 14px; background: #f5f5f5; color: #666;
  border: 1px solid #ddd; border-radius: 8px; font-size: 12px;
  cursor: pointer; font-family: var(--bb-font);
}
.bb-order-cancel-btn:hover { background: #fee2e2; color: #b91c1c; }
.bb-order-confirmed { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 12px; font-size: 13px; color: #166534; text-align: center; line-height: 1.6; }
.bb-order-cancelled { font-size: 12px; color: #b91c1c; text-align: center; padding: 8px; }

/* ── Cart Action Banner ── */
.bb-cart-action {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  background: #fff8f0; border: 1px solid #f0d0a0; border-radius: 10px;
  margin-top: 8px; font-size: 13px;
}
.bb-cart-link {
  margin-left: auto; padding: 5px 12px; background: var(--bb-primary);
  color: #fff; border-radius: 8px; text-decoration: none; font-size: 12px; font-weight: 600;
}

/* ── Typing Indicator ── */
.bb-typing .bb-bubble-msg { display: flex; align-items: center; gap: 5px; padding: 12px 16px; }
.bb-dot { width: 7px; height: 7px; border-radius: 50%; background: #aaa; animation: bb-bounce .9s ease infinite; }
.bb-dot:nth-child(2) { animation-delay: .15s; }
.bb-dot:nth-child(3) { animation-delay: .3s; }
@keyframes bb-bounce { 0%,100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-5px); opacity: 1; } }

/* ── Image Preview ── */
.bb-img-preview { display: none; padding: 7px 12px; background: #f9f9f9; border-top: 1px solid #eee; font-size: 12px; color: #666; align-items: center; gap: 8px; flex-shrink: 0; }
.bb-img-preview.bb-active { display: flex; }
.bb-img-preview img { height: 38px; border-radius: 6px; }
.bb-img-clear { background: none; border: none; color: #aaa; cursor: pointer; font-size: 16px; }

/* ── Input Area ── */
.bb-input-area {
  padding: 10px 11px; border-top: 1px solid #f0f0f0;
  display: flex; gap: 7px; align-items: flex-end; flex-shrink: 0; background: #fff;
}
.bb-input-wrap { flex: 1; }
#bb-input {
  width: 100%; border: 1.5px solid #e5e5e5; border-radius: 14px;
  padding: 9px 13px; font-size: 14px; font-family: var(--bb-font);
  resize: none; outline: none; max-height: 100px; overflow-y: auto;
  transition: border-color .15s; line-height: 1.4; box-sizing: border-box; display: block;
}
#bb-input:focus { border-color: var(--bb-primary); }
#bb-input::placeholder { color: #c0c0c0; }
.bb-icon-btn {
  width: 37px; height: 37px; border-radius: 10px; border: none;
  background: #f5f5f5; cursor: pointer; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; transition: background .15s;
}
.bb-icon-btn:hover { background: #ebebeb; }
.bb-icon-btn svg { width: 18px; height: 18px; fill: #777; }
#bb-send-btn {
  width: 37px; height: 37px; border-radius: 10px; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: opacity .15s;
}
#bb-send-btn:hover { opacity: .88; }
#bb-send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* ── Responsive / Mobile position ── */

/* CSS custom props injected by JS on mobile */
:root {
  --bb-mobile-bottom: 80px;
  --bb-mobile-side: 16px;
}

@media (max-width: 480px) {
  #bb-window {
    width: calc(100vw - 16px);
    height: calc(100vh - calc(var(--bb-mobile-bottom) + 10px));
  }
  #bb-window.bb-pos-bottom-right,
  #bb-window.bb-pos-bottom-left,
  #bb-window.bb-pos-bottom-center {
    bottom: calc(var(--bb-mobile-bottom) + 8px);
    left: 8px; right: 8px;
  }
  /* Bubble mobile positioning */
  #bb-bubble.bb-mobile-bottom-right {
    bottom: var(--bb-mobile-bottom) !important;
    right: var(--bb-mobile-side) !important;
    left: auto !important;
  }
  #bb-bubble.bb-mobile-bottom-left {
    bottom: var(--bb-mobile-bottom) !important;
    left: var(--bb-mobile-side) !important;
    right: auto !important;
  }
  #bb-bubble.bb-mobile-bottom-center {
    bottom: var(--bb-mobile-bottom) !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%);
  }
  /* If no override class, apply default bottom offset */
  #bb-bubble:not(.bb-mobile-bottom-right):not(.bb-mobile-bottom-left):not(.bb-mobile-bottom-center) {
    bottom: var(--bb-mobile-bottom) !important;
  }
}
