/* ============================================================================
   ib-chat.css — floating chat bubble (messenger) + notifications popup.
   Framework-agnostic, loaded on every surface alongside ib-nav (static pages via
   patch-nav, Next via app/layout). Dark is the default; [data-theme="light"]
   overrides. Mounted/controlled by public/ib-chat.js.
   ============================================================================ */

:root { --ibc-teal: #0fbcad; }

/* ── Floating action button (bubble) ── */
.ib-chat-fab {
  position: fixed; right: 24px; bottom: 26px; z-index: 320;
  width: 48px; height: 48px; border-radius: 50%; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  /* Frosted teal glass */
  background: rgba(15,188,173,0.18); color: #0fbcad;
  border: 1px solid rgba(15,188,173,0.40);
  -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 8px 26px rgba(0,0,0,0.32), inset 0 1px 0 rgba(255,255,255,0.22);
  transition: transform .18s ease, box-shadow .18s ease;
  -webkit-tap-highlight-color: transparent;
}
.ib-chat-fab.show { display: flex; }
.ib-chat-fab:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(0,0,0,0.5); }
.ib-chat-fab svg { width: 22px; height: 22px; }
.ib-chat-fab-badge {
  position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; background: #ff5757; color: #fff; font: 700 11px/20px 'Inter',sans-serif;
  text-align: center; box-shadow: 0 0 0 2px #0e0e10; display: none;
}
.ib-chat-fab-badge.show { display: block; }

