/* TitanShield public FAQ assistant widget.
 *
 * Bottom-right floating launcher that opens a chat panel.
 * Dark / light via CSS vars (auto from prefers-color-scheme, and
 * overridable by adding [data-theme="dark"] / [data-theme="light"] on
 * the html element). Mobile (<=640px): full-screen overlay panel.
 *
 * Plain CSS, no preprocessing, no external deps.
 */

#ts-chatbot {
  /* Brand: aligned to the app-wide v7 accent (#00d972). Dark ink text on
     the accent fill for contrast, matching lp_v7.html's --resolved-ink. */
  --tsc-accent: #00d972;
  --tsc-accent-ink: #03170d;
  --tsc-accent-dark: #003528;

  /* Light theme (default) */
  --tsc-panel-bg: #ffffff;
  --tsc-panel-fg: #1d2733;
  --tsc-header-bg: #003528;
  --tsc-header-fg: #ffffff;
  --tsc-bot-bubble: #f1f4f6;
  --tsc-bot-fg: #1d2733;
  --tsc-user-bubble: #00d972;
  --tsc-user-fg: #03170d;
  --tsc-border: #e2e8ec;
  --tsc-muted: #6b7785;
  --tsc-input-bg: #ffffff;
  --tsc-shadow: none;
}

@media (prefers-color-scheme: dark) {
  #ts-chatbot {
    --tsc-panel-bg: #161b22;
    --tsc-panel-fg: #e6edf3;
    --tsc-header-bg: #0c2f24;
    --tsc-header-fg: #ffffff;
    --tsc-bot-bubble: #21262d;
    --tsc-bot-fg: #e6edf3;
    --tsc-user-bubble: #00d972;
    --tsc-user-fg: #03170d;
    --tsc-border: #2d333b;
    --tsc-muted: #9aa7b3;
    --tsc-input-bg: #0d1117;
    --tsc-shadow: none;
  }
}

/* Explicit theme override wins over the media query. */
html[data-theme="dark"] #ts-chatbot {
  --tsc-panel-bg: #161b22;
  --tsc-panel-fg: #e6edf3;
  --tsc-header-bg: #0c2f24;
  --tsc-header-fg: #ffffff;
  --tsc-bot-bubble: #21262d;
  --tsc-bot-fg: #e6edf3;
  --tsc-user-bubble: #00d972;
  --tsc-user-fg: #03170d;
  --tsc-border: #2d333b;
  --tsc-muted: #9aa7b3;
  --tsc-input-bg: #0d1117;
  --tsc-shadow: none;
}
html[data-theme="light"] #ts-chatbot {
  --tsc-panel-bg: #ffffff;
  --tsc-panel-fg: #1d2733;
  --tsc-header-bg: #003528;
  --tsc-header-fg: #ffffff;
  --tsc-bot-bubble: #f1f4f6;
  --tsc-bot-fg: #1d2733;
  --tsc-user-bubble: #00d972;
  --tsc-user-fg: #03170d;
  --tsc-border: #e2e8ec;
  --tsc-muted: #6b7785;
  --tsc-input-bg: #ffffff;
  --tsc-shadow: none;
}

/* ----- launcher ----- */
.ts-chatbot-launcher {
  position: fixed;
  right: 1.25rem;
  /* --ts-bottom-bar-h: height of a visible fixed bottom action bar
     ([data-ts-bottom-bar], measured by chatbot.js), so the launcher sits
     above it instead of on its button. */
  bottom: calc(1.25rem + var(--ts-bottom-bar-h, 0px));
  z-index: 9990;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--tsc-accent);
  color: var(--tsc-accent-ink);
  border: none;
  box-shadow: var(--tsc-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  line-height: 1;
  transition: transform 0.12s ease;
}
.ts-chatbot-launcher:hover { transform: translateY(-2px); }
.ts-chatbot-launcher:focus-visible {
  outline: 3px solid var(--tsc-accent-dark);
  outline-offset: 2px;
}

.ts-chatbot-ic-close { display: none; }
.ts-chatbot-launcher.is-open .ts-chatbot-ic-open { display: none; }
.ts-chatbot-launcher.is-open .ts-chatbot-ic-close { display: inline; }

/* ----- panel ----- */
.ts-chatbot-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  z-index: 9991;
  width: 360px;
  max-width: calc(100vw - 2rem);
  height: 540px;
  max-height: calc(100vh - 7.5rem);
  background: var(--tsc-panel-bg);
  color: var(--tsc-panel-fg);
  border: 1px solid var(--tsc-border);
  border-radius: 2px;
  box-shadow: var(--tsc-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: inherit;
}
.ts-chatbot-panel.is-open { display: flex; }

.ts-chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: var(--tsc-header-bg);
  color: var(--tsc-header-fg);
  flex: 0 0 auto;
}
.ts-chatbot-header-title { font-weight: 600; font-size: 1rem; }
.ts-chatbot-close {
  background: transparent;
  border: none;
  color: var(--tsc-header-fg);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}
