:root {
  --cwp-chat-brand: #1f2f56;
  --cwp-chat-brand-dark: #101c35;
  --cwp-chat-accent: #f28c38;
  --cwp-chat-gradient: linear-gradient(135deg, #243d70 0%, #15284d 100%);
  --cwp-chat-navy: #0b1730;
  --cwp-chat-text: #172033;
  --cwp-chat-muted: #64748b;
  --cwp-chat-line: #dfe7ef;
  --cwp-chat-surface: #ffffff;
  --cwp-chat-ease: cubic-bezier(.22, 1, .36, 1);
}

html.cwp-chat-lock,
html.cwp-chat-lock body {
  overflow: hidden !important;
  overscroll-behavior: none;
}

.cwp-chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10060;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 999px;
  background: var(--cwp-chat-gradient);
  color: #fff;
  box-shadow: 0 16px 38px rgba(8, 20, 44, .30), inset 0 1px 0 rgba(255, 255, 255, .18);
  font: inherit;
  font-size: .93rem;
  font-weight: 800;
  letter-spacing: -.2px;
  cursor: pointer;
  transition: transform .28s var(--cwp-chat-ease), box-shadow .28s ease, opacity .24s ease, visibility .24s ease;
}

.cwp-chat-launcher::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 1px;
  border-radius: 999px;
  background: var(--cwp-chat-accent);
  box-shadow: 0 0 0 4px rgba(242, 140, 56, .15);
}

.cwp-chat-launcher:hover {
  transform: translateY(-3px) scale(1.015);
  box-shadow: 0 20px 48px rgba(8, 20, 44, .36), inset 0 1px 0 rgba(255, 255, 255, .22);
}

.cwp-chat-launcher:active {
  transform: translateY(0) scale(.97);
}

.cwp-chat-root.is-open .cwp-chat-launcher {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px) scale(.96);
}

.cwp-chat-launcher svg {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .12));
}

.cwp-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 10050;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(390px, calc(100vw - 32px));
  height: min(610px, calc(100dvh - 124px));
  overflow: hidden;
  border: 1px solid rgba(197, 208, 226, .92);
  border-radius: 24px;
  background: var(--cwp-chat-surface);
  box-shadow: 0 34px 88px rgba(7, 18, 40, .28), 0 10px 28px rgba(31, 47, 86, .10);
  opacity: 0;
  visibility: hidden;
  transform: translateY(26px) scale(.955);
  transform-origin: right bottom;
  transition:
    opacity .28s ease,
    visibility 0s linear .36s,
    transform .38s var(--cwp-chat-ease);
}

.cwp-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.cwp-chat-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 13px 14px 13px 16px;
  background:
    radial-gradient(circle at 12% 0%, rgba(100, 149, 237, .18), transparent 38%),
    linear-gradient(135deg, #0b1730 0%, #1f2f56 100%);
  color: #fff;
}

.cwp-chat-head::after {
  content: "";
  position: absolute;
  right: 16px;
  bottom: 0;
  left: 16px;
  height: 1px;
  background: linear-gradient(90deg, var(--cwp-chat-accent), rgba(242, 140, 56, 0));
}

.cwp-chat-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 15px;
  background: linear-gradient(145deg, #31558d 0%, #1f2f56 72%);
  box-shadow: 0 8px 20px rgba(3, 24, 44, .25), inset 0 1px 0 rgba(255, 255, 255, .22);
}

.cwp-chat-mark svg {
  width: 25px;
  height: 25px;
}

.cwp-chat-title {
  min-width: 0;
  flex: 1;
}

.cwp-chat-title strong,
.cwp-chat-title span {
  display: block;
}

.cwp-chat-title strong {
  font-size: .98rem;
  letter-spacing: -.2px;
}

.cwp-chat-title span {
  margin-top: 3px;
  color: rgba(255, 255, 255, .7);
  font-size: .77rem;
}

.cwp-chat-close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font: inherit;
  cursor: pointer;
  transition: background .22s ease, transform .28s var(--cwp-chat-ease);
}

.cwp-chat-close svg {
  display: block;
  width: 19px;
  height: 19px;
}

.cwp-chat-close:hover {
  background: rgba(255, 255, 255, .17);
  transform: rotate(5deg) scale(1.05);
}

