/* Busy Guide widget — themeable via CSS custom properties
   All selectors prefixed with #dc-root / .dc- to avoid clinic CSS collisions. */

/* ── Theme defaults (Medix Gold/Noir) — overridden per-clinic by widget.js ── */
#dc-root {
  --dc-primary:        #c8a97e;
  --dc-primary-rgb:    200, 169, 126;
  --dc-primary-hover:  #b8945a;
  --dc-primary-active: #a88040;
  --dc-header-bg:      #1e1e1c;
}

/* ── Root anchor (bubble position) ─────────────────────────── */
#dc-root {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  right: 16px;
  z-index: 2147483647;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* reCAPTCHA v3 badge (Google wstrzykuje prawy-dół) — unieś ponad bąbel czatu,
   by się nie nakładały. Bąbel: 56-60px @ bottom 16-24px → top ~80px; badge nad nim. */
.grecaptcha-badge { bottom: 92px !important; }

/* ── Bubble ─────────────────────────────────────────────────── */
.dc-bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--dc-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(var(--dc-primary-rgb), 0.45);
  transition: background 0.2s, transform 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dc-bubble:hover { background: var(--dc-primary-hover); }
.dc-bubble:active { transform: scale(0.94); }
.dc-bubble:focus-visible {
  outline: 3px solid rgba(var(--dc-primary-rgb), 0.5);
  outline-offset: 2px;
}

/* ── Panel — MOBILE BASE (full-screen) ──────────────────────── */
.dc-panel {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 2147483646;
}
.dc-panel--open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ── Header ─────────────────────────────────────────────────── */
.dc-header {
  background: var(--dc-header-bg);
  color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(var(--dc-primary-rgb), 0.25);
}
.dc-header-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 300;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #e8e4dc;
}
.dc-close {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  margin-left: 8px;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dc-close:hover, .dc-close:active { color: var(--dc-primary); }

/* ── Messages ───────────────────────────────────────────────── */
.dc-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: #fafaf8;
}
.dc-msg {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 18px;
  word-wrap: break-word;
  font-size: 15px;
  font-weight: 300;
  line-height: 1.55;
}
.dc-msg--user {
  background: var(--dc-primary);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.dc-msg--assistant {
  background: #f0f0ee;
  color: #1a1a18;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

/* ── Input row ──────────────────────────────────────────────── */
.dc-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #e0e0dc;
  flex-shrink: 0;
  background: #fff;
}
.dc-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #d0d0cc;
  border-radius: 24px;
  padding: 11px 16px;
  font-size: 16px;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 300;
  color: #1a1a18;
  outline: none;
  transition: border-color 0.15s;
  background: #fafaf8;
}
.dc-input:focus { border-color: var(--dc-primary); }
.dc-input:disabled { background: #f5f5f3; color: #a0a09c; }

.dc-send {
  background: var(--dc-primary);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 400;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dc-send:hover:not(:disabled) { background: var(--dc-primary-hover); }
.dc-send:active:not(:disabled) { background: var(--dc-primary-active); }
.dc-send:disabled { background: rgba(var(--dc-primary-rgb), 0.4); cursor: not-allowed; }

/* ── Mic button ─────────────────────────────────────────────── */
.dc-mic {
  background: transparent;
  border: 1.5px solid #d0d0cc;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #888;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dc-mic:hover:not(:disabled) { border-color: var(--dc-primary); color: var(--dc-primary); }
.dc-mic:disabled { opacity: 0.4; cursor: not-allowed; }

.dc-mic--recording {
  border-color: #e03c3c;
  color: #e03c3c;
  background: rgba(224, 60, 60, 0.08);
  animation: dc-mic-pulse 1.2s infinite ease-in-out;
}

@keyframes dc-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 60, 60, 0.35); }
  50%       { box-shadow: 0 0 0 7px rgba(224, 60, 60, 0); }
}

/* ── Footer ─────────────────────────────────────────────────── */
.dc-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  font-size: 11px;
  font-weight: 300;
  color: #a0a09c;
  padding: 6px 16px 8px;
  background: #fff;
  flex-shrink: 0;
}

/* ── RODO: pasek zgody, stopka, panel klauzuli art. 13 ──────── */
.dc-consent {
  font-size: 11px;
  line-height: 1.45;
  font-weight: 300;
  color: #6b6b66;
  background: #f5f4f0;
  border-top: 1px solid #e0e0dc;
  padding: 8px 16px;
  flex-shrink: 0;
}
.dc-privacy-a {
  color: var(--dc-primary);
  text-decoration: underline;
}
.dc-privacy-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--dc-primary);
  text-decoration: underline;
  cursor: pointer;
}
.dc-privacy-link:hover { color: var(--dc-primary-hover); }
.dc-privacy-link:focus-visible,
.dc-privacy-a:focus-visible {
  outline: 2px solid rgba(var(--dc-primary-rgb), 0.6);
  outline-offset: 2px;
}