.ts-chatbot-close:focus-visible { outline: 2px solid var(--tsc-accent); }

.ts-chatbot-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ----- messages ----- */
.ts-chatbot-msg {
  max-width: 85%;
  padding: 0.55rem 0.75rem;
  border-radius: 2px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-wrap: break-word;
}
.ts-chatbot-msg-text { white-space: pre-wrap; }
.ts-chatbot-msg-assistant {
  align-self: flex-start;
  background: var(--tsc-bot-bubble);
  color: var(--tsc-bot-fg);
  border-bottom-left-radius: 2px;
}
.ts-chatbot-msg-user {
  align-self: flex-end;
  background: var(--tsc-user-bubble);
  color: var(--tsc-user-fg);
  border-bottom-right-radius: 2px;
}
.ts-chatbot-msg-time {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.78rem;
  opacity: 0.65;
}

.ts-chatbot-actions { margin-top: 0.5rem; }
.ts-chatbot-mail-btn {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  background: var(--tsc-accent);
  color: var(--tsc-accent-ink);
  border-radius: 2px;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
}
/* The mail button is an <a>; without an explicit hover color the global
   a:hover (green text) leaks in and paints green-on-green. Pin the ink. */
.ts-chatbot-mail-btn:hover { filter: brightness(1.05); color: var(--tsc-accent-ink); text-decoration: none; }
.ts-chatbot-mail-btn:focus-visible {
  outline: 2px solid var(--tsc-accent-dark);
  outline-offset: 2px;
}

/* ----- fallback quick-suggestion chips ----- */
.ts-chatbot-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}
.ts-chatbot-suggestion-chip {
  display: inline-block;
  padding: 0.35rem 0.7rem;
  background: transparent;
  color: var(--tsc-accent);
  border: 1px solid var(--tsc-accent-dark);
  border-radius: 2px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.ts-chatbot-suggestion-chip:hover {
  background: var(--tsc-accent-dim, rgba(0, 217, 114, 0.08));
}
.ts-chatbot-suggestion-chip:focus-visible {
  outline: 2px solid var(--tsc-accent-dark);
  outline-offset: 2px;
}

/* ----- typing indicator ----- */
.ts-chatbot-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.6rem 0.75rem;
  background: var(--tsc-bot-bubble);
  border-radius: 2px;
  border-bottom-left-radius: 2px;
}
.ts-chatbot-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tsc-muted);
  animation: ts-chatbot-blink 1.2s infinite ease-in-out;
}
.ts-chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.ts-chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ts-chatbot-blink {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* ----- input row ----- */
.ts-chatbot-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem;
  border-top: 1px solid var(--tsc-border);
  flex: 0 0 auto;
  background: var(--tsc-panel-bg);
}
.ts-chatbot-input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--tsc-border);
  border-radius: 2px;
  padding: 0.5rem 0.65rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--tsc-input-bg);
  color: var(--tsc-panel-fg);
  max-height: 100px;
  overflow-y: auto;
}
.ts-chatbot-input:focus-visible {
  outline: 2px solid var(--tsc-accent);
  outline-offset: 0;
  border-color: var(--tsc-accent);
}
.ts-chatbot-send {
  flex: 0 0 auto;
  border: none;
  border-radius: 2px;
  padding: 0 1rem;
  background: var(--tsc-accent);
  color: var(--tsc-accent-ink);
  font-weight: 600;
  cursor: pointer;
}
.ts-chatbot-send:disabled { opacity: 0.55; cursor: default; }
.ts-chatbot-send:focus-visible {
  outline: 2px solid var(--tsc-accent-dark);
  outline-offset: 2px;
}

.ts-chatbot-disclaimer {
  flex: 0 0 auto;
  padding: 0.45rem 0.75rem 0.6rem;
  font-size: 0.78rem;
  color: var(--tsc-muted);
  text-align: center;
  background: var(--tsc-panel-bg);
}

/* ----- mobile: full screen ----- */
@media (max-width: 640px) {
  .ts-chatbot-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .ts-chatbot-launcher {
    right: 1rem;
    bottom: calc(1rem + var(--ts-bottom-bar-h, 0px) + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
    font-size: 22px;
  }
  /* The end of every page clears the launcher, so the last CTA of a page
     (e.g. a store-check result) can always be scrolled out from under it.
     Not while the cookie banner is shown: the banner reserves its own
     height and the launcher is hidden then. */
  body:has(> #ts-chatbot):not(.ts-cc-banner-visible) {
    padding-bottom: calc(4.75rem + var(--ts-bottom-bar-h, 0px));
  }
}

/* 2026-10-08: the launcher (z 9990) sat on top of the cookie banner (z 1100)
   and covered its Accept button at every width. Hidden while the banner is
   shown; it comes back as soon as a choice is made. Never hidden while the
   chat panel is open. */
body.ts-cc-banner-visible .ts-chatbot-launcher:not(.is-open) { display: none; }

/* Respect reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .ts-chatbot-launcher { transition: none; }
  .ts-chatbot-typing span { animation: none; }
}
