/*
 * Restonic Bed Advisor — Widget Styles
 * © 2025 Codexist Labs — https://codexist.co.za
 *
 * Theming: override --rba-* custom properties on
 * #celabs-rba-wrapper or .celabs-rba-inline in your theme stylesheet.
 */

/* ═══════════════════════════════════════════════════════
   Design tokens
   ═══════════════════════════════════════════════════════ */
:root {
  --rba-primary:       #c8102e;
  --rba-primary-dark:  #a00d24;
  --rba-primary-light: rgba(200, 16, 46, 0.10);
  --rba-bg:            #ffffff;
  --rba-bg-surface:    #f6f6f7;
  --rba-text:          #1a1a1a;
  --rba-text-muted:    #6b7280;
  --rba-border:        #e5e7eb;
  --rba-shadow:        0 12px 40px rgba(0, 0, 0, 0.16);
  --rba-radius:        18px;
  --rba-radius-sm:     10px;
  --rba-w:             380px;
  --rba-h:             580px;
  --rba-fab:           58px;
  --rba-z:             999999;
  --rba-font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --rba-transition:    .22s cubic-bezier(.4, 0, .2, 1);
}

/* ═══════════════════════════════════════════════════════
   Floating wrapper
   ═══════════════════════════════════════════════════════ */
#celabs-rba-wrapper {
  position: fixed;
  z-index: var(--rba-z);
  font-family: var(--rba-font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
#celabs-rba-wrapper.rba-pos-bottom-right { bottom: 24px; right: 24px; }
#celabs-rba-wrapper.rba-pos-bottom-left  { bottom: 24px; left:  24px; }

/* ── Toggle FAB ──────────────────────────────────────── */
.rba-toggle {
  width:  var(--rba-fab);
  height: var(--rba-fab);
  border-radius: 50%;
  background: var(--rba-primary);
  border: none;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(200, 16, 46, .40);
  transition: background var(--rba-transition), transform var(--rba-transition), box-shadow var(--rba-transition);
  position: relative;
  padding: 0;
}
.rba-toggle:hover  { background: var(--rba-primary-dark); transform: scale(1.07); }
.rba-toggle:active { transform: scale(.96); }

.rba-icon {
  width: 24px;
  height: 24px;
  position: absolute;
  transition: opacity var(--rba-transition), transform var(--rba-transition);
}
.rba-icon--close  { opacity: 0; transform: rotate(-45deg) scale(.8); }

.rba-toggle.is-open .rba-icon--chat  { opacity: 0; transform: rotate(45deg) scale(.8); }
.rba-toggle.is-open .rba-icon--close { opacity: 1; transform: rotate(0) scale(1); }

/* ── Floating chat window ────────────────────────────── */
.rba-pos-bottom-right .rba-window,
.rba-pos-bottom-left  .rba-window {
  position: absolute;
  bottom: calc(var(--rba-fab) + 14px);
  width: var(--rba-w);
  height: var(--rba-h);
  background: var(--rba-bg);
  border-radius: var(--rba-radius);
  box-shadow: var(--rba-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Closed state */
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px) scale(.96);
  transition: opacity var(--rba-transition), transform var(--rba-transition);
}
.rba-pos-bottom-right .rba-window { right: 0; }
.rba-pos-bottom-left  .rba-window { left:  0; }

.rba-window.is-open {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0) scale(1);
}

/* ═══════════════════════════════════════════════════════
   Inline (shortcode) container
   ═══════════════════════════════════════════════════════ */
.celabs-rba-inline {
  font-family: var(--rba-font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  border-radius: var(--rba-radius);
  box-shadow: var(--rba-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--rba-bg);
  max-width: 100%;
}

/* ═══════════════════════════════════════════════════════
   Shared: Header
   ═══════════════════════════════════════════════════════ */
.rba-header {
  background: var(--rba-primary);
  color: #fff;
  padding: 14px 16px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
}
.rba-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.rba-avatar { font-size: 26px; line-height: 1; flex-shrink: 0; }
.rba-header-text { min-width: 0; }
.rba-title {
  display: block;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rba-subtitle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  opacity: .85;
  margin-top: 1px;
}
.rba-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, .3);
}
.rba-header-actions { display: flex; gap: 4px; flex-shrink: 0; }
.rba-btn-icon {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 7px;
  color: #fff;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  transition: background var(--rba-transition);
}
.rba-btn-icon:hover { background: rgba(255,255,255,.28); }
.rba-btn-icon svg { width: 15px; height: 15px; }

/* ═══════════════════════════════════════════════════════
   Shared: Messages
   ═══════════════════════════════════════════════════════ */
.rba-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.rba-messages::-webkit-scrollbar { width: 4px; }
.rba-messages::-webkit-scrollbar-track { background: transparent; }
.rba-messages::-webkit-scrollbar-thumb { background: var(--rba-border); border-radius: 4px; }

/* ── Message rows ────────────────────────────────────── */
.rba-msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 88%;
  animation: rba-msg-in .18s ease-out both;
}
.rba-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.rba-msg--bot  { align-self: flex-start; }

