/* Website chat widget: styling and motion. Motion is disabled for reduced-motion users. */
#carmine-chat { position: relative; z-index: 1200; }

:root { --chat-red: var(--red, #CD0040); --chat-red-dark: #a80035; }

/* ---------- launcher ---------- */
.chat-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px 8px 8px;
  border: 0;
  border-radius: 999px;
  background: var(--chat-red);
  color: #FFFFFF;
  font: 700 14px/1 Inter, Arial, sans-serif;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(205, 0, 64, 0.32);
  transition: transform 220ms cubic-bezier(.2,.8,.2,1), background-color 200ms ease, box-shadow 220ms ease;
}
.chat-launcher:hover { background: var(--chat-red-dark); transform: translateY(-2px); box-shadow: 0 16px 34px rgba(205, 0, 64, 0.38); }
.chat-launcher:active { transform: translateY(0) scale(0.97); }
.chat-launcher:focus-visible { outline: 3px solid #1A1A1A; outline-offset: 3px; }
.chat-launcher.is-hidden { display: none; }
.chat-launcher-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
}
.chat-launcher-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
/* soft ring that tells the visitor the assistant is there */
.chat-launcher::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  border: 2px solid var(--chat-red);
  opacity: 0;
  pointer-events: none;
}

/* ---------- panel ---------- */
.chat-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1201;
  width: min(390px, calc(100vw - 32px));
  max-height: min(600px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  background: #FFFFFF;
  border: 1px solid #E1E4E9;
  border-top: 3px solid var(--chat-red);
  border-radius: 10px;
  box-shadow: 0 24px 60px rgba(10, 10, 12, 0.24);
  font: 400 14px/1.5 Inter, Arial, sans-serif;
  color: #1A1A1A;
  transform-origin: bottom right;
}
.chat-panel[hidden] { display: none; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 12px 16px;
  border-bottom: 1px solid #EEF0F3;
}
.chat-avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--chat-red);
  color: #FFFFFF;
  font: 800 16px/1 Inter, Arial, sans-serif;
}
.chat-titles { flex: 1; min-width: 0; }
.chat-head strong { display: block; font-weight: 800; font-size: 15px; }
.chat-sub { display: flex; align-items: flex-start; gap: 6px; font-size: 11.5px; line-height: 1.35; color: #6B7280; margin-top: 2px; }
.chat-live {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-top: 4px;
  border-radius: 50%;
  background: #16A34A;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5);
}
.chat-close {
  border: 0;
  background: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: #1A1A1A;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background-color 160ms ease;
}
.chat-close:hover { background: #F2F3F5; }
.chat-close:focus-visible { outline: 2px solid #1A1A1A; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
  scroll-behavior: smooth;
}
.chat-msg {
  margin: 0;
  padding: 10px 13px;
  border-radius: 14px;
  max-width: 88%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat-msg-bot { background: #F4F5F7; align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg-user { background: #1A1A1A; color: #FFFFFF; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg.is-error { background: #FDECEC; color: #8A1C15; }

/* formatted assistant replies: paragraphs, lists and bold terms */
.chat-msg-bot > *:first-child { margin-top: 0; }
.chat-msg-bot > *:last-child { margin-bottom: 0; }
.chat-msg-bot .chat-para { margin: 0 0 8px; }
.chat-msg-bot .chat-para:last-child { margin-bottom: 0; }
.chat-msg-bot .chat-list { margin: 0 0 8px; padding-left: 20px; }
.chat-msg-bot .chat-list li { margin: 0 0 4px; padding-left: 2px; }
.chat-msg-bot .chat-list li::marker { color: var(--chat-red); }
.chat-msg-bot strong { font-weight: 700; color: #111111; }
.chat-msg .w { transition: opacity 140ms ease; }
.chat-msg .w.w-hidden { opacity: 0; }

.chat-typing { display: inline-flex; gap: 5px; align-items: center; padding: 13px 14px; }
.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8A8F98;
}

.chat-starters { display: flex; flex-direction: column; gap: 6px; align-self: stretch; }
.chat-option {
  text-align: left;
  padding: 9px 12px;
  border: 1px solid #DCE0E6;
  border-radius: 8px;
  background: #FFFFFF;
  font: 600 13.5px/1.3 Inter, Arial, sans-serif;
  color: #1A1A1A;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, transform 160ms ease;
}
.chat-option:hover { border-color: var(--chat-red); color: var(--chat-red); transform: translateX(3px); }
.chat-option:focus-visible { outline: 2px solid #1A1A1A; outline-offset: 2px; }

.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid #EEF0F3;
}
.chat-input input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #DCE0E6;
  border-radius: 8px;
  font: 400 14px/1.4 Inter, Arial, sans-serif;
  color: #1A1A1A;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.chat-input input:focus { outline: none; border-color: var(--chat-red); box-shadow: 0 0 0 3px rgba(205, 0, 64, 0.14); }
.chat-send {
  display: grid;
  place-items: center;
  width: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--chat-red);
  color: #FFFFFF;
  cursor: pointer;
  transition: background-color 160ms ease, transform 160ms ease;
}
.chat-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chat-send:hover { background: var(--chat-red-dark); }
.chat-send:active { transform: scale(0.94); }
.chat-send:disabled { opacity: 0.55; cursor: wait; }
.chat-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 560px) {
  .chat-panel { right: 10px; bottom: 10px; width: calc(100vw - 20px); }
  .chat-launcher { right: 12px; bottom: 12px; }
  .chat-launcher-label { display: none; }
  .chat-launcher { padding: 8px; }
}

/* ---------- motion (skipped for reduced-motion users) ---------- */
@media (prefers-reduced-motion: no-preference) {
  /* panel opens by growing out of the launcher corner */
  .chat-panel:not([hidden]) { animation: chatPanelIn 320ms cubic-bezier(.2,.8,.2,1) both; }
  .chat-panel.is-closing { animation: chatPanelOut 180ms ease-in both; }
  @keyframes chatPanelIn { from { opacity: 0; transform: translateY(14px) scale(0.92); } to { opacity: 1; transform: none; } }
  @keyframes chatPanelOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(10px) scale(0.94); } }

  /* the launcher's soft ring pulses a couple of times, then rests */
  .chat-launcher:not(.is-hidden)::after { animation: chatRing 2.4s ease-out 1.2s 3; }
  @keyframes chatRing { 0% { opacity: 0.7; transform: scale(1); } 100% { opacity: 0; transform: scale(1.28); } }

  /* messages slide in from their side */
  .chat-msg.is-entering { animation: chatMsgIn 380ms cubic-bezier(.2,.8,.2,1) both; }
  .chat-msg-user.is-entering { --dx: 14px; }
  .chat-msg-bot.is-entering { --dx: -14px; }
  @keyframes chatMsgIn { from { opacity: 0; transform: translate(var(--dx, 0), 8px); } to { opacity: 1; transform: none; } }

  /* typing dots bounce in a wave */
  .chat-typing span { animation: chatDot 1.1s ease-in-out infinite; }
  .chat-typing span:nth-child(2) { animation-delay: 0.15s; }
  .chat-typing span:nth-child(3) { animation-delay: 0.3s; }
  @keyframes chatDot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.35; } 30% { transform: translateY(-5px); opacity: 1; } }

  /* starter buttons fade up one after another */
  .chat-option.is-entering { animation: chatOptIn 360ms cubic-bezier(.2,.8,.2,1) both; }
  @keyframes chatOptIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

  /* the green dot shows the assistant is live */
  .chat-live { animation: chatLive 2s ease-out infinite; }
  @keyframes chatLive { 0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5); } 70%, 100% { box-shadow: 0 0 0 7px rgba(22, 163, 74, 0); } }

  /* sending: the form pulses softly while the answer is on its way */
  .chat-input.is-busy .chat-send { animation: chatBusy 1s ease-in-out infinite; }
  @keyframes chatBusy { 0%, 100% { transform: scale(1); } 50% { transform: scale(0.94); } }

  .chat-msg.is-error.is-entering { animation: chatShake 420ms ease both; }
  @keyframes chatShake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
}

/* launcher over a red section: white pill with black text and a red icon */
.chat-launcher.is-on-red { background: #FFFFFF; color: #141416; box-shadow: 0 12px 28px rgba(10,10,12,0.22); }
.chat-launcher.is-on-red:hover { background: #F4F5F7; }
.chat-launcher.is-on-red .chat-launcher-icon { background: #F4F5F7; color: #CD0040; }
.chat-launcher.is-on-red::after { border-color: #141416; }
