/* ============================================================
   Poppy - RB Healthcare store dashboard chat widget
   Self-contained styles. Poppins is already loaded site-wide.
   ============================================================ */

:root {
  /* ---- REPLACE WITH BRAND HEX CODES IF THESE EVER CHANGE ----
     These are the current RB Healthcare brand hexes taken from the
     logo pack and the portal build (rb blue / green / amber). */
  --poppy-primary: #0094d0;       /* RB blue */
  --poppy-primary-deep: #00719e;  /* darker blue for hover / header */
  --poppy-primary-ink: #00435f;   /* deepest blue */
  --poppy-accent: #5e9d34;        /* RB green (online dot) */
  /* ---------------------------------------------------------- */

  --poppy-ink: #0f1e2b;
  --poppy-body: #3e4e5a;
  --poppy-mute: #5f6e7a;
  --poppy-hair: #e5eaee;
  --poppy-panel-bg: #ffffff;
  --poppy-user-bubble: #0094d0;
  --poppy-bot-bubble: #f2f6f9;
  --poppy-shadow: 0 18px 48px rgba(15, 30, 43, 0.28);
  --poppy-radius: 16px;
}

/* ---- Floating launcher button ---- */
.poppy-launch {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px 12px 14px;
  border: none;
  border-radius: 999px;
  background: var(--poppy-primary);
  color: #fff;
  font-family: 'Poppins', ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--poppy-shadow);
  transition: transform 0.12s ease, background 0.12s ease;
}
.poppy-launch:hover { background: var(--poppy-primary-deep); transform: translateY(-1px); }
.poppy-launch:active { transform: translateY(0); }
.poppy-launch .poppy-launch-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-weight: 700;
  font-size: 15px;
}
.poppy-launch[hidden] { display: none; }

/* ---- Chat panel ---- */
.poppy-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147483001;
  display: flex;
  flex-direction: column;
  width: 384px;
  height: min(600px, calc(100vh - 44px));
  background: var(--poppy-panel-bg);
  border-radius: var(--poppy-radius);
  box-shadow: var(--poppy-shadow);
  overflow: hidden;
  font-family: 'Poppins', ui-sans-serif, system-ui, sans-serif;
  color: var(--poppy-body);
}
.poppy-panel[hidden] { display: none; }

/* ---- Header ---- */
.poppy-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--poppy-primary) 0%, var(--poppy-primary-deep) 100%);
  color: #fff;
}
.poppy-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
}
.poppy-title { flex: 1; line-height: 1.25; }
.poppy-title .poppy-name { font-weight: 700; font-size: 16px; }
.poppy-title .poppy-role {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  opacity: 0.9;
}
.poppy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--poppy-accent);
  box-shadow: 0 0 0 3px rgba(94, 157, 52, 0.28);
}
.poppy-close {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  opacity: 0.9;
}
.poppy-close:hover { background: rgba(255, 255, 255, 0.16); opacity: 1; }

/* ---- Messages ---- */
.poppy-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafcfd;
}
.poppy-msg { max-width: 86%; font-size: 14px; line-height: 1.5; }
.poppy-msg-bot {
  align-self: flex-start;
  background: var(--poppy-bot-bubble);
  color: var(--poppy-ink);
  padding: 10px 13px;
  border-radius: 4px 14px 14px 14px;
}
.poppy-msg-user {
  align-self: flex-end;
  background: var(--poppy-user-bubble);
  color: #fff;
  padding: 10px 13px;
  border-radius: 14px 14px 4px 14px;
}
.poppy-msg-error {
  align-self: flex-start;
  background: #fef2f2;
  color: #b91c1c;
  padding: 10px 13px;
  border-radius: 4px 14px 14px 14px;
  font-size: 13px;
}
.poppy-msg p { margin: 0 0 8px; }
.poppy-msg p:last-child { margin-bottom: 0; }
.poppy-msg strong { font-weight: 700; }
.poppy-msg code {
  background: rgba(15, 30, 43, 0.08);
  padding: 1px 5px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
}
.poppy-msg ul { margin: 4px 0 8px; padding-left: 18px; }
.poppy-msg li { margin: 2px 0; }
.poppy-msg table {
  border-collapse: collapse;
  width: 100%;
  margin: 6px 0;
  font-size: 12.5px;
}
.poppy-msg th, .poppy-msg td {
  border: 1px solid var(--poppy-hair);
  padding: 5px 8px;
  text-align: left;
}
.poppy-msg th { background: #eef4f8; font-weight: 600; }

/* ---- Typing indicator ---- */
.poppy-typing { display: inline-flex; gap: 4px; align-items: center; }
.poppy-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--poppy-mute);
  opacity: 0.5;
  animation: poppy-bounce 1.2s infinite ease-in-out;
}
.poppy-typing span:nth-child(2) { animation-delay: 0.15s; }
.poppy-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes poppy-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 0.9; }
}

