/* =====================================================================
   Floating live chat widget – Modafinil Sydney (scoped with .tbc-)
   Mobile: the panel is sized from window.visualViewport (set by chat.js
   as --tbc-h / --tbc-top) so the input always sits above the keyboard.
   ===================================================================== */
.tbc {
  --tbc-brand: #2D4F2B;        /* Modafinil Sydney green */
  --tbc-brand-dark: #1f3a1e;
  --tbc-brand-2: #3d6a3a;
  --tbc-accent: #FFB823;       /* amber */
  --tbc-cream: #FFF1CA;
  --tbc-ink: #1b2618;
  --tbc-text: #26321f;
  --tbc-muted: #6b7a69;
  --tbc-line: #ECE6D3;
  --tbc-bg: #F7F4EA;
  --tbc-radius: 20px;
  /* --tbc-lift is set by chat.js when another fixed bar (e.g. the cart's sticky checkout bar) sits at the bottom */
  position: fixed; right: 24px; bottom: calc(24px + var(--tbc-lift, 0px)); z-index: 99990;
  font-family: 'Lexend', system-ui, -apple-system, sans-serif; font-size: 14px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
.tbc *, .tbc *::before, .tbc *::after { box-sizing: border-box; }
.tbc [hidden] { display: none !important; }
/* The site's style.css gives every <form> a 10px bottom margin, which left a strip under the
   input bar (between the input and the keyboard on phones). The chat sets its own spacing. */
.tbc form, .tbc .tbc-form, .tbc .tbc-foot { margin: 0; }
.tbc button { font-family: inherit; }
.tbc-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Launcher ---------- */
.tbc-launcher {
  position: relative; width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  background: linear-gradient(135deg, var(--tbc-brand-2), var(--tbc-brand-dark)); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 30px rgba(45,79,43,.35), 0 3px 8px rgba(0,0,0,.15);
  transition: transform .2s ease, box-shadow .2s ease;
}
.tbc-launcher:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 16px 36px rgba(45,79,43,.42); }
.tbc-launcher:focus-visible { outline: 3px solid rgba(45,79,43,.35); outline-offset: 4px; }
.tbc-launcher::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--tbc-accent);
  animation: tbcPulse 2.4s ease-out infinite; pointer-events: none;
}
.tbc.is-open .tbc-launcher::after, .tbc.has-opened .tbc-launcher::after { animation: none; opacity: 0; }
@keyframes tbcPulse { 0% { transform: scale(1); opacity: .65; } 100% { transform: scale(1.6); opacity: 0; } }

.tbc-launcher-icon { position: absolute; display: flex; transition: transform .25s ease, opacity .2s ease; }
.tbc-icon-close { opacity: 0; transform: rotate(-90deg) scale(.6); }
.tbc.is-open .tbc-icon-open { opacity: 0; transform: rotate(90deg) scale(.6); }
.tbc.is-open .tbc-icon-close { opacity: 1; transform: none; }

.tbc-badge {
  position: absolute; top: -3px; right: -3px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--tbc-accent); color: #1b2618; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* Small "Need help?" bubble next to the launcher (desktop, first visit) */
.tbc-hint {
  position: absolute; right: 74px; bottom: 12px; white-space: nowrap;
  background: #fff; color: var(--tbc-ink); font-size: 13px; font-weight: 600;
  padding: 9px 14px; border-radius: 14px 14px 4px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.14);
  animation: tbcHint .35s ease .8s both; cursor: pointer;
}
.tbc.has-opened .tbc-hint { display: none; }
@keyframes tbcHint { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }

