/* =============================================================================
   Tutiv AI Chat Widget — styles
   Zero dependencies. All classes are prefixed .tvc- to avoid colliding with
   the host site's CSS. WCAG 2.1 AA: focus rings, 44px targets, AA contrast.
   ============================================================================= */

.tvc-root,
.tvc-root * { box-sizing: border-box; }

.tvc-root {
  /* Tokens mirror tutiv.ca */
  --tvc-ink: #0B0D12;
  --tvc-ink-2: #15181F;
  --tvc-line: rgba(255,255,255,.12);
  --tvc-line-strong: rgba(255,255,255,.22);
  --tvc-accent: #D8FF36;
  --tvc-accent-ink: #0B0D12;
  --tvc-paper: #FFFFFF;
  --tvc-paper-2: #F5F4F0;
  --tvc-text: #15181F;
  --tvc-text-dim: #5B6066;
  --tvc-text-on-dark: #F5F4F0;
  --tvc-text-on-dark-dim: #A4ABB3;
  --tvc-user-bubble: #0B0D12;
  --tvc-ai-bubble: #F0EFEA;
  --tvc-human-bubble: #FBFFE3;
  --tvc-radius: 14px;
  --tvc-radius-lg: 20px;
  --tvc-shadow: 0 18px 50px rgba(11,13,18,.22), 0 2px 8px rgba(11,13,18,.10);
  --tvc-fd: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tvc-fm: "Space Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --tvc-fb: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  font-family: var(--tvc-fb);
  color: var(--tvc-text);
}

/* ---- Launcher pill ---------------------------------------------------------- */
/* Launcher is the pill shell; the open button and the dismiss "x" sit inside it. */
.tvc-launcher {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--tvc-line-strong);
  border-radius: 999px;
  background: var(--tvc-ink);
  box-shadow: var(--tvc-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .4s ease, transform .4s ease;
  pointer-events: none;
}
.tvc-launcher.tvc-show { opacity: 1; transform: translateY(0); pointer-events: auto; }

.tvc-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 48px;
  padding: 0 8px 0 16px;
  border: none;
  background: transparent;
  color: var(--tvc-text-on-dark);
  font-family: var(--tvc-fd);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .01em;
  cursor: pointer;
  transition: background .2s ease;
}
.tvc-pill:hover { background: rgba(255,255,255,.06); }
.tvc-pill .tvc-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tvc-accent); flex: none; }
.tvc-pill:focus-visible { outline: 3px solid var(--tvc-accent); outline-offset: -3px; }

/* Dismiss "x", folded into the pill behind a thin divider (muted, not a badge) */
.tvc-dismiss {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; padding: 0;
  border: none; border-left: 1px solid var(--tvc-line);
  background: transparent; color: var(--tvc-text-on-dark-dim);
  cursor: pointer;
  transition: background .2s ease, color .2s ease;
}
.tvc-dismiss:hover { background: rgba(255,255,255,.06); color: var(--tvc-text-on-dark); }
.tvc-dismiss svg { width: 15px; height: 15px; }
.tvc-dismiss:focus-visible { outline: 3px solid var(--tvc-accent); outline-offset: -3px; }

/* ---- Panel ------------------------------------------------------------------ */
.tvc-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 40px);
  background: var(--tvc-paper);
  border: 1px solid rgba(11,13,18,.12);
  border-radius: var(--tvc-radius-lg);
  box-shadow: var(--tvc-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.tvc-panel.tvc-open { display: flex; animation: tvc-pop .22s ease both; }
/* Launcher hides while the panel is open so it never paints over the window. */
.tvc-root.tvc-paneled .tvc-launcher { display: none; }
@keyframes tvc-pop {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* ---- Header ----------------------------------------------------------------- */
.tvc-head {
  background: var(--tvc-ink);
  color: var(--tvc-text-on-dark);
  padding: 14px 14px 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.tvc-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tvc-logo { width: 26px; height: 26px; flex: none; }
.tvc-title { min-width: 0; }
.tvc-title b {
  display: block;
  font-family: var(--tvc-fd);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.1;
}
.tvc-title span {
  display: block;
  font-family: var(--tvc-fm);
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--tvc-text-on-dark-dim);
  margin-top: 3px;
}
.tvc-head-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.tvc-human-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--tvc-line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--tvc-text-on-dark);
  font-family: var(--tvc-fb);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s ease, border-color .2s ease;
}
.tvc-human-btn:hover { background: rgba(255,255,255,.08); border-color: var(--tvc-accent); }
.tvc-human-btn svg { width: 14px; height: 14px; flex: none; }

