/* =============================================================
   CAPITAL FOOD — PACKAGING & PRIVATE-LABEL ASSISTANT WIDGET
   ============================================================= */

.rgb-chat {
  --chat-w: 384px;
  --chat-h: 560px;
  --chat-launcher: 58px;
  /* Gap, bottom and size must match .rgb-whatsapp-btn */
  --chat-gap: 24px;
  --chat-bottom: 24px;
  --chat-whatsapp: 58px;
  --chat-pair-gap: 14px;
  --chat-panel-bottom: calc(var(--chat-bottom) + var(--chat-launcher) + 12px);
}

/* ================= LAUNCHER ================= */
.rgb-chat-launcher {
  position: fixed;
  z-index: 1045;
  bottom: var(--chat-bottom);
  inset-inline-start: calc(var(--chat-gap) + var(--chat-whatsapp) + var(--chat-pair-gap));
  width: var(--chat-launcher);
  height: var(--chat-launcher);
  border: 1px solid rgba(198, 161, 91, 0.42);
  border-radius: 50%;
  background: var(--grad-primary);
  color: var(--cf-warm-cream);
  font-size: 1.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-btn);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), opacity .2s var(--ease);
}
.rgb-chat-launcher:hover { transform: scale(1.07); box-shadow: var(--shadow-btn-hover); }
.rgb-chat-launcher:active { transform: scale(.98); }

/* Attention ring until first open */
.rgb-chat-launcher::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--cf-premium-gold);
  opacity: 0;
  animation: rgb-chat-ring 2.8s var(--ease) infinite;
}
.rgb-chat.is-used .rgb-chat-launcher::after { animation: none; content: none; }

@keyframes rgb-chat-ring {
  0%   { transform: scale(1);    opacity: .55; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

.rgb-chat.is-open .rgb-chat-launcher {
  opacity: 0;
  visibility: hidden;
  transform: scale(.7);
  pointer-events: none;
}

/* ================= PANEL SHELL ================= */
.rgb-chat-panel {
  position: fixed;
  z-index: 1045;
  bottom: var(--chat-panel-bottom);
  inset-inline-start: var(--chat-gap);
  width: var(--chat-w);
  height: var(--chat-h);
  max-height: calc(100vh - var(--rgb-header-h) - var(--chat-panel-bottom) - 16px);
  max-height: calc(100dvh - var(--rgb-header-h) - var(--chat-panel-bottom) - 16px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-blue);
  transform-origin: bottom var(--chat-origin-x, left);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.96);
  transition: opacity .28s var(--ease), transform .28s var(--ease), visibility .28s;
}
html[dir="rtl"] .rgb-chat-panel { --chat-origin-x: right; }

.rgb-chat.is-open .rgb-chat-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ================= HEADER ================= */
.rgb-chat-head {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .85rem 1rem;
  background: var(--grad-primary);
  color: var(--cf-warm-cream);
  flex: 0 0 auto;
}

.rgb-chat-avatar {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(16, 45, 36, 0.65);
  border: 1px solid rgba(198, 161, 91, 0.50);
  color: var(--cf-premium-gold);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  padding: 5px;
}
.rgb-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.rgb-chat-head-text { min-width: 0; flex: 1; }
.rgb-chat-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: .96rem;
  line-height: 1.3;
  color: var(--cf-warm-cream);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rgb-chat-status {
  display: flex; align-items: center; gap: .35rem;
  font-size: .74rem;
  color: rgba(245, 240, 230, 0.84);
  line-height: 1.4;
}
.rgb-chat-status::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--cf-fresh-olive);
  flex: 0 0 auto;
}

.rgb-chat-head-actions { display: flex; gap: .25rem; flex: 0 0 auto; }
.rgb-chat-icon-btn {
  width: 32px; height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: var(--cf-warm-cream);
  font-size: .95rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background-color .2s var(--ease);
}
.rgb-chat-icon-btn:hover { background: rgba(255, 255, 255, 0.28); }

/* ================= MESSAGE LOG ================= */
.rgb-chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  background: var(--bg-soft);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.rgb-chat-log::-webkit-scrollbar { width: 6px; }
.rgb-chat-log::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
.rgb-chat-log::-webkit-scrollbar-track { background: transparent; }

.rgb-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: rgb-chat-pop .28s var(--ease) both;
}
.rgb-chat-msg.is-bot { align-self: flex-start; }
.rgb-chat-msg.is-user { align-self: flex-end; align-items: flex-end; }

@keyframes rgb-chat-pop {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.rgb-chat-bubble {
  padding: .72rem .95rem;
  border-radius: var(--radius-md);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  white-space: pre-line;
}
.rgb-chat-msg.is-bot .rgb-chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-start-start-radius: 4px;
}
.rgb-chat-msg.is-user .rgb-chat-bubble {
  background: var(--grad-primary);
  color: var(--cf-pure-white);
  border-start-end-radius: 4px;
  box-shadow: var(--shadow-btn);
}

