/* Support widget for distancedefender.ntinno.net.
 *
 * Built on the site's own custom properties rather than a parallel palette, so
 * a change to --accent or --radius-card moves the widget with everything else.
 * The ntinno.net widget was dark, teal and Tailwind-compiled; nothing of its
 * styling transfers here, only its markup contract.
 *
 * The site declares no dark theme and no reduced-motion handling. This file
 * follows it on the first and does not follow it on the second: honouring
 * prefers-reduced-motion costs nothing and the widget is the only thing on the
 * page that animates.
 */

/* Every var() below carries a fallback, and that is not belt-and-braces.
 * The four pages of this site do not declare the same token set: the blog post
 * defines neither --bg-body nor --radius-card, and the user guide defines
 * neither --shadow-card nor --radius-btn. A missing custom property makes the
 * whole declaration invalid at computed-value time, so the panel would have
 * rendered transparent with square corners on the blog page. The site's token
 * still wins wherever it exists.
 */

.dd-chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 90;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 100px;
  background: var(--accent, #007AFF);
  color: #fff;
  cursor: pointer;
  /* The site's own button shadow, already tinted with the accent. */
  box-shadow: 0 10px 20px rgba(0, 122, 255, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.dd-chat-launcher:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(0, 122, 255, 0.28);
}

.dd-chat-launcher svg {
  width: 24px;
  height: 24px;
  display: block;
}

.dd-chat-launcher[aria-expanded="true"] {
  /* Fades rather than disappears, so the panel does not seem to erupt from
     nothing on a slow connection. */
  opacity: 0;
  pointer-events: none;
}

.dd-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  width: min(400px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 48px));
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border, #D2D2D7);
  border-radius: var(--radius-card, 20px);
  /* Opaque. The panel sits over body copy, and the one thing it must do is be
     readable while someone follows a numbered instruction from it. */
  background: var(--bg-body, #FFFFFF);
  box-shadow: var(--shadow-card, 0 20px 40px rgba(0, 0, 0, 0.06));
}

.dd-chat-panel.is-open {
  display: flex;
}

.dd-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, #D2D2D7);
  background: var(--bg-alt, #F5F5F7);
}

.dd-chat-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main, #1D1D1F);
  margin: 0;
}

.dd-chat-sub {
  font-size: 12px;
  color: var(--text-secondary, #6E6E73);
  margin: 2px 0 0;
}

.dd-chat-close {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #6E6E73);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.dd-chat-close:hover {
  background: var(--accent-soft, rgba(0, 122, 255, 0.1));
  color: var(--accent, #007AFF);
}

.dd-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Momentum scrolling inside the panel rather than the page behind it. */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.dd-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.dd-msg-user {
  align-self: flex-end;
  background: var(--accent, #007AFF);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.dd-msg-agent {
  align-self: flex-start;
  background: var(--bg-alt, #F5F5F7);
  color: var(--text-main, #1D1D1F);
  border-bottom-left-radius: 6px;
}

.dd-msg-agent strong {
  font-weight: 600;
}

.dd-msg-error {
  align-self: flex-start;
  background: rgba(255, 59, 48, 0.08);
  color: #b3271f;
  border-bottom-left-radius: 6px;
}

.dd-msg.is-pending {
  opacity: 0.6;
}

.dd-sources {
  align-self: flex-start;
  font-size: 11px;
  color: var(--text-secondary, #6E6E73);
  padding-left: 4px;
}

.dd-chat-foot {
  border-top: 1px solid var(--border, #D2D2D7);
  padding: 12px;
  background: var(--bg-body, #FFFFFF);
}

.dd-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.dd-chat-input {
  flex: 1;
  /* Auto-grows in script; starts at one line and stops at five so a long
     question never swallows the conversation above it. */
  min-height: 38px;
  max-height: 116px;
  padding: 9px 12px;
  border: 1px solid var(--border, #D2D2D7);
  border-radius: var(--radius-btn, 12px);
  background: var(--bg-body, #FFFFFF);
  color: var(--text-main, #1D1D1F);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
}

.dd-chat-input:focus {
  outline: none;
  border-color: var(--accent, #007AFF);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(0, 122, 255, 0.1));
}

.dd-chat-input::placeholder {
  color: var(--text-secondary, #6E6E73);
}

/* Sized for text, not an icon: the script writes "Ask" here, or "…" while the
   Turnstile token is still being minted. That label is the only signal a
   visitor gets that the wait is deliberate rather than a broken button, which
   is why it is not replaced with a static arrow. */
.dd-chat-send {
  flex: none;
  min-width: 52px;
  height: 38px;
  padding: 0 14px;
  display: grid;
  place-items: center;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 0;
  border-radius: var(--radius-btn, 12px);
  background: var(--accent, #007AFF);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.dd-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.dd-chat-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-secondary, #6E6E73);
}

/* Turnstile renders on page load rather than on panel open, because minting a
   token takes a few seconds and doing it lazily made the send button look
   broken. It is interaction-only, so usually this box is empty. */
.dd-chat-turnstile {
  min-height: 0;
}

.dd-chat-turnstile.needs-attention {
  border-radius: 8px;
  outline: 2px solid var(--accent, #007AFF);
  outline-offset: 3px;
}

:where(.dd-chat-launcher, .dd-chat-close, .dd-chat-send, .dd-chat-input):focus-visible {
  outline: 2px solid var(--accent, #007AFF);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .dd-chat-launcher,
  .dd-chat-close,
  .dd-chat-send {
    transition: none;
  }
  .dd-chat-launcher:hover {
    transform: none;
  }
}
