.dgcrm-site-chat {
  --dgcrm-chat-side-offset: 12px;
  --dgcrm-chat-bottom-offset: calc(var(--dgcrm-chat-side-offset) + env(safe-area-inset-bottom, 0px));
  --dgcrm-chat-primary: #2e5aa7;
  --dgcrm-chat-primary-dark: #18315d;
  --dgcrm-chat-primary-soft: #86c5ff;
  --dgcrm-chat-surface: #ffffff;
  --dgcrm-chat-surface-blue: #f2f8ff;
  --dgcrm-chat-line: #dbe8f6;
  --dgcrm-chat-text: #18315d;
  --dgcrm-chat-muted: #58739b;
  --dgcrm-chat-shadow-soft: 0 14px 30px rgba(46, 90, 167, 0.14);
  --dgcrm-chat-shadow-window: 0 22px 54px rgba(46, 90, 167, 0.16);
  position: fixed;
  right: var(--dgcrm-chat-side-offset);
  bottom: var(--dgcrm-chat-bottom-offset);
  z-index: 10010;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.dgcrm-site-chat[hidden] {
  display: none !important;
}

.dgcrm-site-chat-toggle {
  display: inline-flex;
  align-items: stretch;
  justify-content: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--dgcrm-chat-primary) 0%, #4877ca 52%, var(--dgcrm-chat-primary-soft) 100%);
  color: #fff;
  box-shadow: var(--dgcrm-chat-shadow-soft);
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    opacity 0.18s ease;
}

.dgcrm-site-chat-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 36px rgba(46, 90, 167, 0.2);
}

.dgcrm-site-chat-toggle:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(134, 197, 255, 0.36),
    0 18px 36px rgba(46, 90, 167, 0.2);
}

.dgcrm-site-chat-toggle__eyebrow {
  display: none;
}

.dgcrm-site-chat-toggle__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 0;
  border-radius: inherit;
}

.dgcrm-site-chat-toggle__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}

.dgcrm-site-chat-toggle__icon svg {
  display: block;
  width: 22px;
  height: 22px;
}

.dgcrm-site-chat-toggle__text {
  display: none;
  white-space: nowrap;
  color: #fff;
}

.dgcrm-site-chat-backdrop {
  position: fixed;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(24, 49, 93, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    visibility 0s linear 0.18s;
}

.dgcrm-site-chat-window {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 0;
  display: flex;
  flex-direction: column;
  height: min(82vh, 760px);
  height: min(82dvh, 760px);
  max-height: calc(100vh - env(safe-area-inset-top, 0px) - 8px);
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 8px);
  background: var(--dgcrm-chat-surface);
  border: 1px solid var(--dgcrm-chat-line);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--dgcrm-chat-shadow-window);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(18px);
  transition:
    opacity 0.22s ease,
    transform 0.24s ease,
    visibility 0s linear 0.24s;
}

.dgcrm-site-chat.is-open .dgcrm-site-chat-backdrop {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.dgcrm-site-chat.is-open .dgcrm-site-chat-window {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
  transition:
    opacity 0.22s ease,
    transform 0.24s ease,
    visibility 0s linear 0s;
}

.dgcrm-site-chat.is-open .dgcrm-site-chat-toggle {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.96);
}

.dgcrm-site-chat-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 14px 12px;
  background: linear-gradient(135deg, var(--dgcrm-chat-primary-dark) 0%, var(--dgcrm-chat-primary) 58%, #4877ca 100%);
  color: #fff;
}

.dgcrm-site-chat-title {
  font-size: 17px;
  font-weight: 700;
}

.dgcrm-site-chat-sub {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.78);
}

.dgcrm-site-chat-close {
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.dgcrm-site-chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  background:
    radial-gradient(circle at top left, rgba(134, 197, 255, 0.18), transparent 34%),
    var(--dgcrm-chat-surface-blue);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}

.dgcrm-site-chat-message {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 14px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.05);
}

.dgcrm-site-chat-message.is-visitor {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--dgcrm-chat-primary-dark), var(--dgcrm-chat-primary));
  color: #fff;
  border-top-right-radius: 4px;
}

.dgcrm-site-chat-message.is-manager {
  align-self: flex-start;
  background: #fff;
  color: var(--dgcrm-chat-text);
  border: 1px solid var(--dgcrm-chat-line);
  border-top-left-radius: 4px;
}

.dgcrm-site-chat-message.is-system {
  align-self: center;
  max-width: 94%;
  background: #eaf4ff;
  color: var(--dgcrm-chat-muted);
  border: 1px solid var(--dgcrm-chat-line);
  box-shadow: none;
}

