/* ==========================================================================
   CoopEast Support — floating chat widget (vanilla, self-contained)
   Palette pulls from variables.css (--clr-*) with safe fallbacks.
   ========================================================================== */

.cchat {
  --cc-green: var(--clr-primary, #0a6e3d);
  --cc-green-deep: var(--clr-primary-deep, #06432a);
  --cc-green-soft: #12905180;
  --cc-tint: var(--clr-primary-tint, #e9f4ee);
  --cc-ink: #16241d;
  --cc-mut: #647a6f;
  --cc-line: #e4ebe7;
  --cc-bg: #f4f8f6;
  --cc-white: #ffffff;
  --cc-radius: 1.25rem;
  --cc-shadow: 0 12px 48px -12px rgba(6, 67, 42, 0.28), 0 2px 8px rgba(6, 67, 42, 0.08);

  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1200;
  font-family: var(--ff-base, "Inter", system-ui, sans-serif);
  color: var(--cc-ink);
}

/* --------------------------------------------------------------------------
   Floating action button
   -------------------------------------------------------------------------- */

.cchat__fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 1rem 0.5rem 0.5rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--cc-green), var(--cc-green-deep));
  color: var(--cc-white);
  cursor: pointer;
  box-shadow: var(--cc-shadow);
  transition: transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 240ms;
  animation: cc-pop 400ms cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}

.cchat__fab:hover {
  transform: translateY(-2px);
}

.cchat__fab:focus-visible {
  outline: 3px solid var(--cc-tint);
  outline-offset: 2px;
}

.cchat__fab-ic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
}

.cchat__fab-ic svg {
  width: 1.375rem;
  height: 1.375rem;
}

.cchat__fab-ic svg + svg {
  display: none;
}

.cchat__fab-label {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  text-align: left;
  padding-right: 0.375rem;
}

.cchat__fab-label strong {
  font-size: 0.8125rem;
  font-weight: 600;
}

.cchat__fab-label small {
  font-size: 0.6875rem;
  opacity: 0.85;
}

/* Unread badge */
.cchat__badge {
  position: absolute;
  top: -0.25rem;
  right: -0.25rem;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 0.3125rem;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--clr-accent, #e9a13b);
  color: #3a2600;
  font-size: 0.6875rem;
  font-weight: 700;
  box-shadow: 0 0 0 2px var(--cc-white);
}

.cchat.has-unread .cchat__badge {
  display: inline-flex;
  animation: cc-pop 300ms cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}

/* When open, morph the fab to a compact close puck */
.cchat.is-open .cchat__fab {
  padding: 0.5rem;
}

.cchat.is-open .cchat__fab-label {
  display: none;
}

.cchat.is-open .cchat__fab-ic svg:first-child {
  display: none;
}

.cchat.is-open .cchat__fab-ic svg + svg {
  display: block;
}

.cchat.is-open .cchat__badge {
  display: none;
}

/* --------------------------------------------------------------------------
   Chat window
   -------------------------------------------------------------------------- */

.cchat__win {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.875rem);
  width: 23rem;
  max-width: calc(100vw - 2.5rem);
  height: 34rem;
  max-height: calc(100vh - 6rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--cc-white);
  border: 1px solid var(--cc-line);
  border-radius: var(--cc-radius);
  box-shadow: var(--cc-shadow);
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  pointer-events: none;
  transition: opacity 220ms ease, transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.cchat.is-open .cchat__win {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.cchat.is-min .cchat__win {
  display: none;
}

/* Header */
.cchat__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9375rem 1rem;
  background: linear-gradient(135deg, var(--cc-green), var(--cc-green-deep));
  color: var(--cc-white);
}

.cchat__avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 700;
  font-size: 0.9375rem;
}

.cchat__avatar svg {
  width: 1.375rem;
  height: 1.375rem;
}

.cchat__presence {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: #34d17a;
  box-shadow: 0 0 0 2px var(--cc-green-deep);
}

.cchat__head-text {
  flex: 1;
  min-width: 0;
}

.cchat__head-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0;
}

.cchat__head-status {
  display: flex;
  align-items: center;
  gap: 0.3125rem;
  font-size: 0.75rem;
  opacity: 0.9;
  margin: 0.0625rem 0 0;
}

.cchat__head-status::before {
  content: "";
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: 50%;
  background: #34d17a;
}

.cchat__head-btns {
  display: flex;
  gap: 0.25rem;
}

.cchat__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--cc-white);
  cursor: pointer;
  opacity: 0.85;
  transition: background 160ms, opacity 160ms;
}

.cchat__icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  opacity: 1;
}

.cchat__icon-btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* Message list */
.cchat__body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--cc-bg);
  scroll-behavior: smooth;
}

.cchat__day {
  text-align: center;
  font-size: 0.6875rem;
  color: var(--cc-mut);
  margin: 0 0 0.75rem;
}