@keyframes rba-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* ── Bubbles ─────────────────────────────────────────── */
.rba-bubble {
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}
.rba-msg--user .rba-bubble {
  background: var(--rba-primary);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.rba-msg--bot .rba-bubble {
  background: var(--rba-bg-surface);
  color: var(--rba-text);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--rba-border);
}
.rba-bubble--error {
  background: #fff0f1 !important;
  color: #b91c1c !important;
  border-color: #fecaca !important;
}
.rba-bubble strong { font-weight: 600; }
.rba-bubble a { color: var(--rba-primary); text-decoration: underline; }

/* ═══════════════════════════════════════════════════════
   Shared: Typing indicator
   ═══════════════════════════════════════════════════════ */
.rba-typing {
  padding: 0 14px 6px;
  animation: rba-msg-in .18s ease-out both;
}
.rba-typing .rba-bubble {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 10px 16px;
}
.rba-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rba-text-muted);
  animation: rba-bounce 1.1s ease-in-out infinite;
}
.rba-dot:nth-child(2) { animation-delay: .16s; }
.rba-dot:nth-child(3) { animation-delay: .32s; }

@keyframes rba-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* ═══════════════════════════════════════════════════════
   Shared: Input area
   ═══════════════════════════════════════════════════════ */
.rba-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 10px 14px;
  border-top: 1px solid var(--rba-border);
  background: var(--rba-bg);
  flex-shrink: 0;
}
.rba-input {
  flex: 1;
  border: 1.5px solid var(--rba-border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13.5px;
  line-height: 1.5;
  font-family: var(--rba-font);
  resize: none;
  outline: none;
  max-height: 110px;
  overflow-y: auto;
  color: var(--rba-text);
  background: var(--rba-bg-surface);
  transition: border-color var(--rba-transition), background var(--rba-transition);
  box-sizing: border-box;
}
.rba-input:focus { border-color: var(--rba-primary); background: var(--rba-bg); }
.rba-input::placeholder { color: var(--rba-text-muted); }

.rba-btn-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--rba-primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--rba-transition), transform var(--rba-transition);
  padding: 0;
}
.rba-btn-send:hover:not(:disabled) { background: var(--rba-primary-dark); transform: scale(1.06); }
.rba-btn-send:disabled { opacity: .4; cursor: not-allowed; }
.rba-btn-send svg { width: 16px; height: 16px; }

/* ═══════════════════════════════════════════════════════
   Shared: Footer
   ═══════════════════════════════════════════════════════ */
.rba-footer {
  text-align: center;
  font-size: 11px;
  color: var(--rba-text-muted);
  padding: 5px 14px 8px;
  border-top: 1px solid var(--rba-border);
  flex-shrink: 0;
  background: var(--rba-bg);
}
.rba-footer a { color: var(--rba-primary); text-decoration: none; }
.rba-footer a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════
   Responsive — mobile
   ═══════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  #celabs-rba-wrapper.rba-pos-bottom-right,
  #celabs-rba-wrapper.rba-pos-bottom-left {
    bottom: 0;
    right:  0;
    left:   0;
  }

  .rba-pos-bottom-right .rba-window,
  .rba-pos-bottom-left  .rba-window {
    position: fixed;
    bottom: var(--rba-fab);
    left:   0;
    right:  0;
    width:  100%;
    height: calc(100vh - var(--rba-fab) - 16px);
    border-bottom-left-radius:  0;
    border-bottom-right-radius: 0;
  }

  .rba-toggle {
    position: fixed;
    bottom: 16px;
    right: 16px;
  }

  .rba-pos-bottom-left .rba-toggle {
    right: auto;
    left: 16px;
  }

  .celabs-rba-inline {
    border-radius: var(--rba-radius-sm);
  }
}

/* ═══════════════════════════════════════════════════════
   Reduced motion
   ═══════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .rba-window,
  .rba-toggle,
  .rba-msg,
  .rba-dot      { animation: none !important; transition: none !important; }
}

/* ── Voice input (v1.2.0) ─────────────────────────────────────────────── */
.rba-btn-mic {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--rba-primary, #c8102e);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.rba-btn-mic:hover { background: var(--rba-primary-light, rgba(200,16,46,.1)); }
.rba-btn-mic svg { width: 18px; height: 18px; }
.rba-btn-mic.is-listening {
  background: var(--rba-primary, #c8102e);
  color: #fff;
  animation: rba-pulse 1.4s ease-out infinite;
}
@keyframes rba-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(200, 16, 46, .45); }
  70%  { box-shadow: 0 0 0 10px rgba(200, 16, 46, 0); }
  100% { box-shadow: 0 0 0 0 rgba(200, 16, 46, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .rba-btn-mic.is-listening { animation: none; }
}

/* ── Recommendation links (v1.2.0) ────────────────────────────────────── */
.rba-bubble a.rba-link {
  display: inline-block;
  margin-top: 4px;
  padding: 6px 12px;
  background: var(--rba-primary, #c8102e);
  color: #fff !important;
  border-radius: 16px;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s ease;
}
.rba-bubble a.rba-link:hover { background: var(--rba-primary-dark, #a90d27); }