/* Nakładka nad całym panelem — czytelna klauzula bez opuszczania czatu. */
.dc-privacy {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dc-privacy[hidden] { display: none; }
.dc-privacy-head {
  background: var(--dc-header-bg);
  color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.dc-privacy-title {
  font-size: 14px;
  font-weight: 500;
}
.dc-privacy-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: #fafaf8;
  font-size: 13px;
  line-height: 1.55;
  color: #3a3a36;
}
.dc-privacy-h {
  margin: 14px 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: #1e1e1c;
}
.dc-privacy-h:first-child { margin-top: 0; }
.dc-privacy-p {
  margin: 0;
  font-weight: 300;
}

/* ── Typing indicator ───────────────────────────────────────── */
.dc-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 2px 0;
}
.dc-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dc-primary);
  animation: dc-bounce 1.1s infinite ease-in-out;
}
.dc-dots span:nth-child(2) { animation-delay: 0.18s; }
.dc-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dc-bounce {
  0%, 70%, 100% { transform: translateY(0) scale(0.7); opacity: 0.4; }
  35%            { transform: translateY(-5px) scale(1); opacity: 1; }
}

/* ── Persona (header avatar + name + status) ────────────────── */
.dc-persona {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.dc-persona-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.dc-header-status {
  font-size: 11px;
  font-weight: 300;
  color: rgba(232, 228, 220, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dc-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.dc-human {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  padding: 5px;
  display: flex;
  border-radius: 6px;
  transition: color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dc-human:hover:not(:disabled) { color: var(--dc-primary); }
.dc-human:disabled { opacity: 0.4; cursor: default; }

/* ── Avatar (persona) ───────────────────────────────────────── */
.dc-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--dc-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  overflow: hidden;
}
.dc-avatar--sm {
  width: 26px;
  height: 26px;
  font-size: 12px;
  align-self: flex-end;
  margin-bottom: 2px;
}
.dc-avatar-img { width: 100%; height: 100%; object-fit: cover; }

/* ── Message rows (avatar + bubble) ─────────────────────────── */
.dc-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}
.dc-row--user { justify-content: flex-end; }
.dc-row--assistant { justify-content: flex-start; }
.dc-row .dc-msg { align-self: auto; }
.dc-row--assistant .dc-msg { max-width: calc(100% - 40px); }

/* ── Markdown inside bubbles ────────────────────────────────── */
.dc-msg a { color: inherit; text-decoration: underline; word-break: break-word; }
.dc-msg--assistant a { color: var(--dc-primary-active); }
.dc-msg strong { font-weight: 600; }
.dc-msg ul, .dc-msg ol { margin: 6px 0; padding-left: 20px; }
.dc-msg li { margin: 2px 0; }
.dc-msg code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── Quick-reply chips ──────────────────────────────────────── */
.dc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-left: 34px;
}
.dc-chip {
  background: #fff;
  border: 1.5px solid var(--dc-primary);
  color: var(--dc-primary);
  border-radius: 16px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dc-chip:hover { background: var(--dc-primary); color: #fff; }
.dc-chip:active { background: var(--dc-primary-active); }

/* ── Retry button (after error) ─────────────────────────────── */
.dc-retry {
  margin-top: 6px;
  background: transparent;
  border: 1px solid var(--dc-primary);
  color: var(--dc-primary);
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dc-retry:hover { background: var(--dc-primary); color: #fff; }

/* ── Proactive teaser bubble ────────────────────────────────── */
.dc-teaser {
  position: absolute;
  bottom: 76px;
  right: 0;
  /* width: max-content — bez tego shrink-to-fit liczy się od szerokości
     #dc-root (~56px, sam bąbel) i teaser łamie się co słowo w pionową nitkę. */
  width: max-content;
  max-width: 240px;
  background: #fff;
  color: #1a1a18;
  border-radius: 14px;
  padding: 12px 30px 12px 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 14px;
  font-weight: 300;
  line-height: 1.4;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.dc-teaser--show { opacity: 1; transform: translateY(0); }
.dc-teaser-close {
  position: absolute;
  top: 4px;
  right: 6px;
  background: transparent;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: #a0a09c;
  cursor: pointer;
  padding: 2px 4px;
}
.dc-teaser-close:hover { color: #1a1a18; }

/* ── Desktop override (≥ 500px) ─────────────────────────────── */
@media (min-width: 500px) {
  #dc-root {
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    right: 24px;
  }
  .dc-bubble {
    width: 56px;
    height: 56px;
  }
  .dc-panel {
    position: absolute;
    inset: auto;
    bottom: 68px;
    right: 0;
    width: 370px;
    height: auto;
    max-height: 560px;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.16);
    transform: translateY(12px) scale(0.97);
  }
  .dc-panel--open {
    transform: translateY(0) scale(1);
  }
  .dc-header {
    padding-top: 14px;
    border-radius: 16px 16px 0 0;
  }
  .dc-input-row {
    padding-bottom: 12px;
  }
  .dc-msg {
    font-size: 14px;
  }
  .dc-input {
    font-size: 14px;
    border-radius: 8px;
    padding: 9px 12px;
  }
  .dc-send {
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
  }
  .dc-mic {
    width: 36px;
    height: 36px;
  }
}
