/* Patriot MedBill AI chat widget — scoped under #pmb-chat-widget to avoid
   clashing with host-site styles. */
#pmb-chat-widget,
#pmb-chat-widget * {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#pmb-chat-widget {
  /* Patriot MedBill palette: flag red (#b22234) accent + deep navy (#162d56). */
  --dz-primary: #b22234;        /* readable patriot red for text/links/borders */
  --dz-primary-dark: #8e1b29;
  --dz-grad: linear-gradient(135deg, #be1f31 0%, #b22234 55%, #8e1b29 100%); /* red fills */
  --dz-header: linear-gradient(135deg, #1d3a6b 0%, #162d56 100%);            /* deep navy header */
  --dz-bg: #ffffff;
  --dz-user: linear-gradient(135deg, #be1f31, #8e1b29);
  --dz-bot: #f2f4f8;
  --dz-text: #1a2233;
  --dz-glow: rgba(178, 34, 52, 0.22);   /* red input focus glow */
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2147483000;
}

/* ---- launcher -------------------------------------------------------- */
#pmb-chat-launcher {
  position: relative;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--dz-grad);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(178, 34, 52, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: dz-pulse 2.6s ease-out infinite;
}
#pmb-chat-launcher:hover { transform: scale(1.06); box-shadow: 0 10px 30px rgba(178, 34, 52, 0.6); }
#pmb-chat-launcher:focus-visible { outline: 3px solid rgba(178, 34, 52, 0.55); outline-offset: 3px; }
#pmb-chat-widget.open #pmb-chat-launcher { animation: none; }
.dz-ico { position: absolute; width: 28px; height: 28px; transition: opacity 0.2s ease, transform 0.25s ease; }
.dz-ico-close { opacity: 0; transform: rotate(-90deg) scale(0.6); }
#pmb-chat-widget.open .dz-ico-open { opacity: 0; transform: rotate(90deg) scale(0.6); }
#pmb-chat-widget.open .dz-ico-close { opacity: 1; transform: none; }
@keyframes dz-pulse {
  0% { box-shadow: 0 8px 24px rgba(178, 34, 52, 0.5), 0 0 0 0 rgba(178, 34, 52, 0.45); }
  70% { box-shadow: 0 8px 24px rgba(178, 34, 52, 0.5), 0 0 0 16px rgba(178, 34, 52, 0); }
  100% { box-shadow: 0 8px 24px rgba(178, 34, 52, 0.5), 0 0 0 0 rgba(178, 34, 52, 0); }
}

/* ---- panel (animated open) ------------------------------------------ */
#pmb-chat-panel {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--dz-bg);
  border-radius: 18px;
  box-shadow: 0 16px 56px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.22s;
}
#pmb-chat-widget.open #pmb-chat-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ---- header ---------------------------------------------------------- */
.dz-header {
  position: relative;
  background: var(--dz-header);
  color: #fff;
  padding: 13px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  box-shadow: inset 0 -3px 0 0 rgba(178, 34, 52, 0.95);  /* red brand underline */
}
/* soft top highlight for depth */
.dz-header::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 140% at 0% 0%, rgba(255, 255, 255, 0.14), transparent 55%);
}
.dz-header > * { position: relative; }
/* meta grows + truncates so the action buttons always stay on screen */
.dz-head-meta { flex: 1 1 auto; min-width: 0; }
.dz-header h3 {
  margin: 0; font-size: 15px; font-weight: 700; letter-spacing: 0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dz-header p {
  margin: 2px 0 0; font-size: 11.5px; opacity: 0.92; display: flex; align-items: center; gap: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dz-dot { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.7); animation: dz-blink 1.8s infinite; }
@keyframes dz-blink { 0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6); } 70% { box-shadow: 0 0 0 6px rgba(61, 220, 132, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); } }
.dz-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--dz-grad);
  box-shadow: 0 2px 8px rgba(178, 34, 52, 0.5);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
/* unified header icon buttons (new chat, voice, contact, close) */
.dz-header .dz-hbtn {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  border: none; cursor: pointer; text-decoration: none;
  background: rgba(255, 255, 255, 0.16); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}