/* ---------- Panel ---------- */
.tbc-panel {
  position: absolute; right: 0; bottom: 80px;
  width: 380px; height: min(620px, calc(100vh - 130px)); height: min(620px, calc(100dvh - 130px));
  display: flex; flex-direction: column; background: #fff; border-radius: var(--tbc-radius); overflow: hidden;
  box-shadow: 0 28px 70px rgba(0,0,0,.22), 0 6px 16px rgba(0,0,0,.08);
  transform-origin: bottom right; animation: tbcIn .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes tbcIn { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }

/* Header */
.tbc-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 16px 14px 16px 18px; color: #fff;
  background: linear-gradient(120deg, #0D2B1A 0%, var(--tbc-brand-dark) 45%, var(--tbc-brand) 100%);
  border-bottom: 3px solid var(--tbc-accent);
}
.tbc-avatar {
  position: relative; flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%;
  background: var(--tbc-cream); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px rgba(255,184,35,.55), 0 2px 8px rgba(0,0,0,.25);
}
.tbc-avatar img { width: 64%; height: 64%; object-fit: contain; display: block; }
.tbc-online { position: absolute; right: 0; bottom: 1px; width: 12px; height: 12px; border-radius: 50%; background: #22c55e; border: 2px solid var(--tbc-brand-dark); }
.tbc-online.is-off { background: #a3a3a3; }
.tbc-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.tbc-head-text strong { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.3; }
.tbc-head-text span { font-size: 12px; color: rgba(255,241,202,.9); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tbc-close {
  flex: 0 0 38px; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  background: rgba(255,255,255,.14); color: #fff; display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.tbc-close:hover { background: rgba(255,255,255,.28); }

/* Messages (min-height:0 is required so the flex child can scroll) */
.tbc-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 18px 14px 10px; background: var(--tbc-bg);
  display: flex; flex-direction: column; gap: 4px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: #d4d4d4 transparent;
}
.tbc-body::-webkit-scrollbar { width: 6px; }
.tbc-body::-webkit-scrollbar-thumb { background: #d4d4d4; border-radius: 6px; }
.tbc-day { align-self: center; font-size: 11px; font-weight: 600; color: var(--tbc-muted); background: #EFEAD9; padding: 3px 10px; border-radius: 999px; margin: 2px 0 10px; }

.tbc-msg { display: flex; flex-direction: column; max-width: 80%; margin-top: 6px; animation: tbcMsg .2s ease; }
.tbc-msg.is-grouped { margin-top: 0; }
@keyframes tbcMsg { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.tbc-bubble {
  padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.5; color: var(--tbc-text);
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.tbc-msg.from-bot, .tbc-msg.from-agent { align-self: flex-start; }
.tbc-msg.from-bot .tbc-bubble, .tbc-msg.from-agent .tbc-bubble {
  background: #fff; border-top-left-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.tbc-msg.from-agent .tbc-bubble { background: #fff; box-shadow: inset 3px 0 0 var(--tbc-accent), 0 1px 2px rgba(0,0,0,.06); }
.tbc-msg.from-visitor { align-self: flex-end; align-items: flex-end; }
.tbc-msg.from-visitor .tbc-bubble {
  background: linear-gradient(135deg, var(--tbc-brand-2), var(--tbc-brand)); color: #fff; border-top-right-radius: 6px;
  box-shadow: 0 2px 6px rgba(45,79,43,.18);
}
.tbc-meta { font-size: 10.5px; color: var(--tbc-muted); margin: 3px 8px 2px; }
.tbc-msg.is-grouped-next .tbc-meta { display: none; }
.tbc-msg.is-error .tbc-bubble { background: #fff4f4; color: #a40000; box-shadow: inset 0 0 0 1px #ffd2d2; }

.tbc-typing {
  align-self: flex-start; display: flex; gap: 4px; padding: 13px 15px; margin-top: 6px;
  background: #fff; border-radius: 18px; border-top-left-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.tbc-typing span { width: 7px; height: 7px; border-radius: 50%; background: #b9b9b9; animation: tbcDot 1.2s infinite ease-in-out; }
.tbc-typing span:nth-child(2) { animation-delay: .15s; }
.tbc-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes tbcDot { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-4px); opacity: 1; } }

/* Links inside bot / staff messages */
.tbc-bubble a.tbc-link { color: var(--tbc-brand); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }

/* Quick replies */
.tbc-quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; justify-content: flex-end; }
.tbc-chip {
  border: 1px solid rgba(45,79,43,.35); background: #fff; color: var(--tbc-brand); cursor: pointer;
  font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 18px; line-height: 1.3; text-align: left; max-width: 100%;
  transition: background .15s, color .15s, border-color .15s;
}
.tbc-chip:hover, .tbc-chip:focus-visible { background: var(--tbc-brand); border-color: var(--tbc-brand); color: var(--tbc-cream); outline: none; }

.tbc-new {
  align-self: center; margin: 12px 0 6px; padding: 9px 18px; border-radius: 999px; border: 1px solid var(--tbc-brand);
  background: #fff; color: var(--tbc-brand); font-weight: 600; font-size: 13px; cursor: pointer;
}
.tbc-new:hover { background: var(--tbc-brand); color: #fff; }

/* Scroll-to-latest button */
.tbc-jump {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 2;
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  background: #fff; color: var(--tbc-ink); box-shadow: 0 4px 14px rgba(0,0,0,.18);
  display: flex; align-items: center; justify-content: center;
}

/* Input bar */
.tbc-form {
  position: relative;
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--tbc-line); background: #fff;
}
.tbc-input {
  flex: 1; min-width: 0; min-height: 46px; max-height: 120px; padding: 12px 16px; resize: none; overflow-y: hidden;
  border-radius: 24px; border: 1px solid #E2DCC7; background: #FBF8EF;
  font: inherit; font-size: 15px; line-height: 1.4; color: var(--tbc-ink); outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.tbc-input::placeholder { color: #9a9a9a; }
.tbc-input:focus { border-color: var(--tbc-brand); background: #fff; box-shadow: 0 0 0 3px rgba(45,79,43,.1); }
.tbc-input:disabled { opacity: .6; }
.tbc-input.has-link, .tbc-input.has-link:focus { border-color: #b42318; box-shadow: 0 0 0 3px rgba(180,35,24,.12); }
.tbc-send {
  flex: 0 0 46px; width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  background: var(--tbc-brand); color: var(--tbc-accent); display: flex; align-items: center; justify-content: center;
  transition: background .2s, transform .15s, opacity .2s;
}
.tbc-send:hover { background: var(--tbc-brand-dark); }
.tbc-send:active { transform: scale(.92); }
.tbc-send:disabled { background: #E2DCC7; color: #fff; cursor: default; }
.tbc-count {
  position: absolute; right: 66px; top: -24px; font-size: 11px; font-weight: 600; color: var(--tbc-muted);
  background: #fff; padding: 2px 8px; border-radius: 999px; box-shadow: 0 1px 4px rgba(0,0,0,.12); pointer-events: none;
}
.tbc-count.is-max { color: var(--tbc-brand); }
.tbc-foot { flex: 0 0 auto; margin: 0; padding: 0 12px 10px; font-size: 11px; color: var(--tbc-muted); text-align: center; background: #fff; }

/* ---------- Tablet / small laptop ---------- */
@media (max-width: 991.98px) {
  .tbc { right: 18px; bottom: calc(18px + var(--mbn-h, 0px) + var(--tbc-lift, 0px)); }   /* above the mobile bottom nav */
}

/* ---------- Phone: full-screen sheet that follows the visible viewport ---------- */
@media (max-width: 575.98px) {
  .tbc { right: 14px; bottom: calc(14px + var(--mbn-h, env(safe-area-inset-bottom)) + var(--tbc-lift, 0px)); }
  .tbc-launcher { width: 56px; height: 56px; }
  .tbc-hint { display: none; }
  .tbc.is-open .tbc-launcher { display: none; }

  .tbc-panel {
    position: fixed; left: 0; right: 0; bottom: auto;
    top: var(--tbc-top, 0px);
    width: 100%;
    height: 100vh; height: 100dvh; height: var(--tbc-h, 100dvh);
    border-radius: 0; box-shadow: none;
    overscroll-behavior: none;
    animation: tbcUp .25s cubic-bezier(.2,.8,.2,1);
  }
  /* Safety net for browsers that report the keyboard/viewport size a few pixels off:
     the panel paints its header colour above itself and its input-bar colour below itself,
     so a gap can never show the page behind the chat. */
  .tbc-panel { overflow: visible; }
  .tbc-panel::before, .tbc-panel::after {
    content: ""; position: absolute; left: 0; right: 0; height: 100vh; pointer-events: none;
  }
  .tbc-panel::before { bottom: calc(100% - 1px); background: #0D2B1A; }   /* 1px overlap: no seam */
  .tbc-panel::after { top: calc(100% - 1px); background: #fff; }
  /* While the chat is open on a phone it covers the whole screen, so the page behind it is hidden
     and the canvas painted white. Some browsers (e.g. Brave, which hides its bottom toolbar when the
     keyboard opens) clip fixed elements a few dozen px above the keyboard and let the page show
     through there; with the page hidden that strip is plain white like the input bar. */
  html.tbc-lock, html.tbc-lock body { background: #fff !important; }
  html.tbc-lock body > *:not(#msChat):not(#tbcDebug) { visibility: hidden !important; }
  /* Keyboard up: the input sits directly on the keyboard (no footer, no home-bar padding). */
  .tbc.kb-open .tbc-form { padding-bottom: 8px; }
  .tbc.kb-open .tbc-foot { display: none; }
  .tbc-head { padding: max(12px, env(safe-area-inset-top)) 12px 12px 14px; }
  .tbc-avatar { flex-basis: 40px; width: 40px; height: 40px; }
  .tbc-body { padding: 14px 12px 8px; }
  .tbc-msg { max-width: 85%; }
  .tbc-bubble { font-size: 15px; }
  .tbc-form { padding: 8px 10px; }
  .tbc.kb-closed .tbc-form { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .tbc-input { font-size: 16px; min-height: 44px; padding: 11px 15px; }  /* 16px stops iOS auto-zoom */
  .tbc-send { flex-basis: 44px; width: 44px; height: 44px; }
  .tbc-foot { display: none; }
  .tbc.kb-closed .tbc-foot { display: block; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .tbc-jump { bottom: 76px; }
}
@keyframes tbcUp { from { transform: translateY(100%); } to { transform: none; } }

/* Page behind the chat must not scroll on phones */
html.tbc-lock, html.tbc-lock body { overflow: hidden !important; overscroll-behavior: none; }
html.tbc-lock body { position: fixed; left: 0; right: 0; width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .tbc-launcher::after, .tbc-panel, .tbc-msg, .tbc-typing span, .tbc-hint { animation: none !important; }
  .tbc-launcher, .tbc-launcher-icon { transition: none; }
}
@media print { .tbc { display: none !important; } }