.tvc-icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--tvc-text-on-dark);
  border-radius: 8px; cursor: pointer;
}
.tvc-icon-btn:hover { background: rgba(255,255,255,.08); }
.tvc-icon-btn svg { width: 18px; height: 18px; }

.tvc-head-actions .tvc-human-btn:focus-visible,
.tvc-icon-btn:focus-visible,
.tvc-close-mobile:focus-visible {
  outline: 3px solid var(--tvc-accent);
  outline-offset: 2px;
}

/* status strip under header when a human is in the loop */
.tvc-status {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--tvc-accent);
  color: var(--tvc-accent-ink);
  font-family: var(--tvc-fm);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  flex: none;
}
.tvc-status.tvc-show { display: flex; }
.tvc-status .tvc-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tvc-accent-ink); }

/* ---- Message log ------------------------------------------------------------ */
.tvc-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 16px 8px;
  background: var(--tvc-paper);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.tvc-msg { max-width: 85%; }
.tvc-msg-who {
  font-family: var(--tvc-fm);
  font-size: 10px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--tvc-text-dim);
  margin: 0 0 4px 2px;
  display: flex; align-items: center; gap: 6px;
}
.tvc-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--tvc-accent);
  color: var(--tvc-accent-ink);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .05em;
}
.tvc-bubble {
  padding: 11px 14px;
  border-radius: var(--tvc-radius);
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.tvc-bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.tvc-msg.tvc-user { align-self: flex-end; }
.tvc-msg.tvc-user .tvc-bubble {
  background: var(--tvc-user-bubble);
  color: var(--tvc-text-on-dark);
  border-bottom-right-radius: 5px;
}
.tvc-msg.tvc-user .tvc-msg-who { justify-content: flex-end; }
.tvc-msg.tvc-ai .tvc-bubble {
  background: var(--tvc-ai-bubble);
  color: var(--tvc-text);
  border-bottom-left-radius: 5px;
}
.tvc-msg.tvc-human .tvc-bubble {
  background: var(--tvc-human-bubble);
  color: var(--tvc-text);
  border: 1px solid var(--tvc-accent);
  border-bottom-left-radius: 5px;
}

/* message entrance */
.tvc-msg { animation: tvc-msg-in .26s cubic-bezier(.22,.61,.36,1) both; }
.tvc-msg.tvc-noanim { animation: none; }
@keyframes tvc-msg-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }

/* ---- Suggested question chips (opening screen) ----------------------------- */
.tvc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 2px 4px;
  animation: tvc-msg-in .3s cubic-bezier(.22,.61,.36,1) both;
  animation-delay: .08s;
}
.tvc-chip {
  font-family: var(--tvc-fb);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--tvc-ink);
  background: var(--tvc-paper);
  border: 1px solid rgba(11,13,18,.16);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.tvc-chip:hover { background: var(--tvc-paper-2); border-color: var(--tvc-ink); }
.tvc-chip:active { transform: scale(.97); }
.tvc-chip:focus-visible { outline: 3px solid var(--tvc-accent); outline-offset: 2px; }

