:root {
  --bg: #FAF7F2;
  --bg-raised: #F2EBE1;
  --bg-raised-2: #EAE0D1;
  --text: #2A1B10;
  --text-dim: #7C6952;
  --accent: #9C4A1F;
  --accent-dim: rgba(156,74,31,0.10);
  --accent-vivid: #C2571F;
  --gold: #C68C53;
  --gold-dim: rgba(198,140,83,0.18);
  --redline: #C2571F;
  --redline-dim: rgba(194,87,31,0.14);
  --espresso: #3B2415;
  --espresso-2: #2A1810;
  --cream: #F3E6D2;
  --ok: #6B7A3F;
  --line: #E3D2B0;
  --glass-bg: rgba(250,247,242,0.6);
  --glass-bg-strong: rgba(250,247,242,0.78);
  --glass-border: rgba(227,210,176,0.65);
  --shadow-soft: 0 10px 28px -16px rgba(42,24,16,0.16);
  --shadow-lift: 0 26px 52px -20px rgba(42,24,16,0.26);
}

@keyframes pulse-glow {
  0% { box-shadow: 0 0 0 0 rgba(156, 74, 31, 0.3); }
  70% { box-shadow: 0 0 0 12px rgba(156, 74, 31, 0); }
  100% { box-shadow: 0 0 0 0 rgba(156, 74, 31, 0); }
}

/* Lightweight storefront context for the embedded support experience. */
.storefront-mock { max-width: 880px; min-height: 100svh; margin: 0 auto; padding: 0 32px 80px; font-family: 'Inter', sans-serif; }
.storefront-mock__nav { padding: 28px 0; border-bottom: 1px solid var(--line); }
.storefront-mock__logo { font-weight: 800; font-size: 22px; letter-spacing: -0.03em; }
.storefront-mock__hero { padding: 64px 0; max-width: 480px; }
.storefront-mock__hero h1 { font-family: 'Newsreader', serif; font-size: 46px; line-height: 1.15; font-weight: 600; letter-spacing: -0.02em; color: var(--text); }
.storefront-mock__hero p { color: var(--text-dim); font-size: 17px; margin-top: 18px; line-height: 1.6; }

#wrennon-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 999;
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  color: var(--text);
}

#launcher {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--cream);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lift);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  animation: pulse-glow 2.5s infinite;
  margin-left: auto;
  min-width: 48px;
  min-height: 48px;
}
#launcher:hover { transform: translateY(-4px) scale(1.02); animation: none; }
#launcher:focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }
#launcher svg { width: 28px; height: 28px; }

/* Panel / Chat Card */
#panel {
  position: absolute;
  bottom: 90px;
  right: 0;
  width: 360px;
  height: 520px;
  display: flex;
  flex-direction: column;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.4s;
  transform-origin: bottom right;
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
}
#panel.hidden {
  display: flex !important;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.92) translateY(24px);
  pointer-events: none;
}

.chat-card {
  background: var(--glass-bg-strong);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: var(--shadow-lift);
  overflow: hidden;
  text-align: left;
  position: relative;
  z-index: 2;
}

.chat-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--espresso);
  color: var(--cream);
  border-bottom: none;
}

.chat-card-head .chat-avatar {
  background: var(--cream);
  border-color: var(--espresso);
}
.chat-card-head .chat-avatar img {
  filter: brightness(0); /* Make the wren mark match dark background */
}

.chat-card-head .chat-name {
  color: var(--cream);
  font-size: 13px;
  font-weight: 600;
}

.chat-card-head .chat-status {
  color: #C9AF8C;
  font-size: 10.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.chat-card-head .chat-icon-btn {
  color: var(--cream);
  opacity: 0.75;
}
.chat-card-head .chat-icon-btn:hover {
  opacity: 1;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
  animation: statusPulse 2s ease infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

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

.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }

.bubble {
  max-width: 84%;
  font-size: 13px;
  line-height: 1.45;
  padding: 10px 14px;
  border-radius: 14px;
}

.bubble p:last-child { margin-bottom: 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p { margin: 8px 0; }

.bubble-user {
  align-self: flex-end;
  background: var(--bg-raised);
  border-bottom-right-radius: 4px;
  color: var(--text);
}

.bubble-agent, .bubble-bot {
  align-self: flex-start;
  background: var(--accent-dim);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.bubble-system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  border: none;
  max-width: 100%;
}

.bubble-enter {
  animation: bubbleIn 0.32s ease both;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-raised);
}

.chat-input-icons {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 4px;
}

.chat-icon-btn {
  display: flex;
  color: var(--text-dim);
  opacity: 0.75;
  transition: opacity 0.2s;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
}
.chat-icon-btn:hover {
  opacity: 1;
}
.chat-icon-btn:focus-visible { outline: 2px solid var(--text); }

.chat-icon-btn svg {
  width: 18px;
  height: 18px;
}

.chat-input-placeholder {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-size: 13.5px;
  color: var(--text);
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  padding: 2px 0;
}

.chat-input-placeholder::placeholder {
  color: var(--text-dim);
  opacity: 0.8;
}

.chat-send {
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  padding-bottom: 4px;
}
.chat-send svg {
  width: 20px;
  height: 20px;
  transform: rotate(90deg);
}
.chat-send:hover {
  color: var(--accent-vivid);
}

/* Extras that widget.js might inject dynamically */
.typing-indicator-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--line);
  background: var(--glass-bg-strong);
}

