/* ──────────────────────────────────────────────────────────────────
   DoorKnockers chatbot widget — floating chat bubble, panel, modal.
   All brand colors come from theme.css variables so widget restyles
   automatically when the theme changes. Scoped under .dk-chat to
   avoid bleeding into other components.
   ────────────────────────────────────────────────────────────────── */

.dk-chat, .dk-chat * {
  box-sizing: border-box;
}

.dk-chat-sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.dk-chat {
  position: fixed;
  z-index: 9998;
  bottom: 24px;
  right: 24px;
  font-family: var(--font-brand, 'Poppins', sans-serif);
  color: var(--fg, #14283D);
  /* Render high so it sits above nav/footer overlays on every page. */
}

/* ── Floating toggle button ─────────────────────────────────────── */

.dk-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--color-sage, #557B66);
  color: var(--color-navy, #14283D);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 30px rgba(20, 40, 61, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  z-index: 9999;
}
.dk-chat-toggle:hover, .dk-chat-toggle:focus-visible {
  background: var(--color-mist, #96BEAA);
  transform: translateY(-2px);
  outline: none;
}
.dk-chat-toggle .dk-chat-icon-close { display: none; }
.dk-chat-root-open .dk-chat-toggle .dk-chat-icon-open { display: none; }
.dk-chat-root-open .dk-chat-toggle .dk-chat-icon-close { display: block; }

/* ── Chat panel ─────────────────────────────────────────────────── */

.dk-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 130px);
  background: var(--bg-card, #FFFFFF);
  border-radius: 16px;
  border: 1px solid var(--border, rgba(20, 40, 61, 0.10));
  box-shadow: 0 24px 60px rgba(20, 40, 61, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.dk-chat-root-open .dk-chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.dk-chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-navy, #14283D);
  color: var(--color-cream, #FAF7F2);
  padding: 14px 16px;
}
.dk-chat-header-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.dk-chat-wordmark {
  font-weight: 700;
  letter-spacing: -0.3px;
  font-size: 17px;
}
.dk-chat-sub {
  font-size: 0.75rem;
  color: var(--color-mist, #96BEAA);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.dk-chat-close {
  background: transparent;
  border: none;
  color: var(--color-cream, #FAF7F2);
  opacity: 0.85;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dk-chat-close:hover { opacity: 1; background: rgba(255,255,255,0.08); }

/* ── Message body (scrollable) ────────────────────────────────── */

.dk-chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  background: var(--bg, #FAF7F2);
  padding: 14px 14px 6px;
  scroll-behavior: smooth;
}
.dk-chat-message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dk-chat-msg {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  /* Allow <a> tags that we inject to be clickable & styled. */
}
.dk-chat-msg a {
  color: var(--color-sage, #557B66);
  text-decoration: underline;
  font-weight: 600;
}
.dk-chat-msg-bot {
  background: var(--bg-card, #FFFFFF);
  border: 1px solid var(--border, rgba(20,40,61,0.10));
  color: var(--fg, #14283D);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.dk-chat-msg-user {
  background: var(--color-sage, #557B66);
  color: #ffffff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.dk-chat-msg-user a {
  color: var(--color-cream, #FAF7F2);
}

/* ── Quick-reply chips ─────────────────────────────────────────── */

.dk-chat-quickreplies {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-card, #FFFFFF);
  border-top: 1px solid var(--border, rgba(20,40,61,0.10));
}
.dk-chat-chip {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--accent-dim, rgba(85,123,102,0.08));
  border: 1px solid var(--border, rgba(20,40,61,0.10));
  color: var(--accent, #557B66);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.dk-chat-chip:hover {
  background: var(--color-sage, #557B66);
  color: #ffffff;
  transform: translateY(-1px);
}
.dk-chat-chip-escalate {
  background: var(--color-navy, #14283D);
  color: var(--color-cream, #FAF7F2);
  border-color: var(--color-navy, #14283D);
}
.dk-chat-chip-escalate:hover {
  background: var(--color-sage, #557B66);
  border-color: var(--color-sage, #557B66);
}

/* ── Input row ─────────────────────────────────────────────────── */

.dk-chat-input-row {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  background: var(--bg-card, #FFFFFF);
  border-top: 1px solid var(--border, rgba(20,40,61,0.10));
}
.dk-chat-input-row textarea {
  flex: 1 1 auto;
  resize: none;
  min-height: 38px;
  max-height: 100px;
  padding: 9px 12px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--fg, #14283D);
  background: var(--bg, #FAF7F2);
  border: 1px solid var(--border, rgba(20,40,61,0.10));
  border-radius: 12px;
  outline: none;
  line-height: 1.35;
}
.dk-chat-input-row textarea:focus {
  border-color: var(--accent, #557B66);
  background: var(--bg-card, #FFFFFF);
}
.dk-chat-send {
  background: var(--color-sage, #557B66);
  color: #ffffff;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.dk-chat-send:hover {
  background: var(--color-mist, #96BEAA);
  transform: translateY(-1px);
}
.dk-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Footer line ──────────────────────────────────────────────── */

.dk-chat-foot {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: var(--fg-muted, #5A6E7F);
  text-align: center;
  padding: 6px 12px 8px;
  background: var(--bg-card, #FFFFFF);
}
.dk-chat-foot a {
  color: var(--accent, #557B66);
  text-decoration: none;
  font-weight: 600;
}
.dk-chat-foot a:hover { text-decoration: underline; }

/* ── Escalation modal ─────────────────────────────────────────── */

.dk-chat-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 61, 0.45);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.dk-chat-modal-backdrop:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}
.dk-chat-modal {
  background: var(--bg-card, #FFFFFF);
  border-radius: 18px;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(20, 40, 61, 0.35);
  padding: 22px;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}
.dk-chat-modal-backdrop:not([hidden]) .dk-chat-modal {
  transform: translateY(0) scale(1);
}
.dk-chat-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.dk-chat-modal-header h3 {
  font-family: var(--font-brand, 'Poppins', sans-serif);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--fg, #14283D);
  margin: 0;
}
.dk-chat-modal-close {
  background: transparent;
  border: none;
  color: var(--fg-muted, #5A6E7F);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dk-chat-modal-close:hover { background: var(--accent-dim, rgba(85,123,102,0.08)); color: var(--fg, #14283D); }
.dk-chat-modal-intro {
  font-size: 0.88rem;
  color: var(--fg-muted, #5A6E7F);
  margin: 0 0 14px;
  line-height: 1.5;
}
.dk-chat-modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dk-chat-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg-muted, #5A6E7F);
}
.dk-chat-field input, .dk-chat-field textarea {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 400;
  padding: 9px 12px;
  border: 1px solid var(--border, rgba(20,40,61,0.12));
  border-radius: 10px;
  background: var(--bg, #FAF7F2);
  color: var(--fg, #14283D);
  resize: vertical;
}
.dk-chat-field input:focus, .dk-chat-field textarea:focus {
  outline: none;
  border-color: var(--accent, #557B66);
  background: var(--bg-card, #FFFFFF);
}
.dk-chat-honeypot {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}
.dk-chat-modal-feedback {
  font-size: 0.82rem;
  min-height: 1rem;
  color: var(--fg-muted, #5A6E7F);
}
.dk-chat-modal-feedback.is-success { color: var(--color-sage, #557B66); }
.dk-chat-modal-feedback.is-error   { color: #B91C1C; }
.dk-chat-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
.dk-chat-modal-cancel {
  background: transparent;
  color: var(--fg-muted, #5A6E7F);
  border: 1px solid var(--border, rgba(20,40,61,0.10));
  padding: 9px 18px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.dk-chat-modal-cancel:hover { background: var(--accent-dim, rgba(85,123,102,0.08)); }
.dk-chat-modal-submit {
  background: var(--color-sage, #557B66);
  color: #ffffff;
  border: none;
  padding: 9px 20px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.dk-chat-modal-submit:hover:not(:disabled) {
  background: var(--color-mist, #96BEAA);
}
.dk-chat-modal-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Mobile full-width bottom sheet ──────────────────────────── */

@media (max-width: 640px) {
  .dk-chat-panel {
    position: fixed;
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 92px;
    height: calc(100vh - 110px);
    max-height: none;
  }
  .dk-chat-modal {
    max-width: 100%;
  }
  .dk-chat {
    right: 12px;
    bottom: 12px;
  }
  .dk-chat-toggle {
    right: 12px;
    bottom: 12px;
  }
}

/* ── Reduced motion: drop the bounce-in transition ──────────── */

@media (prefers-reduced-motion: reduce) {
  .dk-chat-panel,
  .dk-chat-modal,
  .dk-chat-modal-backdrop {
    transition: none !important;
  }
  .dk-chat-toggle, .dk-chat-chip, .dk-chat-send, .dk-chat-modal-submit {
    transition: none !important;
  }
}