/* Handoff topic selector (single-select chips) */
.tvc-topics { display: flex; flex-wrap: wrap; gap: 7px; }
.tvc-topics .tvc-chip { padding: 7px 12px; font-size: 12.5px; }
.tvc-chip.tvc-sel { background: var(--tvc-ink); color: var(--tvc-text-on-dark); border-color: var(--tvc-ink); }
.tvc-chip.tvc-sel:hover { background: var(--tvc-ink-2); }

/* typing indicator */
.tvc-typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.tvc-typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--tvc-text-dim);
  animation: tvc-bounce 1.2s infinite ease-in-out;
}
.tvc-typing i:nth-child(2) { animation-delay: .15s; }
.tvc-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes tvc-bounce { 0%,60%,100%{transform:translateY(0);opacity:.5} 30%{transform:translateY(-5px);opacity:1} }

/* ---- Handoff form ----------------------------------------------------------- */
.tvc-handoff {
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
}
/* When open, the form owns the scrollable area so the submit button is always reachable. */
.tvc-handoff.tvc-show { display: flex; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.tvc-handoff h4 {
  margin: 0;
  font-family: var(--tvc-fd);
  font-size: 15px;
  font-weight: 600;
}
.tvc-handoff p { margin: 0; font-size: 13px; color: var(--tvc-text-dim); line-height: 1.5; }
.tvc-field { display: flex; flex-direction: column; gap: 4px; }
.tvc-field label { font-size: 12px; font-weight: 600; color: var(--tvc-text); }
.tvc-field input, .tvc-field textarea {
  font-family: var(--tvc-fb);
  font-size: 16px; /* prevents iOS zoom */
  padding: 10px 12px;
  border: 1px solid rgba(11,13,18,.2);
  border-radius: 10px;
  background: var(--tvc-paper);
  color: var(--tvc-text);
  width: 100%;
}
.tvc-field textarea { resize: vertical; min-height: 60px; }
.tvc-field input:focus, .tvc-field textarea:focus {
  outline: 3px solid var(--tvc-accent);
  outline-offset: 1px;
  border-color: var(--tvc-ink);
}
.tvc-field .tvc-err { font-size: 12px; color: #B42318; display: none; }
.tvc-field.tvc-invalid .tvc-err { display: block; }
.tvc-field.tvc-invalid input { border-color: #B42318; }

/* honeypot — visually gone, still focusable off-screen for bots */
.tvc-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px; height: 1px; overflow: hidden;
}

/* ---- Composer --------------------------------------------------------------- */
.tvc-foot { flex: none; background: var(--tvc-paper); padding-top: 4px; }
.tvc-compose {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin: 12px 14px 2px;
  padding: 5px 5px 5px 15px;
  background: var(--tvc-paper-2);
  border: 1px solid rgba(11,13,18,.14);
  border-radius: 24px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.tvc-compose:focus-within {
  border-color: var(--tvc-ink);
  box-shadow: 0 0 0 3px rgba(216,255,54,.45);
}
.tvc-input {
  flex: 1 1 auto;
  font-family: var(--tvc-fb);
  font-size: 16px; /* prevents iOS zoom */
  line-height: 1.4;
  border: none;
  background: transparent;
  color: var(--tvc-text);
  resize: none;
  max-height: 120px;
  padding: 8px 0;
}
.tvc-input:focus { outline: none; }
.tvc-send {
  flex: none;
  width: 38px; height: 38px;
  border: none; border-radius: 50%;
  background: var(--tvc-accent);
  color: var(--tvc-accent-ink);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: filter .2s ease;
}
.tvc-send:hover { filter: brightness(1.05); }
.tvc-send:disabled { opacity: .4; cursor: default; }
.tvc-send svg { width: 18px; height: 18px; }
.tvc-send:focus-visible, .tvc-primary:focus-visible, .tvc-secondary:focus-visible {
  outline: 3px solid var(--tvc-ink);
  outline-offset: 2px;
}
.tvc-count {
  display: none; /* shown by JS only once the visitor starts typing */
  font-family: var(--tvc-fm);
  font-size: 10px;
  color: var(--tvc-text-dim);
  text-align: right;
  padding: 0 24px 8px;
}
.tvc-count.tvc-warn { color: #B42318; }

.tvc-primary, .tvc-secondary {
  font-family: var(--tvc-fb);
  font-size: 14px; font-weight: 600;
  padding: 11px 16px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.tvc-primary { background: var(--tvc-ink); color: var(--tvc-text-on-dark); }
.tvc-primary:hover { background: var(--tvc-ink-2); }
.tvc-secondary { background: transparent; color: var(--tvc-text); border-color: rgba(11,13,18,.2); }
.tvc-secondary:hover { background: var(--tvc-paper-2); }
.tvc-form-actions { display: flex; gap: 8px; padding: 4px 0 2px; }
.tvc-form-actions .tvc-primary { flex: 1; }
.tvc-consent { margin: 6px 0 2px; font-size: 11.5px; line-height: 1.4; color: var(--tvc-text-dim); }
.tvc-consent a { color: var(--tvc-text-dim); text-decoration: underline; }
.tvc-consent a:hover { color: var(--tvc-ink); }

/* ---- Privacy footer --------------------------------------------------------- */
.tvc-legal {
  flex: none;
  padding: 8px 14px 10px;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--tvc-text-dim);
  text-align: center;
  background: var(--tvc-paper);
  border-top: 1px solid rgba(11,13,18,.06);
}
.tvc-legal a { color: var(--tvc-text-dim); text-decoration: underline; }
.tvc-legal a:hover { color: var(--tvc-ink); }
.tvc-legal .tvc-sep { opacity: .5; margin: 0 5px; }

/* Close / minimize control — visible on desktop and mobile. */
.tvc-close-mobile {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: none; background: transparent;
  color: var(--tvc-text-on-dark);
  border-radius: 8px; cursor: pointer;
}
.tvc-close-mobile svg { width: 18px; height: 18px; }
.tvc-close-mobile:hover { background: rgba(255,255,255,.08); }

/* ---- Reduced motion --------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .tvc-launcher, .tvc-pill, .tvc-log { transition: none; scroll-behavior: auto; }
  .tvc-typing i { animation: none; }
  .tvc-panel.tvc-open, .tvc-msg, .tvc-chips { animation: none; }
}

/* ---- Mobile (< 768px): full-screen overlay --------------------------------- */
@media (max-width: 767px) {
  .tvc-root { right: 14px; bottom: 14px; }
  .tvc-pill { height: 46px; font-size: 14.5px; }
  /* lock the page behind the full-screen overlay so it doesn't scroll away */
  html.tvc-lock, html.tvc-lock body { overflow: hidden; }
  .tvc-panel.tvc-open { animation: tvc-slide .25s ease both; }
  @keyframes tvc-slide { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

  .tvc-panel.tvc-open {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: none;
    border-radius: 0;
  }
  .tvc-panel.tvc-open .tvc-foot,
  .tvc-panel.tvc-open .tvc-legal {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .tvc-panel.tvc-open .tvc-handoff.tvc-show {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  /* clear the status bar / notch at the top of the full-screen overlay */
  .tvc-panel.tvc-open .tvc-head { padding-top: calc(15px + env(safe-area-inset-top)); }
  .tvc-msg { max-width: 88%; }
  .tvc-compose { margin: 14px 12px 2px; }
  .tvc-log { padding: 18px 16px 10px; }
  .tvc-close-mobile {
    display: inline-flex;
    align-items: center; justify-content: center;
    width: 38px; height: 38px;
    border: none; background: transparent;
    color: var(--tvc-text-on-dark);
    border-radius: 8px; cursor: pointer;
  }
  .tvc-close-mobile svg { width: 22px; height: 22px; }
  /* on mobile the header can get tight; let the human button shrink to an icon */
  .tvc-human-btn span { display: none; }
  .tvc-human-btn { padding: 0 10px; }
}
