/*
  tibbot.css — shared panel UI for case study pages.
  index.html carries its own inline tibbot styles; this file
  is only linked from case-studies/*.html.
*/

/* ── CSS variables the tibbot panel needs ───────────────────────────────── */
:root {
  --color-sidebar:            #2C2C28;
  --color-text-sidebar:       oklch(95% 0.007 100);
  --color-text-sidebar-muted: oklch(95% 0.007 100 / 55%);
  --color-accent-sidebar:     #8FB894;
  --ease-out-quint:           cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Case-study sidebar expansion ────────────────────────────────────────── */
body.tibbot-open .cs-sidebar { width: 420px; transition: width 260ms cubic-bezier(0.25, 1, 0.5, 1); }
body.tibbot-open .cs-main    { margin-left: 420px; transition: margin-left 260ms cubic-bezier(0.25, 1, 0.5, 1); }
body.tibbot-open .cs-sidebar-head,
body.tibbot-open .cs-sidebar-case,
body.tibbot-open .cs-sidebar-nav,
body.tibbot-open .cs-sidebar-foot {
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

/* ── Chat panel (mounts inside aside.cs-sidebar) ─────────────────────────── */
.tibbot-chat {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-sidebar);
  color: var(--color-text-sidebar);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 2;
}
body.tibbot-open .tibbot-chat {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 100ms ease;
}

.tibbot-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px 24px;
  border-bottom: 1px solid color-mix(in srgb, var(--color-text-sidebar) 12%, transparent);
  flex-shrink: 0;
}
.tibbot-chat-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent-sidebar);
}
.tibbot-chat-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.tibbot-chat-action {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-sidebar-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease;
}
.tibbot-chat-action:hover,
.tibbot-chat-action:focus-visible {
  color: var(--color-text-sidebar);
  background: oklch(100% 0 0 / 6%);
}
.tibbot-chat-action svg { transition: transform 280ms var(--ease-out-quint); }
.tibbot-chat-restart:hover svg,
.tibbot-chat-restart:focus-visible svg { transform: rotate(-90deg); }
.tibbot-chat.is-welcome .tibbot-chat-restart { display: none; }

.tibbot-chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 22px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--color-text-sidebar) 18%, transparent) transparent;
}
.tibbot-chat-log::-webkit-scrollbar { width: 6px; }
.tibbot-chat-log::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--color-text-sidebar) 18%, transparent);
  border-radius: 3px;
}

.tibbot-msg { display: flex; }
.tibbot-msg-user { justify-content: flex-end; }
.tibbot-msg-bot  { justify-content: flex-start; }
.tibbot-bubble {
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 88%;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.tibbot-msg-user .tibbot-bubble {
  background: var(--color-accent-sidebar);
  color: var(--color-sidebar);
  border-bottom-right-radius: 4px;
}
.tibbot-msg-bot .tibbot-bubble {
  background: oklch(100% 0 0 / 6%);
  color: var(--color-text-sidebar);
  border-bottom-left-radius: 4px;
}
.tibbot-msg.is-streaming .tibbot-bubble::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 14px;
  margin-left: 3px;
  vertical-align: -2px;
  background: currentColor;
  opacity: 0.6;
  animation: tibbot-cursor-blink 1s steps(2) infinite;
}
@keyframes tibbot-cursor-blink { 50% { opacity: 0; } }

.tibbot-followups {
  display: flex;
  flex-direction: column;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid color-mix(in srgb, var(--color-text-sidebar) 12%, transparent);
}
.tibbot-followup {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  margin: 0 -10px;
  border-radius: 8px;
  border: none;
  text-align: left;
  background: transparent;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.42;
  color: var(--color-text-sidebar);
  cursor: pointer;
  transition: background-color 160ms var(--ease-out-quart, ease);
}
.tibbot-followup-arrow {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--color-accent-sidebar);
  transition: transform 220ms var(--ease-out-quint, ease);
}
.tibbot-followup:hover,
.tibbot-followup:focus-visible { background: oklch(100% 0 0 / 5%); }
.tibbot-followup:hover .tibbot-followup-arrow,
.tibbot-followup:focus-visible .tibbot-followup-arrow { transform: translate(2px, -1px); }