.cwp-chat-close:active {
  transform: scale(.94);
}

.cwp-chat-body {
  overflow-y: auto;
  padding: 18px 15px 16px;
  background:
    radial-gradient(circle at 100% 0%, rgba(31, 47, 86, .045), transparent 34%),
    #f7f8fb;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scroll-behavior: smooth;
}

.cwp-chat-message {
  display: flex;
  margin: 0 0 12px;
  animation: cwp-chat-message-in .34s var(--cwp-chat-ease) both;
}

@keyframes cwp-chat-message-in {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cwp-chat-message.is-user {
  justify-content: flex-end;
}

.cwp-chat-bubble {
  max-width: 84%;
  padding: 11px 13px;
  border: 1px solid var(--cwp-chat-line);
  border-radius: 8px 18px 18px 18px;
  background: #fff;
  color: var(--cwp-chat-text);
  font-size: .9rem;
  line-height: 1.6;
  letter-spacing: -.12px;
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: anywhere;
  box-shadow: 0 7px 20px rgba(15, 23, 42, .055);
}

.cwp-chat-message.is-user .cwp-chat-bubble {
  border-color: transparent;
  border-radius: 17px 7px 17px 17px;
  background: linear-gradient(135deg, #263f70 0%, #172a50 100%);
  color: #fff;
  box-shadow: 0 7px 18px rgba(22, 59, 99, .16);
}

.cwp-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 14px;
}

.cwp-chat-quick button {
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid #d9e0e9;
  border-radius: 999px;
  background: #fff;
  color: #334155;
  font: inherit;
  font-size: .8rem;
  font-weight: 750;
  cursor: pointer;
  transition: color .22s ease, border-color .22s ease, background .22s ease, transform .26s var(--cwp-chat-ease), box-shadow .22s ease;
}

.cwp-chat-quick button:hover {
  border-color: rgba(242, 140, 56, .65);
  color: #9a4d12;
  background: #fff8f1;
  transform: translateY(-2px);
  box-shadow: 0 7px 16px rgba(242, 140, 56, .11);
}

.cwp-chat-quick button:active { transform: translateY(0) scale(.97); }

.cwp-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 54px;
}

.cwp-chat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: cwp-chat-pulse 1s infinite ease-in-out;
}

.cwp-chat-typing i:nth-child(2) { animation-delay: .14s; }
.cwp-chat-typing i:nth-child(3) { animation-delay: .28s; }

@keyframes cwp-chat-pulse {
  0%, 70%, 100% { opacity: .35; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}

.cwp-chat-footer {
  padding: 11px 12px 10px;
  border-top: 1px solid var(--cwp-chat-line);
  background: #fff;
}

.cwp-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.cwp-chat-input {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 13px;
  border: 1px solid #d7dee8;
  border-radius: 13px;
  outline: none;
  background: #fff;
  color: var(--cwp-chat-text);
  font: inherit;
  font-size: .88rem;
  transition: border-color .22s ease, box-shadow .22s ease, background .22s ease;
}

.cwp-chat-input:focus {
  border-color: #6179a6;
  box-shadow: 0 0 0 3px rgba(31, 47, 86, .11);
  background: #fcfeff;
}

.cwp-chat-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(135deg, #f39a4f 0%, #e97825 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(242, 140, 56, .24);
  transition: transform .25s var(--cwp-chat-ease), box-shadow .25s ease, opacity .2s ease;
}

.cwp-chat-send:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(242, 140, 56, .32);
}

.cwp-chat-send:hover svg { transform: translateX(2px) rotate(-4deg); }
.cwp-chat-send:active { transform: scale(.94); }

.cwp-chat-send:disabled,
.cwp-chat-input:disabled {
  opacity: .55;
  cursor: wait;
}

.cwp-chat-send svg {
  width: 19px;
  height: 19px;
  transition: transform .25s var(--cwp-chat-ease);
}

.cwp-chat-note {
  margin: 8px 2px 0;
  color: var(--cwp-chat-muted);
  font-size: .68rem;
  line-height: 1.45;
  text-align: center;
}