.dgcrm-site-chat-message.is-gift {
  padding: 10px;
}

.dgcrm-site-chat-gift {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.dgcrm-site-chat-gift img {
  display: block;
  width: 100%;
  max-width: 190px;
  height: auto;
  border-radius: 12px;
}

.dgcrm-site-chat-gift__title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--dgcrm-chat-text);
}

.dgcrm-site-chat-gift__text {
  font-size: 12px;
  line-height: 1.4;
  color: var(--dgcrm-chat-muted);
}

.dgcrm-site-chat-message.is-typing {
  opacity: 0.8;
  font-style: italic;
}

.dgcrm-site-chat-typing__body {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dgcrm-site-chat-typing__dots {
  display: inline-flex;
  align-items: flex-end;
  gap: 4px;
  min-width: 22px;
}

.dgcrm-site-chat-typing__dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: dgcrm-chat-typing-bounce 1.2s infinite ease-in-out;
}

.dgcrm-site-chat-typing__dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.dgcrm-site-chat-typing__dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.dgcrm-site-chat-message__meta {
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.72;
}

.dgcrm-site-chat-identify {
  padding: 0 12px 10px;
  background: #fff;
}

.dgcrm-site-chat-identify details {
  border: 1px solid var(--dgcrm-chat-line);
  border-radius: 14px;
  padding: 10px 12px;
}

.dgcrm-site-chat-identify summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--dgcrm-chat-text);
}

.dgcrm-site-chat-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.dgcrm-site-chat-note {
  font-size: 13px;
  line-height: 1.35;
  color: var(--dgcrm-chat-muted);
}

.dgcrm-site-chat-contact-tabs {
  display: grid;
  gap: 8px;
}

.dgcrm-site-chat-contact-tabs__row {
  display: grid;
  gap: 8px;
}

.dgcrm-site-chat-contact-tabs__row:first-child {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dgcrm-site-chat-contact-tabs__row:last-child {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dgcrm-site-chat-contact-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--dgcrm-chat-line);
  border-radius: 999px;
  background: #fff;
  color: var(--dgcrm-chat-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.dgcrm-site-chat-contact-tab span {
  white-space: nowrap;
}

.dgcrm-site-chat-contact-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(46, 90, 167, 0.08);
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.dgcrm-site-chat-contact-tab--icon-only {
  padding: 8px;
}

.dgcrm-site-chat-contact-tab.is-active {
  background: linear-gradient(135deg, var(--dgcrm-chat-primary), #4877ca);
  border-color: var(--dgcrm-chat-primary);
  color: #fff;
  box-shadow: 0 10px 24px rgba(46, 90, 167, 0.2);
}

.dgcrm-site-chat-contact-tab.is-active .dgcrm-site-chat-contact-badge {
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
}

.dgcrm-site-chat-input,
.dgcrm-site-chat-textarea {
  width: 100%;
  border: 1px solid var(--dgcrm-chat-line);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  box-sizing: border-box;
}

.dgcrm-site-chat-textarea {
  min-height: 80px;
  resize: vertical;
}

.dgcrm-site-chat-save {
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--dgcrm-chat-primary), #4877ca);
  color: #fff;
  padding: 11px 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(46, 90, 167, 0.18);
}

.dgcrm-site-chat-save[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.dgcrm-site-chat-compose {
  padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: #fff;
}

.dgcrm-site-chat-policy {
  margin-top: 10px;
  padding: 9px 12px;
  border: 1px solid var(--dgcrm-chat-line);
  border-radius: 12px;
  background: #fbfdff;
}

.dgcrm-site-chat-policy__note {
  font-size: 10px;
  line-height: 1.45;
  color: #6f83a3;
}

.dgcrm-site-chat-policy__note a {
  color: var(--dgcrm-chat-primary);
  text-decoration: none;
}

.dgcrm-site-chat-policy__note a:hover {
  text-decoration: underline;
}

.dgcrm-site-chat-policy__check {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.45;
  color: #6f83a3;
  cursor: pointer;
}

.dgcrm-site-chat-policy__check input {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  margin: 0;
}

.dgcrm-site-chat-policy__check span {
  display: inline;
}

.dgcrm-site-chat-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.dgcrm-site-chat-status {
  font-size: 12px;
  line-height: 1.3;
  color: var(--dgcrm-chat-muted);
}

.dgcrm-site-chat-send {
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--dgcrm-chat-primary), #4877ca);
  color: #fff;
  padding: 11px 16px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.dgcrm-site-chat-send[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
}

@keyframes dgcrm-chat-typing-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }

  40% {
    transform: translateY(-3px);
    opacity: 0.85;
  }
}

/* Tablet: compact pill trigger, regular floating chat window. */
@media (min-width: 768px) {
  .dgcrm-site-chat {
    --dgcrm-chat-side-offset: 14px;
    --dgcrm-chat-shadow-soft: 0 16px 34px rgba(46, 90, 167, 0.16);
  }

  .dgcrm-site-chat-toggle {
    width: auto;
    height: auto;
    padding: 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(219, 232, 246, 0.96);
    box-shadow:
      0 18px 42px rgba(46, 90, 167, 0.16),
      0 0 0 1px rgba(255, 255, 255, 0.72) inset;
  }

  .dgcrm-site-chat-toggle__cta {
    justify-content: flex-start;
    min-height: 48px;
    padding: 10px 14px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--dgcrm-chat-primary) 0%, #4877ca 58%, var(--dgcrm-chat-primary-soft) 100%);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.24),
      0 10px 22px rgba(46, 90, 167, 0.22);
  }

  .dgcrm-site-chat-toggle__icon {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
  }

  .dgcrm-site-chat-toggle__icon svg {
    width: auto;
    height: auto;
  }

  .dgcrm-site-chat-toggle__text--short {
    display: inline;
    font-size: 16px;
    line-height: 1.1;
    font-weight: 600;
  }

  .dgcrm-site-chat-backdrop {
    display: none;
  }

  .dgcrm-site-chat-window {
    position: absolute;
    left: auto;
    right: 0;
    bottom: 0;
    width: min(392px, calc(100vw - 28px));
    height: auto;
    max-height: min(78vh, 720px);
    max-height: min(78dvh, 720px);
    border-radius: 20px;
    transform: translateY(14px) scale(0.97);
    transform-origin: right bottom;
  }

  .dgcrm-site-chat-messages {
    max-height: 320px;
  }

  .dgcrm-site-chat-compose {
    padding-bottom: 14px;
  }
}

