#ccd-chat {
  --ccd-red: #ed1c24;
  --ccd-red-dark: #c4121a;
  --ccd-bg: #ffffff;
  --ccd-soft: #f4f5f7;
  --ccd-text: #1c1d21;
  --ccd-muted: #6b6f76;
  --ccd-border: #e4e6ea;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99990;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ccd-text);
}
#ccd-chat *, #ccd-chat *::before, #ccd-chat *::after { box-sizing: border-box; }

/* Keep Astra's scroll-to-top button clear of the chat bubble. */
#ast-scroll-top { bottom: 96px !important; }

.ccd-chat-fab {
  position: relative;
  width: 60px; height: 60px;
  border: 0; border-radius: 50%;
  background: var(--ccd-red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(237, 28, 36, .4);
  transition: transform .15s ease, background .15s ease;
  margin-left: auto;
  padding: 0;
}
.ccd-chat-fab:hover { background: var(--ccd-red-dark); transform: scale(1.05); }
.ccd-chat-fab:focus-visible { outline: 3px solid #ffd2d4; outline-offset: 2px; }
.ccd-chat-dot {
  position: absolute; top: 4px; right: 4px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #22c55e; border: 2px solid #fff;
}
#ccd-chat.is-open .ccd-chat-fab { display: none; }

.ccd-chat-teaser {
  position: absolute; right: 0; bottom: 72px;
  width: max-content; max-width: 240px;
  background: var(--ccd-bg); color: var(--ccd-text);
  padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .15);
  font-size: 14px; cursor: pointer;
  animation: ccd-pop .25s ease;
}
.ccd-chat-teaser[hidden] { display: none; }

.ccd-chat-panel {
  width: 370px; height: min(580px, calc(100vh - 40px));
  background: var(--ccd-bg);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .22);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: ccd-pop .2s ease;
}
.ccd-chat-panel[hidden] { display: none; }

.ccd-chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px 12px 14px;
  background: var(--ccd-red); color: #fff;
}
.ccd-chat-avatar {
  width: 38px; height: 38px; flex: none; border-radius: 50%;
  background: #fff; color: var(--ccd-red);
  font-weight: 800; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.ccd-chat-hinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ccd-chat-hinfo strong { font-size: 15px; }
.ccd-chat-hinfo span { font-size: 12px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccd-chat-call, .ccd-chat-close {
  width: 34px; height: 34px; flex: none;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .18); color: #fff !important;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1; cursor: pointer; text-decoration: none !important;
  padding: 0;
}
.ccd-chat-close { font-size: 24px; }
.ccd-chat-call:hover, .ccd-chat-close:hover { background: rgba(255, 255, 255, .3); }

.ccd-chat-body {
  flex: 1; overflow-y: auto;
  padding: 14px 12px;
  background: var(--ccd-soft);
  display: flex; flex-direction: column; gap: 8px;
}
.ccd-msg {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 14px;
  word-wrap: break-word; overflow-wrap: anywhere;
  animation: ccd-pop .15s ease;
}
.ccd-msg a { color: inherit; text-decoration: underline; }
.ccd-msg-assistant { align-self: flex-start; background: var(--ccd-bg); border: 1px solid var(--ccd-border); border-bottom-left-radius: 4px; }
.ccd-msg-assistant a { color: var(--ccd-red); }
.ccd-msg-user { align-self: flex-end; background: var(--ccd-red); color: #fff; border-bottom-right-radius: 4px; }

.ccd-typing { display: flex; gap: 4px; padding: 12px 14px; }
.ccd-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #b5b8be; animation: ccd-blink 1.2s infinite ease-in-out;
}
.ccd-typing span:nth-child(2) { animation-delay: .15s; }
.ccd-typing span:nth-child(3) { animation-delay: .3s; }

.ccd-chat-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px; background: var(--ccd-soft); }
.ccd-chat-chips:not(:empty) { padding-bottom: 10px; }
.ccd-chat-chips button {
  border: 1px solid var(--ccd-red); background: var(--ccd-bg); color: var(--ccd-red);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; line-height: 1.2;
}
.ccd-chat-chips button:hover { background: var(--ccd-red); color: #fff; }

.ccd-chat-form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px; border-top: 1px solid var(--ccd-border); background: var(--ccd-bg);
  margin: 0;
}
.ccd-chat-form textarea {
  flex: 1; resize: none; min-height: 40px; max-height: 120px;
  border: 1px solid var(--ccd-border); border-radius: 20px;
  padding: 9px 14px; font: inherit; color: var(--ccd-text); background: var(--ccd-bg);
  outline: none; margin: 0; box-shadow: none;
}
.ccd-chat-form textarea:focus { border-color: var(--ccd-red); }
.ccd-chat-form button {
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--ccd-red); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.ccd-chat-form button:hover { background: var(--ccd-red-dark); }
.ccd-chat-foot { font-size: 11px; color: var(--ccd-muted); text-align: center; padding: 0 10px 8px; background: var(--ccd-bg); }

@keyframes ccd-pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ccd-blink { 0%, 80%, 100% { opacity: .3; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

@media (max-width: 599px) {
  #ccd-chat { right: 16px; bottom: 16px; }
  /* Full screen; JS sets top/height to the visible area so the keyboard never covers the input. */
  #ccd-chat.is-open { top: 0; left: 0; right: 0; bottom: auto; height: 100vh; height: 100dvh; }
  #ccd-chat.is-open .ccd-chat-panel { width: 100%; height: 100%; border-radius: 0; animation: none; }
  .ccd-chat-head { padding-top: max(12px, env(safe-area-inset-top)); }
  .ccd-chat-form { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .ccd-chat-foot { display: none; } /* save vertical space while typing */
  .ccd-chat-form textarea { font-size: 16px; } /* stops iOS zoom on focus */
}

@media (prefers-reduced-motion: reduce) {
  #ccd-chat * { animation: none !important; transition: none !important; }
}
