:root {
  --cp-chat-primary: #1457d9;
  --cp-chat-primary-dark: #0b2f75;
  --cp-chat-accent: #22c55e;
  --cp-chat-text: #0f172a;
  --cp-chat-muted: #64748b;
  --cp-chat-border: rgba(20, 87, 217, 0.16);
  --cp-chat-surface: #ffffff;
  --cp-chat-soft: #f8fbff;
  --cp-chat-shadow: 0 24px 80px rgba(15, 23, 42, 0.22);
  --cp-chat-radius: 22px;
  --cp-chat-z: 2147483000;
}

.cp-chat *,
.cp-chat *::before,
.cp-chat *::after,
.cp-chat-invite *,
.cp-chat-invite *::before,
.cp-chat-invite *::after {
  box-sizing: border-box;
}

.cp-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--cp-chat-z);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.cp-chat-window {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: min(390px, calc(100vw - 40px));
  height: min(640px, calc(100dvh - 116px));
  overflow: hidden;
  border: 1px solid var(--cp-chat-border);
  border-radius: var(--cp-chat-radius);
  background: var(--cp-chat-surface);
  box-shadow: var(--cp-chat-shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px) scale(0.96);
  transform-origin: right bottom;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    visibility 0.18s ease;
}

.cp-chat.is-open .cp-chat-window {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.cp-chat-header {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background:
    radial-gradient(circle at 20% -20%, rgba(255, 255, 255, 0.24), transparent 120px),
    linear-gradient(135deg, var(--cp-chat-primary-dark), var(--cp-chat-primary));
  color: #ffffff;
}

.cp-chat-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.cp-chat-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.cp-chat-avatar svg {
  width: 22px;
  height: 22px;
}

.cp-chat svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cp-chat-title strong {
  display: block;
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.015em;
}

.cp-chat-title small {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 600;
}

.cp-chat-title small i {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--cp-chat-accent);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.14);
}

.cp-chat-close {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.13);
  color: #ffffff;
  cursor: pointer;
  transition: background 0.14s ease, transform 0.14s ease;
}

.cp-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.cp-chat-close:active {
  transform: translateY(1px);
}

.cp-chat-close svg {
  width: 18px;
  height: 18px;
}

.cp-chat-frame {
  display: block;
  width: 100%;
  height: calc(100% - 70px);
  border: 0;
  background: var(--cp-chat-soft);
}

.cp-chat-launcher {
  position: relative;
  min-width: 152px;
  min-height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 14px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--cp-chat-primary), var(--cp-chat-primary-dark));
  color: #ffffff;
  border: 2px solid rgba(255, 255, 255, 0.92);
  box-shadow:
    0 0 0 6px rgba(20, 87, 217, 0.14),
    0 20px 56px rgba(20, 87, 217, 0.46),
    0 10px 24px rgba(15, 23, 42, 0.24);
  cursor: pointer;
  animation: cpChatLauncherBreathe 2.2s ease-in-out infinite;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.01em;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}

.cp-chat-launcher:hover {
  filter: brightness(1.07);
  box-shadow:
    0 0 0 7px rgba(20, 87, 217, 0.18),
    0 24px 64px rgba(20, 87, 217, 0.56),
    0 12px 28px rgba(15, 23, 42, 0.28);
}

.cp-chat-launcher:active {
  transform: translateY(1px);
}

.cp-chat-launcher svg {
  width: 22px;
  height: 22px;
}

.cp-chat-pulse {
  position: absolute;
  inset: -5px;
  border-radius: inherit;
  background: rgba(37, 99, 235, 0.30);
  box-shadow: 0 0 0 1px rgba(255,255,255,.28);
  animation: cpChatPulse 1.45s ease-out infinite;
  z-index: -1;
}

@keyframes cpChatPulse {
  0% {
    opacity: 0.95;
    transform: scale(0.9);
  }
  100% {
    opacity: 0;
    transform: scale(1.28);
  }
}

@keyframes cpChatLauncherBreathe {
  0%, 100% {
    transform: translateY(0) scale(1);
    box-shadow:
      0 0 0 6px rgba(20, 87, 217, 0.14),
      0 20px 56px rgba(20, 87, 217, 0.46),
      0 10px 24px rgba(15, 23, 42, 0.24);
  }
  50% {
    transform: translateY(-1px) scale(1.035);
    box-shadow:
      0 0 0 9px rgba(20, 87, 217, 0.20),
      0 26px 72px rgba(20, 87, 217, 0.60),
      0 14px 30px rgba(15, 23, 42, 0.28);
  }
}

.cp-chat.is-open .cp-chat-pulse {
  display: none;
}

.cp-chat.is-open .cp-chat-launcher {
  animation: none;
}

.cp-chat-badge {
  position: absolute;
  top: -4px;
  right: -2px;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #ef4444;
  color: #ffffff;
  border: 2px solid #ffffff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.cp-chat-invite {
  position: fixed;
  inset: 0;
  z-index: calc(var(--cp-chat-z) - 1);
  display: none;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.cp-chat-invite.is-open {
  display: block;
}

.cp-chat-invite-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(5px);
}