.tibbot-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px 18px;
  border-top: 1px solid color-mix(in srgb, var(--color-text-sidebar) 12%, transparent);
  flex-shrink: 0;
}
.tibbot-chat-input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid color-mix(in srgb, var(--color-text-sidebar) 22%, transparent);
  color: var(--color-text-sidebar);
  font: inherit;
  /* 16px minimum — iOS Safari auto-zooms when a focused input is below 16px. */
  font-size: 16px;
  padding: 8px 4px;
  outline: none;
  transition: border-color 150ms ease;
}
.tibbot-chat-input::placeholder { color: var(--color-text-sidebar-muted); }
.tibbot-chat-input:focus { border-bottom-color: var(--color-accent-sidebar); }
.tibbot-chat-send {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-sidebar);
  color: var(--color-sidebar);
  cursor: pointer;
  transition: filter 150ms ease, transform 150ms ease;
}
.tibbot-chat-send:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* ── Welcome screen ──────────────────────────────────────────────────────── */
.tibbot-welcome {
  display: flex;
  flex-direction: column;
  padding: 6px 2px 4px;
}
.tibbot-welcome-title {
  margin: 6px 0 15px;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 400;
  line-height: 1.28;
  color: var(--color-text-sidebar);
}
.tibbot-welcome-title .wave {
  display: inline-block;
  margin-left: 3px;
  transform-origin: 70% 80%;
}
body.tibbot-open .tibbot-welcome-title .wave {
  animation: tibbot-wave 1.6s var(--ease-out-quart) 720ms 2;
}
@keyframes tibbot-wave {
  0%, 60%, 100% { transform: rotate(0deg); }
  15%, 45%      { transform: rotate(15deg); }
  30%           { transform: rotate(-8deg); }
}
.tibbot-welcome-text {
  margin: 0 0 11px;
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--color-text-sidebar-muted);
}
.tibbot-welcome-rule {
  height: 1px;
  margin: 9px 0 16px;
  background: color-mix(in srgb, var(--color-text-sidebar) 13%, transparent);
}
.tibbot-welcome-label {
  margin: 0 0 9px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text-sidebar-muted);
}
.tibbot-starters {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tibbot-starter {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 11px;
  margin: 0 -11px;
  border-radius: 8px;
  border: none;
  text-align: left;
  background: transparent;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.42;
  color: var(--color-text-sidebar);
  cursor: pointer;
  transition: background-color 160ms var(--ease-out-quart);
}
.tibbot-starter-arrow {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--color-accent-sidebar);
  transition: transform 220ms var(--ease-out-quint);
}
.tibbot-starter:hover,
.tibbot-starter:focus-visible { background: oklch(100% 0 0 / 5%); }
.tibbot-starter:hover .tibbot-starter-arrow,
.tibbot-starter:focus-visible .tibbot-starter-arrow { transform: translate(2px, -1px); }

/* ── Open choreography ───────────────────────────────────────────────────── */
@keyframes tibbot-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
body.tibbot-open .tibbot-chat-head,
body.tibbot-open .tibbot-chat-form,
body.tibbot-open .tibbot-welcome > *:not(.tibbot-starters),
body.tibbot-open .tibbot-starter {
  animation: tibbot-rise 400ms var(--ease-out-quint) backwards;
}
body.tibbot-open .tibbot-chat-head                 { animation-delay: 120ms; }
body.tibbot-open .tibbot-chat-form                 { animation-delay: 150ms; }
body.tibbot-open .tibbot-welcome > *:nth-child(1)  { animation-delay: 210ms; }
body.tibbot-open .tibbot-welcome > *:nth-child(2)  { animation-delay: 250ms; }
body.tibbot-open .tibbot-welcome > *:nth-child(3)  { animation-delay: 286ms; }
body.tibbot-open .tibbot-welcome > *:nth-child(4)  { animation-delay: 318ms; }
body.tibbot-open .tibbot-welcome > *:nth-child(5)  { animation-delay: 346ms; }
body.tibbot-open .tibbot-starter:nth-child(1)      { animation-delay: 386ms; }
body.tibbot-open .tibbot-starter:nth-child(2)      { animation-delay: 426ms; }
body.tibbot-open .tibbot-starter:nth-child(3)      { animation-delay: 466ms; }

@media (prefers-reduced-motion: reduce) {
  .cs-sidebar, .cs-main, .tibbot-chat,
  body.tibbot-open .cs-sidebar-head,
  body.tibbot-open .cs-sidebar-case,
  body.tibbot-open .cs-sidebar-nav,
  body.tibbot-open .cs-sidebar-foot { transition: none; }
  body.tibbot-open .tibbot-chat-head,
  body.tibbot-open .tibbot-chat-form,
  body.tibbot-open .tibbot-welcome > *,
  body.tibbot-open .tibbot-starter,
  body.tibbot-open .tibbot-welcome-title .wave { animation: none; }
  .tibbot-starter, .tibbot-starter-arrow { transition: none; }
}

/* ── Mobile FAB ──────────────────────────────────────────────────────────
   Floating sparkle button at bottom-right that triggers The TibBot. Hidden
   on desktop; hidden when the chat or nav drawer is already open. */