/* Desktop: expanded trigger follows the light blue site palette. */
@media (min-width: 1024px) {
  .dgcrm-site-chat {
    --dgcrm-chat-side-offset: 18px;
  }

  .dgcrm-site-chat-toggle {
    align-items: center;
    gap: 8px;
    width: min(250px, calc(100vw - 24px));
    padding: 12px;
    border: 1px solid rgba(219, 232, 246, 0.96);
    border-radius: 22px;
  }

  .dgcrm-site-chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow:
      0 24px 54px rgba(46, 90, 167, 0.22),
      0 0 0 1px rgba(255, 255, 255, 0.72) inset;
  }

  .dgcrm-site-chat-toggle:focus-visible {
    transform: translateY(-2px);
    box-shadow:
      0 0 0 3px rgba(134, 197, 255, 0.36),
      0 24px 54px rgba(46, 90, 167, 0.22);
  }

  .dgcrm-site-chat-toggle__eyebrow {
    display: flex;
    align-items: center;
    font-size: 13px;
    line-height: 1.2;
    font-weight: 700;
    color: var(--dgcrm-chat-text);
  }

  .dgcrm-site-chat-toggle__cta {
    min-height: 56px;
    padding: 10px 12px;
    border-radius: 18px;
  }

  .dgcrm-site-chat-toggle__icon {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.16);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  }

  .dgcrm-site-chat-toggle__icon svg {
    width: auto;
    height: auto;
  }

  .dgcrm-site-chat-toggle__text--short {
    display: none;
  }

  .dgcrm-site-chat-toggle__text--full {
    display: inline;
    font-size: 17px;
    line-height: 1.1;
    font-weight: 500;
    letter-spacing: 0.01em;
  }

  .dgcrm-site-chat-window {
    width: min(392px, calc(100vw - 24px));
  }
}

@media (max-width: 360px) {
  .dgcrm-site-chat {
    --dgcrm-chat-side-offset: 10px;
  }

  .dgcrm-site-chat-toggle {
    width: 50px;
    height: 50px;
  }

  .dgcrm-site-chat-window {
    left: 6px;
    right: 6px;
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - 6px);
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 6px);
  }

  .dgcrm-site-chat-head,
  .dgcrm-site-chat-identify,
  .dgcrm-site-chat-compose,
  .dgcrm-site-chat-messages {
    padding-left: 10px;
    padding-right: 10px;
  }
}