.dz-header .dz-hbtn:hover { background: rgba(255, 255, 255, 0.32); transform: translateY(-1px); }
.dz-header .dz-hbtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.dz-header .dz-hbtn svg { width: 16px; height: 16px; }
/* inter-button spacing comes from the header's flex `gap`; no extra margin */
/* voice toggle on/off icon swap + active state */
.dz-header .dz-voice.active { background: #fff; color: var(--dz-primary); }
.dz-header .dz-voice .dz-ic-on { display: none; }
.dz-header .dz-voice .dz-ic-off { display: block; }
.dz-header .dz-voice.active .dz-ic-on { display: block; }
.dz-header .dz-voice.active .dz-ic-off { display: none; }
.dz-header .dz-contact svg { width: 15px; height: 15px; }
.dz-header .dz-close { font-size: 20px; line-height: 1; }

/* ---- messages -------------------------------------------------------- */
.dz-messages {
  flex: 1;
  padding: 18px 16px;
  overflow-y: auto;
  background: #fafbfe;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.dz-messages::-webkit-scrollbar { width: 8px; }
.dz-messages::-webkit-scrollbar-thumb { background: #ccd3e3; border-radius: 8px; }
.dz-messages::-webkit-scrollbar-thumb:hover { background: #aab4cc; }

.dz-msg {
  max-width: 86%; padding: 11px 14px; border-radius: 16px; font-size: 14px; line-height: 1.55;
  word-wrap: break-word; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  animation: dz-rise 0.28s ease both;
}
@keyframes dz-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.dz-msg.user { align-self: flex-end; background: var(--dz-user); color: #fff; border-bottom-right-radius: 5px; white-space: pre-wrap; box-shadow: 0 2px 6px rgba(178, 34, 52, 0.25); }
.dz-msg.bot { align-self: flex-start; background: var(--dz-bot); color: var(--dz-text); border: 1px solid #e6eaf2; border-bottom-left-radius: 5px; }
.dz-msg.bot a { color: var(--dz-primary); font-weight: 600; text-decoration: none; border-bottom: 1px solid rgba(178, 34, 52, 0.35); }
.dz-msg.bot a:hover { border-bottom-color: var(--dz-primary); }
.dz-msg.bot p { margin: 0 0 8px; }
.dz-msg.bot p:last-child { margin-bottom: 0; }
.dz-msg.bot p.dz-h { margin: 10px 0 4px; font-size: 14px; color: #0f1b33; }
.dz-msg.bot p.dz-h:first-child { margin-top: 0; }
.dz-msg.bot ul, .dz-msg.bot ol { margin: 6px 0; padding-left: 20px; }
.dz-msg.bot li { margin: 3px 0; }
.dz-msg.bot strong { font-weight: 700; }
.dz-msg.bot code { background: #e4e8f1; padding: 1px 5px; border-radius: 5px; font-size: 13px; }
/* inline call-to-action buttons (Schedule / Contact Us) under a bot reply */
.dz-cta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.dz-cta {
  display: inline-flex; align-items: center; gap: 7px;
  color: #fff !important; text-decoration: none;
  font-size: 13px; font-weight: 600; padding: 9px 15px; border-radius: 22px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.dz-cta:hover { transform: translateY(-1px); }
.dz-cta:focus-visible { outline: 2px solid var(--dz-primary); outline-offset: 2px; }
.dz-cta svg { width: 15px; height: 15px; }
/* Contact Us — red brand gradient */
.dz-cta-contact { background: var(--dz-grad); box-shadow: 0 3px 10px rgba(178, 34, 52, 0.4); }
.dz-cta-contact:hover { box-shadow: 0 5px 16px rgba(178, 34, 52, 0.5); }
/* Schedule Now — navy gradient to stand apart from Contact */
.dz-cta-schedule { background: var(--dz-header); box-shadow: 0 3px 10px rgba(22, 45, 86, 0.4); }
.dz-cta-schedule:hover { box-shadow: 0 5px 16px rgba(22, 45, 86, 0.55); }

/* quick-reply chips */
.dz-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 16px 10px; background: #fafbfe; }
.dz-chips:empty { display: none; }
.dz-chip {
  background: #fff; border: 1px solid #cdd5e6; color: var(--dz-primary);
  border-radius: 18px; padding: 7px 13px; font-size: 13px; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.dz-chip:hover { background: var(--dz-grad); color: #fff; border-color: transparent; transform: translateY(-1px); }

/* typing indicator */
.dz-typing { align-self: flex-start; display: flex; gap: 4px; padding: 13px 15px; background: var(--dz-bot); border-radius: 16px; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06); }
.dz-typing span { width: 7px; height: 7px; background: #9aa3b2; border-radius: 50%; animation: dz-bounce 1.2s infinite; }
.dz-typing span:nth-child(2) { animation-delay: 0.2s; }
.dz-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dz-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---- input ----------------------------------------------------------- */
.dz-input { display: flex; padding: 12px; border-top: 1px solid #eceef3; gap: 8px; background: #fff; align-items: flex-end; }
.dz-input textarea {
  flex: 1; resize: none; border: 1px solid #d8dce5; border-radius: 12px;
  padding: 11px 13px; font-size: 14px; max-height: 90px; outline: none; line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.dz-input textarea:focus { border-color: var(--dz-primary); box-shadow: 0 0 0 3px var(--dz-glow); }
.dz-input button {
  background: var(--dz-grad); border: none; color: #fff; width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.dz-input button:hover { transform: translateY(-1px); }
.dz-input button:focus-visible { outline: 2px solid var(--dz-primary); outline-offset: 2px; }
.dz-input button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.dz-input button svg { width: 18px; height: 18px; }

/* microphone (speech-to-text) */
.dz-input .dz-mic {
  background: #eef1f8; color: #5b6478; width: 44px; height: 44px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.dz-input .dz-mic:hover { background: #e2e7f3; color: var(--dz-primary); transform: translateY(-1px); }
.dz-input .dz-mic.listening { background: #b22234; color: #fff; animation: dz-mic-pulse 1.3s infinite; }
@keyframes dz-mic-pulse {
  0% { box-shadow: 0 0 0 0 rgba(178, 34, 52, 0.55); }
  70% { box-shadow: 0 0 0 12px rgba(178, 34, 52, 0); }
  100% { box-shadow: 0 0 0 0 rgba(178, 34, 52, 0); }
}

.dz-footer { text-align: center; font-size: 11px; color: #9aa3b2; padding: 7px; background: #fff; }

/* ---- mobile: full-screen panel -------------------------------------- */
@media (max-width: 480px) {
  #pmb-chat-widget { bottom: 18px; right: 18px; }
  #pmb-chat-panel {
    position: fixed; inset: 0; width: 100vw; height: 100vh;
    max-width: 100vw; max-height: 100vh; border-radius: 0; bottom: 0; right: 0;
  }
}

/* respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  #pmb-chat-launcher, .dz-dot, .dz-msg, #pmb-chat-panel { animation: none !important; transition: none !important; }
}