.cwp-chat-contact {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 40px;
  margin-top: 8px;
  border-radius: 12px;
  border: 1px solid #d8dfec;
  background: linear-gradient(135deg, #f5f7fb 0%, #eef2f8 100%);
  color: var(--cwp-chat-brand);
  font-size: .82rem;
  font-weight: 850;
  transition: transform .25s var(--cwp-chat-ease), box-shadow .22s ease, border-color .22s ease;
}

.cwp-chat-contact:hover {
  border-color: #aebbd1;
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(31, 47, 86, .10);
}

@media (max-width: 860px) {
  .cwp-chat-launcher {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    min-height: 50px;
    padding: 0 15px;
    font-size: .86rem;
  }

  .cwp-chat-panel {
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    width: calc(100vw - 16px);
    height: min(620px, calc(100dvh - 84px - env(safe-area-inset-bottom)));
    border-radius: 20px 20px 15px 15px;
    transform-origin: center bottom;
  }

  .cwp-chat-root.has-mobile-cta .cwp-chat-launcher {
    bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .cwp-chat-root.has-mobile-cta .cwp-chat-panel {
    bottom: calc(68px + env(safe-area-inset-bottom));
  }

  .cwp-chat-body {
    padding: 15px 13px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-panel {
    top: var(--cwp-visual-offset-top, 0px);
    right: 0;
    bottom: auto;
    width: 100vw;
    height: var(--cwp-visual-height, 100dvh);
    max-height: none;
    border: 0;
    border-radius: 0;
    transform: none;
    transition: none;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-head {
    min-height: 58px;
    padding: 8px 10px 8px 12px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-close {
    width: 38px;
    height: 38px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px 10px 6px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-body > :first-child {
    margin-top: auto;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-message {
    margin-bottom: 8px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-bubble {
    max-width: 90%;
    padding: 9px 11px;
    font-size: .84rem;
    line-height: 1.5;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-quick {
    gap: 6px;
    margin: 2px 0 6px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-quick button {
    min-height: 34px;
    padding: 6px 9px;
    font-size: .75rem;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-footer {
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-form {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 7px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-input,
  .cwp-chat-root.is-keyboard-open .cwp-chat-send {
    height: 44px;
  }

  .cwp-chat-root.is-keyboard-open .cwp-chat-contact,
  .cwp-chat-root.is-keyboard-open .cwp-chat-note {
    display: none;
  }
}

@media (max-width: 420px) {
  .cwp-chat-launcher span { display: none; }
  .cwp-chat-launcher {
    width: 50px;
    padding: 0;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cwp-chat-launcher,
  .cwp-chat-panel,
  .cwp-chat-typing i,
  .cwp-chat-message,
  .cwp-chat-quick button,
  .cwp-chat-send,
  .cwp-chat-send svg,
  .cwp-chat-close,
  .cwp-chat-contact {
    transition: none;
    animation: none;
  }

  .cwp-chat-body { scroll-behavior: auto; }
}

/* Refined launcher: quieter on mobile, with a clear AI badge. */
.cwp-chat-launcher {
  box-shadow: 0 12px 28px rgba(8, 20, 44, .22), inset 0 1px 0 rgba(255, 255, 255, .18);
}

.cwp-chat-launcher::after {
  display: none;
}

@media (max-width: 860px) {
  .cwp-chat-launcher {
    right: 16px;
    min-height: 48px;
    padding: 0 15px;
    box-shadow: 0 8px 20px rgba(8, 20, 44, .17), inset 0 1px 0 rgba(255, 255, 255, .16);
  }

  .cwp-chat-root.has-mobile-cta .cwp-chat-launcher {
    bottom: calc(84px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 420px) {
  .cwp-chat-launcher {
    width: 48px;
    height: 48px;
    min-height: 48px;
    overflow: visible;
    padding: 0;
  }

  .cwp-chat-launcher::after {
    content: "";
    position: absolute;
    right: 2px;
    top: 2px;
    width: 9px;
    height: 9px;
    min-width: 0;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    display: block;
    background: #f06b3f;
    box-shadow: 0 0 0 2px rgba(240, 107, 63, .14);
  }

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

@media (max-width: 860px) {
  .cwp-chat-root.is-cta-overlap:not(.is-open) .cwp-chat-launcher {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(8px) scale(.94);
  }
}