/* Message row + bubble */
.cc-msg {
  display: flex;
  margin-bottom: 0.75rem;
  animation: cc-rise 300ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.cc-msg__inner {
  max-width: 82%;
}

.cc-msg__bubble {
  padding: 0.625rem 0.875rem;
  font-size: 0.84375rem;
  line-height: 1.5;
  border-radius: 1rem;
  white-space: pre-line;
  word-wrap: break-word;
}

.cc-msg__time {
  font-size: 0.625rem;
  color: var(--cc-mut);
  margin-top: 0.25rem;
  padding: 0 0.25rem;
}

/* Bot (left) */
.cc-msg--bot {
  justify-content: flex-start;
}

.cc-msg--bot .cc-msg__bubble {
  background: var(--cc-white);
  border: 1px solid var(--cc-line);
  border-bottom-left-radius: 0.25rem;
  color: var(--cc-ink);
}

/* User (right) */
.cc-msg--user {
  justify-content: flex-end;
}

.cc-msg--user .cc-msg__inner {
  text-align: right;
}

.cc-msg--user .cc-msg__bubble {
  background: linear-gradient(135deg, var(--cc-green), var(--cc-green-deep));
  color: var(--cc-white);
  border-bottom-right-radius: 0.25rem;
  text-align: left;
}

/* Typing indicator */
.cc-typing .cc-msg__bubble {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.75rem 0.875rem;
}

.cc-typing span {
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: 50%;
  background: var(--cc-mut);
  animation: cc-blink 1.2s infinite ease-in-out both;
}

.cc-typing span:nth-child(2) { animation-delay: 0.18s; }
.cc-typing span:nth-child(3) { animation-delay: 0.36s; }

/* Helpful + follow-ups (attached under a bot answer) */
.cc-extra {
  margin: -0.25rem 0 0.75rem 0;
  animation: cc-rise 300ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.cc-helpful {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--cc-mut);
  margin-bottom: 0.5rem;
}

.cc-helpful__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--cc-line);
  border-radius: 0.5rem;
  background: var(--cc-white);
  color: var(--cc-mut);
  cursor: pointer;
  transition: all 160ms;
}

.cc-helpful__btn:hover {
  border-color: var(--cc-green);
  color: var(--cc-green);
}

.cc-helpful__btn.is-picked {
  background: var(--cc-tint);
  border-color: var(--cc-green);
  color: var(--cc-green);
}

.cc-helpful__btn svg {
  width: 0.9375rem;
  height: 0.9375rem;
}

/* Chips (quick actions + follow-ups) */
.cc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4375rem;
}

.cc-chip {
  padding: 0.4375rem 0.75rem;
  border: 1px solid var(--cc-line);
  border-radius: 999px;
  background: var(--cc-white);
  color: var(--cc-green);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 160ms, border-color 160ms, transform 120ms;
}

.cc-chip:hover {
  background: var(--cc-tint);
  border-color: var(--cc-green);
}

.cc-chip:active {
  transform: scale(0.97);
}

/* Quick-actions label (shown inline with the welcome chips) */
.cc-quick-label {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cc-mut);
  margin: 0 0 0.5rem;
}

/* Composer */
.cchat__composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 0.875rem;
  border-top: 1px solid var(--cc-line);
  background: var(--cc-white);
}

.cchat__input {
  flex: 1;
  max-height: 5rem;
  min-height: 1.375rem;
  padding: 0.5rem 0.25rem;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 0.84375rem;
  line-height: 1.4;
  color: var(--cc-ink);
  background: transparent;
}

.cchat__input::placeholder {
  color: var(--cc-mut);
}

.cchat__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cc-green), var(--cc-green-deep));
  color: var(--cc-white);
  cursor: pointer;
  transition: transform 140ms, opacity 140ms;
}

.cchat__send:hover {
  transform: scale(1.06);
}

.cchat__send:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.cchat__send svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* Composer footer note */
.cchat__foot {
  padding: 0 0.875rem 0.625rem;
  background: var(--cc-white);
  font-size: 0.625rem;
  color: var(--cc-mut);
  text-align: center;
}

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */

@keyframes cc-pop {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes cc-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cc-blink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .cchat *,
  .cchat__win,
  .cchat__fab {
    animation: none !important;
    transition: opacity 120ms ease !important;
  }
}

/* --------------------------------------------------------------------------
   Mobile
   -------------------------------------------------------------------------- */

@media (max-width: 30rem) {
  .cchat {
    right: 1rem;
    bottom: 1rem;
  }

  .cchat__win {
    width: calc(100vw - 2rem);
    height: calc(100vh - 5.5rem);
    max-height: none;
  }

  .cchat__fab-label {
    display: none;
  }

  .cchat__fab {
    padding: 0.5rem;
  }
}