/* ── Backdrop behind the open chat (mobile) + hide the bubble while chatting ── */
.ib-chat-overlay { position: fixed; inset: 0; z-index: 325; display: none; background: rgba(0,0,0,0.45); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
body.ib-chat-open .ib-chat-fab { display: none !important; }
@media (max-width: 767px) { body.ib-chat-open .ib-chat-overlay { display: block; } }

/* ── Chat panel (messenger) ── */
.ib-chat-panel {
  position: fixed; right: 20px; bottom: 88px; z-index: 330;
  width: 380px; max-width: calc(100vw - 32px); height: 560px; max-height: calc(100dvh - 120px);
  display: none; flex-direction: column; overflow: hidden;
  background: rgba(16,17,20,0.98); border: 1px solid rgba(255,255,255,0.12); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.08);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
.ib-chat-panel.open { display: flex; }
@media (max-width: 767px) {
  /* Raised on mobile so the bubble clears the calculators' sticky action bar
     ("See your result" / "Save Dosage"). */
  .ib-chat-fab { right: 16px; bottom: 118px; }
  .ib-chat-panel { bottom: 182px; }
}
@media (max-width: 480px) {
  .ib-chat-panel { right: 8px; left: 8px; bottom: 182px; width: auto; max-width: none; height: calc(100dvh - 202px); }
}
.ib-chat-head {
  display: flex; align-items: center; gap: 10px; padding: 13px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08); flex-shrink: 0;
}
.ib-chat-head-ib { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; background: rgba(15,188,173,0.16); color: var(--ibc-teal); flex-shrink: 0; }
.ib-chat-head-ib svg { width: 19px; height: 19px; }
.ib-chat-head-t { font: 600 14.5px 'Inter',sans-serif; color: #f0f0f2; }
.ib-chat-head-s { font: 400 11.5px 'Inter',sans-serif; color: rgba(240,240,242,0.5); margin-top: 1px; }
.ib-chat-x { background: none; border: none; color: rgba(240,240,242,0.5); cursor: pointer; padding: 6px; line-height: 0; border-radius: 6px; }
.ib-chat-x:hover { color: #f0f0f2; background: rgba(255,255,255,0.06); }
.ib-chat-x svg { width: 18px; height: 18px; }

.ib-chat-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.ib-chat-empty { margin: auto; text-align: center; color: rgba(240,240,242,0.4); font: 400 13.5px 'Inter',sans-serif; padding: 24px; }
.ib-chat-signin { margin: auto; text-align: center; padding: 24px; }
.ib-chat-signin a { color: var(--ibc-teal); font: 600 14px 'Inter',sans-serif; text-decoration: none; }

/* messenger rows: avatar + bubble; mine (user) right, them (InjectBuddy) left */
.ib-cmsg { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.ib-cmsg.mine { flex-direction: row-reverse; }
.ib-cmsg-av { width: 26px; height: 26px; border-radius: 50%; overflow: hidden; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.ib-cmsg-av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ib-cmsg-av.ib-ib { background: rgba(15,188,173,0.16); color: var(--ibc-teal); }
.ib-cmsg-av.ib-ib svg { width: 15px; height: 15px; }
.ib-cmsg-av.ib-initials { background: rgba(15,188,173,0.16); color: var(--ibc-teal); font: 600 10px 'Inter',sans-serif; }
.ib-cbubble {
  max-width: 75%; padding: 8px 12px; border-radius: 14px; font: 400 14px/1.45 'Inter',sans-serif;
  white-space: pre-wrap; word-break: break-word;
}
.ib-cmsg.them .ib-cbubble { background: rgba(255,255,255,0.07); color: #f0f0f2; border-bottom-left-radius: 4px; }
.ib-cmsg.mine .ib-cbubble { background: linear-gradient(140deg, rgba(15,188,173,0.95), rgba(15,188,173,0.78)); color: #04211d; border-bottom-right-radius: 4px; }

.ib-chat-foot { flex-shrink: 0; display: flex; gap: 8px; align-items: flex-end; padding: 10px; border-top: 1px solid rgba(255,255,255,0.08); }
.ib-chat-input {
  flex: 1; resize: none; max-height: 110px; min-height: 40px; box-sizing: border-box;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.12); border-radius: 10px;
  padding: 10px 12px; color: #f0f0f2; outline: none;
  /* 16px: iOS auto-zooms any focused input under 16px, which jerks the panel. */
  font: 400 16px/1.4 'Inter',sans-serif;
}
.ib-chat-input::placeholder { color: rgba(240,240,242,0.4); }
.ib-chat-send {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 10px; border: none; cursor: pointer;
  background: linear-gradient(145deg, #12d0bf, #0c9e91); color: #04211d; display: flex; align-items: center; justify-content: center;
}
.ib-chat-send:disabled { opacity: 0.5; cursor: default; }
.ib-chat-send svg { width: 19px; height: 19px; }

/* ── Notifications popup (dropdown style) ── */
.ib-notify-panel {
  position: fixed; top: 56px; right: 16px; z-index: 420; width: 340px; max-width: calc(100vw - 24px);
  max-height: min(72vh, 560px); display: none; flex-direction: column; overflow: hidden;
  background: rgba(20,22,26,0.99); border: 1px solid rgba(255,255,255,0.16); border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.18);
  -webkit-backdrop-filter: blur(20px) saturate(150%); backdrop-filter: blur(20px) saturate(150%);
}
.ib-notify-panel.open { display: flex; }
.ib-notify-top { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.ib-notify-top-t { font: 700 14px 'Inter',sans-serif; color: #f0f0f2; }
.ib-notify-x { background: none; border: none; color: rgba(240,240,242,0.5); cursor: pointer; padding: 4px; line-height: 0; }
.ib-notify-x:hover { color: #f0f0f2; }
.ib-notify-x svg { width: 16px; height: 16px; }
.ib-notify-list { overflow-y: auto; padding: 6px; }
.ib-notify-empty { text-align: center; color: rgba(240,240,242,0.4); font: 400 13px 'Inter',sans-serif; padding: 28px 16px; }
.ib-notify-item { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 6px; text-decoration: none; background: none; border: none; cursor: pointer; }
.ib-notify-item:hover { background: rgba(255,255,255,0.05); }
.ib-notify-item.unread { background: rgba(15,188,173,0.07); }
.ib-notify-row { display: flex; align-items: center; gap: 7px; }
.ib-notify-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ibc-teal); flex-shrink: 0; }
.ib-notify-kind { font: 700 9.5px 'Inter',sans-serif; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ibc-teal); }
.ib-notify-when { margin-left: auto; font: 400 11px 'Inter',sans-serif; color: rgba(240,240,242,0.4); }
.ib-notify-title { font: 600 13.5px 'Inter',sans-serif; color: #f0f0f2; margin-top: 3px; }
.ib-notify-body { font: 400 12.5px/1.4 'Inter',sans-serif; color: rgba(240,240,242,0.6); margin-top: 2px; white-space: pre-wrap; word-break: break-word; }

/* ── Badges on the nav (count chip in the menu item + avatar dot) ── */
.ib-notify-badge {
  display: none; margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: #ff5757; color: #fff; font: 700 10.5px/18px 'Inter',sans-serif; text-align: center;
}
.ib-notify-badge.show { display: inline-block; }
/* the Notifications menu item is a flex row so the badge sits at the right edge */
.ib-dropdown-item[data-ib-notifications], .ib-rail-link[data-ib-notifications] { display: flex; align-items: center; gap: 8px; }

/* Suggestions is being phased out — hide its legacy floating bubble everywhere
   (the chat bubble replaces it). */
#ib-suggest-bubble { display: none !important; }
.ib-nav-pfp, .ib-rail-pfp { position: relative; }
.ib-avatar-btn.ib-has-notif::after, .ib-nav-pfp.ib-has-notif::after, .ib-rail-pfp.ib-has-notif::after {
  content: ''; position: absolute; top: -1px; right: -1px; width: 10px; height: 10px; border-radius: 50%;
  background: #ff5757; border: 2px solid #0e0e10;
}

@media (prefers-reduced-motion: reduce) { .ib-chat-fab { transition: none; } }

/* ── Light theme ── */
[data-theme="light"] .ib-chat-panel { background: rgba(248,248,252,0.99); border-color: rgba(0,0,0,0.10); }
[data-theme="light"] .ib-chat-head { border-bottom-color: rgba(0,0,0,0.08); }
[data-theme="light"] .ib-chat-head-t { color: #1a1a1e; }
[data-theme="light"] .ib-chat-head-s { color: rgba(20,20,28,0.5); }
[data-theme="light"] .ib-chat-x { color: rgba(20,20,28,0.5); }
[data-theme="light"] .ib-chat-x:hover { color: #1a1a1e; background: rgba(0,0,0,0.05); }
[data-theme="light"] .ib-cmsg.them .ib-cbubble { background: rgba(0,0,0,0.05); color: #1a1a1e; }
[data-theme="light"] .ib-chat-input { background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.12); color: #1a1a1e; }
[data-theme="light"] .ib-chat-input::placeholder { color: rgba(20,20,28,0.4); }
[data-theme="light"] .ib-chat-foot { border-top-color: rgba(0,0,0,0.08); }
[data-theme="light"] .ib-chat-fab { background: rgba(15,188,173,0.16); border-color: rgba(15,188,173,0.42); color: #0c8479; box-shadow: 0 8px 26px rgba(31,38,55,0.18), inset 0 1px 0 rgba(255,255,255,0.6); }
[data-theme="light"] .ib-chat-fab-badge { box-shadow: 0 0 0 2px #f4f4f6; }
[data-theme="light"] .ib-notify-panel { background: rgba(255,255,255,0.99); border-color: rgba(0,0,0,0.10); box-shadow: 0 16px 36px rgba(31,38,55,0.18), inset 0 1px 0 rgba(255,255,255,0.9); }
[data-theme="light"] .ib-notify-top { border-bottom-color: rgba(0,0,0,0.08); }
[data-theme="light"] .ib-notify-top-t { color: #1a1a1e; }
[data-theme="light"] .ib-notify-item:hover { background: rgba(0,0,0,0.04); }
[data-theme="light"] .ib-notify-title { color: #1a1a1e; }
[data-theme="light"] .ib-notify-body { color: rgba(20,20,28,0.6); }
[data-theme="light"] .ib-avatar-btn.ib-has-notif::after, [data-theme="light"] .ib-nav-pfp.ib-has-notif::after, [data-theme="light"] .ib-rail-pfp.ib-has-notif::after { border-color: #f4f4f6; }