.tibbot-fab {
  display: none;
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-accent-sidebar, #8FB894);
  color: var(--color-sidebar, #2C2C28);
  border: 0;
  padding: 0;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.22), 0 2px 6px rgba(0,0,0,0.14);
  cursor: pointer;
  z-index: 90;
  transition: transform 220ms cubic-bezier(0.22, 0.61, 0.36, 1), opacity 180ms ease;
}
.tibbot-fab:hover,
.tibbot-fab:focus-visible {
  transform: translateY(-2px) scale(1.03);
  outline: none;
  box-shadow: 0 12px 30px rgba(0,0,0,0.24), 0 3px 8px rgba(0,0,0,0.16);
}
.tibbot-fab svg { display: block; }

@media (max-width: 720px) {
  .tibbot-fab { display: inline-flex; }
  body.tibbot-open .tibbot-fab,
  body.nav-open   .tibbot-fab {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.7);
  }

  /* Hide the in-header TibBot launchers on case studies — FAB replaces them. */
  .cs-sidebar-foot { display: none !important; }

  /* Hide the top nav while the chat is open so the drawer can take the whole
     viewport. We can't `display: none` the sidebar itself — the chat panel is
     mounted inside it. So collapse the sidebar shell and hide only its
     non-chat children. Also bump the sidebar's z-index above the backdrop
     (99): the sidebar's existing z:50 was forming a stacking context that
     trapped the chat below the backdrop pseudo, breaking interaction. */
  body.tibbot-open .sidebar,
  body.tibbot-open .cs-sidebar {
    min-height: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    z-index: 101 !important;
  }
  body.tibbot-open .sidebar > :not(.tibbot-chat),
  body.tibbot-open .cs-sidebar > :not(.tibbot-chat) {
    display: none !important;
  }
  body.tibbot-open { overflow: hidden; overscroll-behavior: contain; }

  /* Backdrop behind the bottom drawer so the page is dimmed. */
  body.tibbot-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 99;
    animation: tibbot-backdrop-fade 220ms ease both;
    pointer-events: auto;
  }
  @keyframes tibbot-backdrop-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  /* Chat fills the full mobile viewport. Top + bottom insets pin it edge-
     to-edge. We rely on the `interactive-widget=resizes-content` viewport
     meta to make iOS shrink the layout viewport when the keyboard opens
     so position:fixed elements still cover the visible area. */
  body.tibbot-open .tibbot-chat {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: auto;
    max-height: none;
    z-index: 100;
    border-radius: 0;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.28);
    animation: tibbot-slide-up 340ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
    display: flex;
    flex-direction: column;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
  }
  /* Hide the drag-handle pseudo when the drawer fills the whole viewport. */
  body.tibbot-open .tibbot-chat::before { display: none; }
  body.tibbot-open .tibbot-chat-log { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  @keyframes tibbot-slide-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  /* A small drag handle at the top of the drawer for affordance. */
  body.tibbot-open .tibbot-chat::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: color-mix(in srgb, var(--color-text-sidebar) 35%, transparent);
    pointer-events: none;
  }
  body.tibbot-open .tibbot-chat-head { padding-top: 22px; }

  /* The host sidebars stay in their normal closed state — the chat panel is its own overlay. */
  body.tibbot-open .sidebar,
  body.tibbot-open .cs-sidebar { width: 100% !important; }
  body.tibbot-open .cs-main    { margin-left: 0 !important; visibility: visible !important; }
  body.tibbot-open .main       { margin-left: 0 !important; visibility: visible !important; }
}

@media (prefers-reduced-motion: reduce) {
  body.tibbot-open::before,
  body.tibbot-open .tibbot-chat { animation: none; }
  .tibbot-fab { transition: none; }
}

/* ── Curiosity prompts ───────────────────────────────────────────────────── */
.cs-curiosity {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  padding: 7px 14px 7px 10px;
  background: color-mix(in srgb, #8FB894 20%, transparent);
  border: none;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.04em;
  color: #2C2C28;
  cursor: pointer;
  transition: background-color 200ms var(--ease-out-quart),
              box-shadow 220ms var(--ease-out-quart),
              transform 200ms var(--ease-out-quart);
}
.cs-curiosity svg {
  display: block;
  flex-shrink: 0;
  color: #8FB894;
  transition: color 160ms ease;
}
.cs-curiosity:hover {
  background: color-mix(in srgb, #8FB894 42%, transparent);
  box-shadow: 0 0 0 5px color-mix(in srgb, #8FB894 12%, transparent);
  transform: translateY(-1px);
}
.cs-curiosity:hover svg { color: #4E6B54; }