/* ---- Composer ---- */
.poppy-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--poppy-hair);
  background: #fff;
}
.poppy-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--poppy-hair);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  max-height: 120px;
  color: var(--poppy-ink);
  outline: none;
}
.poppy-input:focus { border-color: var(--poppy-primary); box-shadow: 0 0 0 3px rgba(0, 148, 208, 0.15); }
.poppy-send {
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: var(--poppy-primary);
  color: #fff;
  width: 42px;
  height: 42px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}
.poppy-send:hover:not(:disabled) { background: var(--poppy-primary-deep); }
.poppy-send:disabled { opacity: 0.45; cursor: default; }
.poppy-send svg { width: 20px; height: 20px; }

.poppy-foot {
  padding: 0 12px 10px;
  font-size: 11px;
  color: var(--poppy-mute);
  text-align: center;
  background: #fff;
}

/* ---- Mobile ---- */
@media (max-width: 640px) {
  .poppy-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;   /* fallback for iOS before 15.4 */
    height: 100dvh;
    border-radius: 0;
  }
  /* 16px stops iOS zooming the page when the input is focused. */
  .poppy-input { font-size: 16px; }
  /* Keep the composer clear of the home bar / gesture area. */
  .poppy-composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .poppy-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .poppy-launch {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
  }
  /* Bigger touch targets. */
  .poppy-send { width: 46px; height: 46px; }
  .poppy-close { font-size: 26px; padding: 6px 10px; }
  .poppy-expand { display: none; } /* full screen already - nothing to expand */
  .poppy-msg { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .poppy-launch, .poppy-send { transition: none; }
  .poppy-typing span { animation: none; }
}

/* ---- Face avatar + copy button ---- */
.poppy-avatar, .poppy-launch-mark { background: #fff; overflow: hidden; }
.poppy-face { font-size: 24px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.poppy-launch-mark .poppy-face { font-size: 19px; }
.poppy-msg-actions { margin-top: 6px; }
.poppy-copy {
  border: 1px solid var(--poppy-hair);
  background: #fff;
  color: var(--poppy-mute);
  font-family: inherit;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 7px;
  cursor: pointer;
}
.poppy-copy:hover { color: var(--poppy-primary); border-color: var(--poppy-primary); }

/* ---- Expand / pop-out + wide-table handling (added) ---- */
.poppy-panel--wide {
  width: min(780px, calc(100vw - 44px));
  height: min(800px, calc(100vh - 44px));
}
.poppy-panel--wide .poppy-msg { max-width: 94%; }
.poppy-expand {
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  opacity: 0.9;
  display: flex;
  align-items: center;
}
.poppy-expand svg { width: 17px; height: 17px; }
.poppy-expand:hover { background: rgba(255, 255, 255, 0.16); opacity: 1; }
.poppy-tablewrap {
  overflow-x: auto;
  max-width: 100%;
  margin: 6px 0;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--poppy-hair);
  border-radius: 8px;
}
.poppy-tablewrap table { width: auto; min-width: 100%; margin: 0; border: 0; }
.poppy-tablewrap th, .poppy-tablewrap td { white-space: nowrap; }
@media (max-width: 640px) {
  .poppy-panel--wide { width: 100vw; height: 100vh; height: 100dvh; }
}

/* ---- Suggestion chips (page-aware quick questions) ---- */
.poppy-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  max-width: 92%;
}
.poppy-chip {
  border: 1.5px solid var(--poppy-primary);
  background: #fff;
  color: var(--poppy-primary);
  font-family: inherit;
  font-weight: 500;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.poppy-chip:hover { background: var(--poppy-primary); color: #fff; }
@media (max-width: 640px) {
  .poppy-chip { font-size: 14px; padding: 10px 16px; } /* comfier thumb targets */
}

/* ---- Clear hyperlinks in answers + action buttons row (added) ---- */
.poppy-msg a {
  color: var(--poppy-primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.poppy-msg a:hover { color: var(--poppy-primary-deep); }
.poppy-msg-actions { display: flex; gap: 6px; flex-wrap: wrap; }