.typing-dots { display: flex; gap: 4px; }
.typing-dot {
  width: 4px; height: 4px; background: var(--text-dim); border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.unread-indicator {
  text-align: center;
  font-size: 12px;
  margin: 12px 0;
  color: var(--accent);
  border-top: 1px solid var(--accent-dim);
  padding-top: 12px;
}

.csat-card {
  padding: 16px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: center;
  margin: 16px 0;
}

.csat-card__question {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.csat-card__stars {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.csat-star {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--line);
  cursor: pointer;
  transition: transform 0.2s, color 0.2s;
}
.csat-star:hover, .csat-star--hover, .csat-star--selected {
  color: var(--gold);
  transform: scale(1.1);
}

.scroll-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 20px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--glass-bg-strong);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
}
.scroll-bottom-btn:hover { background: var(--bg-raised); }
.scroll-bottom-btn.hidden { display: none; }

/* Image upload attachment styling (voice and images) */
.attachment-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-raised-2);
  border-radius: 8px;
  margin: 12px;
  border: 1px solid var(--line);
}
.attachment-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.attachment-preview audio {
  flex: 1;
  height: 32px;
}
.remove-attachment-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
}
.remove-attachment-btn:hover { color: var(--text); }

/* --- Crisp Theme Overrides --- */
.theme-crisp #launcher {
  background: #1b74e4;
}
.theme-crisp .chat-card {
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  background: #fff;
  border: 1px solid #e5e7eb;
}
.theme-crisp .crisp-head {
  background: #1b74e4;
  flex-direction: column;
  padding: 0;
  color: #fff;
  border-bottom: none;
}
.theme-crisp .crisp-tabs {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px 0;
}
.theme-crisp .crisp-tab {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 20px 20px 0 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.theme-crisp .crisp-tab:hover {
  color: #fff;
}
.theme-crisp .crisp-tab.active {
  background: #fff;
  color: #1b74e4;
}
.theme-crisp .crisp-profile {
  padding: 16px;
  text-align: center;
  position: relative;
}
.theme-crisp .crisp-avatar-wrap {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fff;
  margin: 0 auto 8px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-crisp .crisp-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: #10b981;
  border: 2px solid #1b74e4;
  border-radius: 50%;
}
.theme-crisp .crisp-name {
  font-weight: 600;
  font-size: 16px;
}
.theme-crisp .crisp-connect-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  margin-top: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.theme-crisp .crisp-connect-btn:hover {
  background: rgba(255,255,255,0.3);
}

.theme-crisp .chat-body {
  background: #f9fafb;
}
.theme-crisp .bubble {
  border-radius: 18px;
  padding: 12px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.theme-crisp .bubble-user {
  background: #1b74e4;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.theme-crisp .bubble-agent, .theme-crisp .bubble-bot {
  background: #fff;
  color: #111827;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}
.theme-crisp .chat-input {
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 12px 16px;
}
.theme-crisp .chat-send {
  color: #1b74e4;
}
.theme-crisp .chat-send:hover {
  color: #155bb5;
}
.theme-crisp .date-separator {
  color: #9ca3af;
  font-size: 11px;
}

/* Keep the floating support panel within small viewports and safe areas. */
@media (max-width: 600px) {
  .storefront-mock { padding: 0 20px 96px; }
  .storefront-mock__nav { padding: 20px 0; }
  .storefront-mock__logo { font-size: 19px; }
  .storefront-mock__hero { padding: 42px 0; }
  .storefront-mock__hero h1 { font-size: clamp(34px, 10vw, 42px); }
  .storefront-mock__hero p { font-size: 16px; }

  #wrennon-widget {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  #launcher {
    width: 56px;
    height: 56px;
  }

  #panel {
    position: fixed;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: min(420px, calc(100vw - 24px));
    height: min(680px, calc(100dvh - 100px - env(safe-area-inset-bottom)));
    max-height: calc(100dvh - 100px - env(safe-area-inset-bottom));
  }

  .chat-input-icons { gap: var(--ui-space-2, 8px); }
  .chat-input { gap: var(--ui-space-2, 8px); padding: 10px 12px; }
}

@media (max-height: 560px) and (max-width: 600px) {
  #wrennon-widget {
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
  }

  #panel {
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    pointer-events: auto;
  }
}