.rgb-chat-meta {
  font-size: .68rem;
  color: var(--text-3);
  margin-top: .25rem;
  padding-inline: .35rem;
}

.rgb-chat-matched {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .82rem;
  color: var(--accent-gold);
  margin-bottom: .3rem;
}

.rgb-chat-action {
  display: inline-flex; align-items: center; gap: .4rem;
  margin-top: .6rem;
  padding: .4rem .85rem;
  border: 1px solid var(--border-gold);
  border-radius: 999px;
  background: var(--accent-gold-bg);
  color: var(--accent-gold);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .8rem;
  transition: background-color .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
}
.rgb-chat-action:hover {
  background: var(--accent-tint-strong);
  border-color: var(--cf-forest-green);
  color: var(--text-1);
}

/* ================= CHIPS ================= */
.rgb-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .55rem;
}
.rgb-chat-chip {
  display: inline-flex; align-items: center; gap: .35rem;
  max-width: 100%;
  padding: .38rem .8rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: .82rem;
  line-height: 1.5;
  text-align: start;
  transition: background-color .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease), transform .2s var(--ease);
}
.rgb-chat-chip:hover {
  background: var(--accent-tint);
  border-color: var(--cf-forest-green);
  color: var(--text-1);
  transform: translateY(-1px);
}
.rgb-chat-chip i { color: var(--cf-premium-gold); font-size: .9rem; flex: 0 0 auto; }

/* ================= TYPING INDICATOR ================= */
.rgb-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .75rem .95rem;
}
.rgb-chat-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--cf-sage-green);
  opacity: .55;
  animation: rgb-chat-dot 1.1s var(--ease) infinite;
}
.rgb-chat-typing span:nth-child(2) { animation-delay: .16s; }
.rgb-chat-typing span:nth-child(3) { animation-delay: .32s; }

@keyframes rgb-chat-dot {
  0%, 60%, 100% { transform: translateY(0);    opacity: .45; }
  30%          { transform: translateY(-4px); opacity: 1; }
}

/* ================= QUICK QUESTIONS STRIP ================= */
.rgb-chat-quick {
  flex: 0 0 auto;
  padding: .6rem .9rem 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  max-height: 6.5rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.rgb-chat-quick::-webkit-scrollbar { width: 6px; }
.rgb-chat-quick::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
.rgb-chat-quick:empty { display: none; }
.rgb-chat-quick-label {
  display: block;
  font-size: .7rem;
  color: var(--text-3);
  margin-bottom: .35rem;
}
.rgb-chat-quick .rgb-chat-chips { margin-top: 0; padding-bottom: .6rem; }

/* ================= COMPOSER ================= */
.rgb-chat-form {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem .9rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.rgb-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .6rem 1rem;
  color: var(--text-1);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  transition: border-color .2s var(--ease), background-color .2s var(--ease);
}
.rgb-chat-input::placeholder { color: var(--text-3); }
.rgb-chat-input:focus { outline: none; border-color: var(--cf-forest-green); background: var(--surface); }
.rgb-chat-input:focus-visible { outline: 2px solid var(--cf-premium-gold); outline-offset: 2px; }

.rgb-chat-send {
  width: 42px; height: 42px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: var(--grad-primary);
  color: var(--cf-pure-white);
  font-size: 1.05rem;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-btn);
  transition: transform .2s var(--ease), filter .2s var(--ease), opacity .2s var(--ease);
}
.rgb-chat-send:hover:not(:disabled) { transform: scale(1.06); filter: brightness(1.06); }
.rgb-chat-send:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
html[dir="rtl"] .rgb-chat-send i { transform: scaleX(-1); }

.rgb-chat-foot {
  flex: 0 0 auto;
  padding: 0 .9rem .6rem;
  background: var(--surface);
  font-size: .68rem;
  color: var(--text-3);
  text-align: center;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 767.98px) {
  .rgb-chat {
    --chat-launcher: 52px;
    --chat-gap: 18px;
    --chat-bottom: 18px;
    --chat-whatsapp: 52px;
    --chat-pair-gap: 12px;
  }
  .rgb-chat-launcher { font-size: 1.35rem; }

  .rgb-chat-panel {
    width: auto;
    inset-inline: 12px;
    height: auto;
    top: calc(var(--rgb-header-h) + 10px);
    max-height: none;
  }
}

@media (max-width: 575.98px) {
  .rgb-chat-panel {
    inset-inline: 8px;
    bottom: 12px;
    top: calc(var(--rgb-header-h) + 8px);
    border-radius: var(--radius-md);
  }
  .rgb-chat-log { padding: .85rem; gap: .7rem; }
  .rgb-chat-msg { max-width: 92%; }
  .rgb-chat-bubble { font-size: .88rem; }
  .rgb-chat-head { padding: .75rem .85rem; }
}

@media (max-height: 520px) {
  .rgb-chat-panel { top: calc(var(--rgb-header-h) + 6px); bottom: 10px; height: auto; max-height: none; }
  .rgb-chat-quick { max-height: 4.2rem; }
}
