/* Ben chat widget — themed to Cirrusly Atmospheric
 *
 * Color tokens bridge to theme.json via --wp--preset--* vars when embedded
 * in WordPress. Hex fallbacks fire when loaded standalone (ben.cirruslyweather.com).
 */

/* Token bridge — inherit from Atmospheric when on-site */
.ben-floating-btn,
.ben-chat-window {
  --ben-primary:      var(--wp--preset--color--primary,      #0945c8);
  --ben-dark:         var(--wp--preset--color--primary-dark, #12123F);
  --ben-secondary:    var(--wp--preset--color--secondary,    #DBE6EE);
  --ben-tertiary:     var(--wp--preset--color--tertiary,     #F1F4FA);
  --ben-sun:          var(--wp--preset--color--sun,          #F9D13E);
  --ben-gray-200:     var(--wp--preset--color--gray-200,     #e9ecef);
  --ben-gray-500:     var(--wp--preset--color--gray-500,     #6c757d);
  --ben-gray-700:     var(--wp--preset--color--gray-700,     #495057);
  --ben-gray-900:     var(--wp--preset--color--gray-900,     #212529);
  --ben-font-body:    var(--wp--preset--font-family--primary,  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  --ben-font-heading: var(--wp--preset--font-family--heading,  'Raleway', -apple-system, sans-serif);
}

@keyframes ben-slide-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes ben-badge-pulse {
  0%, 100% { transform: scale(1);    opacity: 1;    }
  50%       { transform: scale(1.15); opacity: 0.65; }
}

/* `.cirrusly-ben-highlight` (the highlight_element pulse) is defined once in
   the theme's assets/css/ben-chat.css using the on-brand sun-yellow accent.
   It lived here too with a conflicting blue keyframe; removed to de-duplicate. */

/* Expanding ring that fades out — fired on load, new message, badge */
@keyframes ben-btn-ring {
  0%   { box-shadow: 0 4px 16px rgba(9, 69, 200, 0.35), 0 0 0 2px rgba(255,255,255,0.85), 0 0 0 3px  rgba(9, 69, 200, 0.8); }
  100% { box-shadow: 0 4px 16px rgba(9, 69, 200, 0.35), 0 0 0 2px rgba(255,255,255,0.85), 0 0 0 14px rgba(9, 69, 200, 0);   }
}

.ben-floating-btn--ring {
  animation: ben-btn-ring 0.85s ease-out forwards;
}

/* ── Floating launcher button ────────────────────────────────── */

.ben-floating-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--ben-primary), var(--ben-dark));
  /* white ring keeps the profile pic distinct against any background */
  box-shadow: 0 4px 16px rgba(9, 69, 200, 0.35), 0 0 0 2px rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2147483647;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.ben-floating-btn img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 999px;
}

.ben-floating-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(9, 69, 200, 0.45), 0 0 0 2px rgba(255,255,255,0.85);
}

.ben-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid white;
  background: #ef4444;
  animation: ben-badge-pulse 1.5s infinite;
}

.ben-chat-invite {
  position: fixed;
  right: 24px;
  bottom: 92px;
  max-width: 260px;
  padding: 14px 16px;
  border: 1px solid var(--ben-secondary);
  border-radius: 18px;
  background: white;
  box-shadow: 0 12px 28px rgba(18, 18, 63, 0.16);
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  cursor: pointer;
  z-index: 2147483646;
  animation: ben-slide-in 0.2s ease;
}

.ben-chat-invite__title {
  font-family: var(--ben-font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ben-dark);
}

.ben-chat-invite__copy {
  font-family: var(--ben-font-body);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--ben-gray-700);
}

/* ── Chat window ─────────────────────────────────────────────── */

.ben-chat-window {
  position: fixed;
  right: 24px;
  bottom: 96px;
  width: min(380px, calc(100vw - 24px));
  height: min(600px, calc(100vh - 120px));
  background: white;
  border: 1px solid var(--ben-secondary);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(18, 18, 63, 0.12);
  overflow: hidden;
  display: none;
  flex-direction: column;
  z-index: 2147483647;
  font-family: var(--ben-font-body);
}

.ben-chat-window-open {
  display: flex;
  animation: ben-slide-in 0.2s ease;
}

/* ── Window header ───────────────────────────────────────────── */

.ben-window-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--ben-primary), var(--ben-dark));
  color: white;
  font-family: var(--ben-font-body);
}

.ben-header-left,
.ben-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ben-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
}

.ben-avatar {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ben-header-info {
  display: flex;
  flex-direction: column;
}

.ben-header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.ben-header-name {
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--ben-font-heading);
}

.ben-header-subtitle {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.8);
}

.ben-status-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  cursor: help;
  user-select: none;
}

.ben-status-help::before {
  content: '?';
}

.ben-status-help:hover,
.ben-status-help:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.ben-close-btn,
.ben-full-btn {
  border: none;
  cursor: pointer;
}