.cp-chat-invite-card {
  position: absolute;
  right: 24px;
  bottom: 96px;
  width: min(430px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 26px;
  background:
    radial-gradient(circle at right top, rgba(20, 87, 217, 0.1), transparent 180px),
    #ffffff;
  color: var(--cp-chat-text);
  box-shadow: 0 28px 90px rgba(15, 23, 42, 0.28);
  border: 1px solid rgba(20, 87, 217, 0.12);
  animation: cpChatInviteIn 0.2s ease-out;
}

@keyframes cpChatInviteIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.cp-chat-invite-x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.06);
  color: var(--cp-chat-text);
  cursor: pointer;
}

.cp-chat-invite-x svg {
  width: 18px;
  height: 18px;
}

.cp-chat-invite-icon {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  border-radius: 20px;
  background: rgba(20, 87, 217, 0.09);
  color: var(--cp-chat-primary);
}

.cp-chat-invite-icon svg {
  width: 30px;
  height: 30px;
}

.cp-chat-invite-card h2 {
  margin: 0 34px 10px 0;
  color: var(--cp-chat-text);
  font-size: 26px;
  line-height: 1.08;
  font-weight: 850;
  letter-spacing: -0.035em;
}

.cp-chat-invite-card p {
  margin: 0 0 20px;
  color: var(--cp-chat-muted);
  font-size: 15px;
  line-height: 1.55;
}

.cp-chat-invite-actions {
  display: grid;
  gap: 10px;
}

.cp-chat-invite-primary,
.cp-chat-invite-secondary,
.cp-chat-invite-link {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.cp-chat-invite-primary {
  border: 0;
  background: linear-gradient(135deg, var(--cp-chat-primary), var(--cp-chat-primary-dark));
  color: #ffffff;
  box-shadow: 0 16px 34px rgba(20, 87, 217, 0.24);
}

.cp-chat-invite-secondary {
  border: 1px solid rgba(20, 87, 217, 0.2);
  background: rgba(20, 87, 217, 0.06);
  color: var(--cp-chat-primary);
}

.cp-chat-invite-link {
  border: 0;
  min-height: 36px;
  background: transparent;
  color: var(--cp-chat-muted);
}

@media (max-width: 767px) {
  .cp-chat {
    right: 14px;
    bottom: 14px;
  }

  .cp-chat-launcher {
    min-width: 58px;
    width: 58px;
    height: 58px;
    padding: 0;
  }

  .cp-chat-launcher-text {
    display: none;
  }

  .cp-chat-window {
    position: fixed;
    right: 10px;
    left: 10px;
    bottom: 84px;
    width: auto;
    height: min(640px, calc(100dvh - 104px));
    border-radius: 20px;
    transform-origin: center bottom;
  }

  .cp-chat-invite-card {
    left: 14px;
    right: 14px;
    bottom: 88px;
    width: auto;
    padding: 24px;
    border-radius: 24px;
  }

  .cp-chat-invite-card h2 {
    font-size: 23px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --cp-chat-text: #f8fafc;
    --cp-chat-muted: #94a3b8;
    --cp-chat-border: rgba(255, 255, 255, 0.12);
    --cp-chat-surface: #111827;
    --cp-chat-soft: #0f172a;
    --cp-chat-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  }

  .cp-chat-invite-card {
    background:
      radial-gradient(circle at right top, rgba(59, 130, 246, 0.14), transparent 180px),
      #111827;
    border-color: rgba(255, 255, 255, 0.1);
  }

  .cp-chat-invite-x {
    background: rgba(255, 255, 255, 0.08);
  }

  .cp-chat-badge {
    border-color: #111827;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cp-chat-window,
  .cp-chat-launcher,
  .cp-chat-close,
  .cp-chat-pulse,
  .cp-chat-invite-card {
    animation: none;
    transition: none;
  }
}


/* P2.2.4: visible invite close button */
.cp-chat-invite-x {
  z-index: 5;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.cp-chat-invite-x:hover,
.cp-chat-invite-x:focus {
  background: #ffffff;
  color: #1457d9;
  transform: translateY(-1px);
}

.cp-chat-invite-x svg {
  display: block;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (prefers-color-scheme: dark) {
  .cp-chat-invite-x {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(15, 23, 42, 0.86);
    color: #f8fafc;
  }

  .cp-chat-invite-x:hover,
  .cp-chat-invite-x:focus {
    background: rgba(30, 41, 59, 0.96);
    color: #93c5fd;
  }
}


/* P2.2.4a: reliable text cross for invite close button */
.cp-chat-invite-x {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.cp-chat-invite-x span {
  display: block;
  width: 1em;
  height: 1em;
  line-height: .88;
  text-align: center;
  transform: translateY(-1px);
}

.cp-chat-invite-x svg {
  display: none !important;
}
