:root {
  --dco-primary: #0b3d91;
  --dco-primary-dark: #082d6b;
  --dco-accent: #00a3e0;
  --dco-bg: #ffffff;
  --dco-text: #1a1a2e;
  --dco-muted: #6b7280;
  --dco-border: #e5e7eb;
  --dco-shadow: 0 12px 40px rgba(11, 61, 145, 0.18);
}

#dco-assistant-root {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#dco-assistant-toggle {
  position: relative;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--dco-primary), var(--dco-accent));
  color: #fff;
  cursor: pointer;
  box-shadow: var(--dco-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#dco-assistant-toggle:hover {
  transform: scale(1.05);
}

/* A soft ring while the invitation is showing, to draw the eye to the button. */
#dco-assistant-toggle.has-invite::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--dco-accent);
  opacity: 0;
  animation: dco-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

@keyframes dco-pulse {
  0% {
    transform: scale(0.9);
    opacity: 0.7;
  }
  70% {
    transform: scale(1.18);
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

/* An author display rule beats the hidden attribute, so restore it explicitly.
   Without this the dismissed banner stays an invisible click target. */
#dco-assistant-invite[hidden] {
  display: none;
}

#dco-assistant-invite {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  position: relative;
  max-width: min(290px, calc(100vw - 48px));
  margin-bottom: 14px;
  padding: 12px 8px 13px 15px;
  background: var(--dco-bg);
  border: 1px solid var(--dco-border);
  border-radius: 16px;
  box-shadow: var(--dco-shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#dco-assistant-invite.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Tail pointing down at the chat button. */
#dco-assistant-invite::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--dco-bg);
  border-right: 1px solid var(--dco-border);
  border-bottom: 1px solid var(--dco-border);
  transform: rotate(45deg);
}

#dco-assistant-invite-open {
  display: block;
  flex: 1;
  padding: 0;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--dco-text);
}

#dco-assistant-invite-open strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--dco-primary);
}

#dco-assistant-invite-open span {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--dco-muted);
}

#dco-assistant-invite-open:hover strong {
  text-decoration: underline;
}

#dco-assistant-invite-close {
  flex: none;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--dco-muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

#dco-assistant-invite-close:hover {
  background: #f1f5f9;
  color: var(--dco-text);
}

#dco-assistant-toggle svg {
  width: 28px;
  height: 28px;
}

#dco-assistant-panel {
  display: none;
  flex-direction: column;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 100px));
  margin-bottom: 14px;
  background: var(--dco-bg);
  border-radius: 16px;
  box-shadow: var(--dco-shadow);
  overflow: hidden;
  border: 1px solid var(--dco-border);
}

#dco-assistant-panel.is-open {
  display: flex;
}

#dco-assistant-header {
  background: linear-gradient(135deg, var(--dco-primary), var(--dco-primary-dark));
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#dco-assistant-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  /* Themes sometimes set a global h2 color and text-shadow; win over both. */
  color: #fff !important;
  text-shadow: none;
  font-family: inherit;
}

#dco-assistant-close {
  background: transparent;
  border: none;
  color: #fff !important;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
}

#dco-assistant-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8fafc;
}

.dco-msg {
  max-width: 92%;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.dco-msg.user {
  margin-left: auto;
  background: var(--dco-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.dco-msg.bot {
  background: #fff;
  color: var(--dco-text);
  border: 1px solid var(--dco-border);
  border-bottom-left-radius: 4px;
}

.dco-msg.bot a {
  color: var(--dco-primary);
}

.dco-msg.loading {
  color: var(--dco-muted);
  font-style: italic;
}

.dco-sources {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--dco-border);
}

.dco-sources-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--dco-muted);
}

.dco-sources a {
  font-size: 12px;
  color: var(--dco-primary);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dco-sources a:hover {
  text-decoration: underline;
}

#dco-assistant-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--dco-border);
  background: #fff;
}

#dco-assistant-input {
  flex: 1;
  border: 1px solid var(--dco-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}

#dco-assistant-input:focus {
  border-color: var(--dco-accent);
  box-shadow: 0 0 0 3px rgba(0, 163, 224, 0.15);
}

#dco-assistant-send {
  border: none;
  border-radius: 10px;
  background: var(--dco-primary);
  color: #fff;
  padding: 0 16px;
  font-weight: 600;
  cursor: pointer;
}

#dco-assistant-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#dco-assistant-disclaimer {
  padding: 0 14px 10px;
  font-size: 11px;
  color: var(--dco-muted);
  background: #fff;
}

@media (max-width: 480px) {
  #dco-assistant-root {
    right: 16px;
    bottom: 16px;
  }

  /* Keep the invitation compact so it never sits over page content. */
  #dco-assistant-invite {
    max-width: calc(100vw - 60px);
    padding: 10px 6px 11px 13px;
  }

  #dco-assistant-invite-open strong {
    font-size: 13px;
  }

  #dco-assistant-invite-open span {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #dco-assistant-invite {
    transition: none;
    transform: none;
  }

  #dco-assistant-toggle,
  #dco-assistant-toggle:hover {
    transition: none;
    transform: none;
  }

  #dco-assistant-toggle.has-invite::after {
    animation: none;
  }
}