.ben-close-btn {
  background: transparent;
  color: white;
  font-size: 1.5rem;
  line-height: 1;
}

.ben-full-btn {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--ben-font-body);
}

.ben-full-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ── Chat log ────────────────────────────────────────────────── */

.ben-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: white;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ben-chat-disclosure {
  padding: 10px 16px 0;
  color: var(--ben-gray-700);
  font-size: 0.69rem;
  line-height: 1.45;
}

.ben-msg {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
  font-family: var(--ben-font-body);
}

.ben-msg-user {
  align-self: flex-end;
  background: var(--ben-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.ben-msg-ben {
  align-self: flex-start;
  background: var(--ben-tertiary);
  color: var(--ben-dark);
  border-bottom-left-radius: 4px;
}

.ben-msg-thinking {
  color: var(--ben-gray-500);
  font-style: italic;
}

.ben-msg-ben a {
  color: var(--ben-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ben-rich-paragraph {
  margin: 0;
}

.ben-rich-paragraph + .ben-rich-paragraph {
  margin-top: 0.65em;
}

.ben-rich-list {
  margin: 0.5em 0;
  padding-left: 1.25em;
}

.ben-msg-system {
  align-self: center;
  background: var(--ben-tertiary);
  color: var(--ben-gray-500);
  font-size: 0.8rem;
  text-align: center;
}

/* ── Product card ────────────────────────────────────────────── */

.ben-product-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--ben-secondary);
  border-radius: 12px;
  background: var(--ben-tertiary);
  text-decoration: none;
  color: var(--ben-dark);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  align-self: flex-start;
  width: 100%;
  font-family: var(--ben-font-body);
  box-sizing: border-box;
}

.ben-product-card:hover {
  border-color: var(--ben-primary);
  box-shadow: 0 2px 8px rgba(9, 69, 200, 0.1);
}

.ben-product-card__thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.ben-product-card__thumb-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: var(--ben-secondary);
  flex-shrink: 0;
}

.ben-product-card__info {
  flex: 1;
  min-width: 0;
}

.ben-product-card__name {
  margin: 0 0 2px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--ben-font-heading);
  color: var(--ben-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ben-product-card__price {
  margin: 0 0 6px;
  font-size: 0.8rem;
  color: var(--ben-gray-700);
}

.ben-product-card__cta {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ben-primary);
}

/* ── Input row ───────────────────────────────────────────────── */

.ben-chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  padding-top: 10px;
  border-top: 1px solid var(--ben-secondary);
  background: white;
}

.ben-msg-input,
.ben-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--ben-gray-200);
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: var(--ben-font-body);
  outline: none;
  color: var(--ben-gray-900);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ben-msg-input:focus,
.ben-input:focus {
  border-color: var(--ben-primary);
  box-shadow: 0 0 0 3px rgba(9, 69, 200, 0.08);
}

.ben-send-btn,
.ben-btn {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--ben-font-body);
  font-weight: 700;
  transition: background 0.15s;
  white-space: nowrap;
}

.ben-send-btn,
.ben-btn-primary {
  padding: 10px 14px;
  background: var(--ben-primary);
  color: white;
  font-size: 0.875rem;
}

.ben-send-btn:hover,
.ben-btn-primary:hover {
  background: var(--ben-dark);
}

/* ── Floating panel (popout) ─────────────────────────────────── */

.ben-panel-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ben-panel-container.ben-panel-open {
  pointer-events: auto;
}

.ben-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 18, 63, 0.25);
  backdrop-filter: blur(2px);
}

.ben-panel {
  position: absolute;
  inset: 0;
  background: white;
  display: flex;
  flex-direction: column;
  animation: ben-slide-in 0.18s ease;
}

.ben-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--ben-primary), var(--ben-dark));
  color: white;
  font-weight: 700;
  font-family: var(--ben-font-heading);
}

.ben-panel-close {
  background: transparent;
  color: white;
  font-size: 1.5rem;
  border: none;
  cursor: pointer;
  line-height: 1;
}

.ben-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: var(--ben-font-body);
}

.ben-panel-copy {
  margin: 0;
  color: var(--ben-gray-700);
  font-size: 0.9rem;
  line-height: 1.5;
}

.ben-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ben-dark);
  font-family: var(--ben-font-body);
}

.ben-panel-actions {
  display: flex;
  justify-content: flex-end;
}

.ben-panel-feedback {
  display: none;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--ben-tertiary);
  color: var(--ben-gray-700);
  font-size: 0.85rem;
  font-family: var(--ben-font-body);
}

.ben-panel-feedback-visible {
  display: block;
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 640px) {
  .ben-floating-btn {
    right: 16px;
    bottom: 16px;
  }

  .ben-chat-invite {
    right: 16px;
    bottom: 84px;
    max-width: calc(100vw - 32px);
  }

  .ben-chat-window {
    right: 12px;
    left: 12px;
    bottom: 84px;
    width: auto;
    height: min(540px, calc(100vh - 110px));
  }
}
