/* ABSL Investor Education Chatbot -- design tokens + UI styles
   Matches the Figma comps: home-learning-assistant (landing) and
   answer-experience (chat). Light theme only, by design. */

:root {
  color-scheme: light;

  --bg-page: #faf9f6;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f3f1ed;
  --bg-badge-gold: #fbf6e9;
  --bg-badge-green: #e8f5e9;

  --border: #e9e6e0;

  --accent: #b71c1c;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, var(--bg-surface));
  --gold: #d4a843;
  --green: #2e7d32;
  --on-accent: #ffffff;

  --text-primary: #1e1c1a;
  --text-secondary: #6e6d6a;

  --radius-pill: 999px;
  --radius-xl: 24px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;

  --content-width: 1200px;

  --shadow-card: 0 4px 8px rgba(30, 28, 26, 0.02);
  --shadow-float: 0 12px 24px rgba(30, 28, 26, 0.05);
  --shadow-bar: 0 -8px 20px rgba(30, 28, 26, 0.05);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

/* Alpine hasn't evaluated x-show yet in the brief window before it
   initializes (its script is deferred) -- x-cloak + this rule hides
   elements until then, so hero/conversation-header/chat-input-area
   never flash in the wrong combination on first paint. Alpine removes
   the x-cloak attribute automatically once it takes over. */
[x-cloak] {
  display: none !important;
}

html,
body {
  background: var(--bg-page);
  color: var(--text-primary);
}

body {
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  margin: 0;
  padding: 0 0 6rem;
  min-height: 100dvh;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.container {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ============================================================
   Header
   ============================================================ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.app-header-inner {
  max-width: calc(var(--content-width) + 7.5rem);
  margin: 0 auto;
  height: 5rem;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand img {
  display: block;
  height: 2.25rem;
  width: auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  font-size: 0.875rem;
  white-space: nowrap;
}

.nav-link {
  color: var(--text-secondary);
  font-weight: 500;
  cursor: default;
}

.nav-link.active {
  color: var(--accent);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

/* Clickable: picks the language the bot replies in (default "Auto" mirrors
   whatever language the learner types in; the other three force that language). */
.lang-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
}

.lang-toggle svg {
  flex: none;
  color: var(--text-secondary);
  margin-right: 0.125rem;
}

.lang-pill {
  padding: 0.375rem 0.75rem;
  border: 0;
  background: none;
  border-radius: var(--radius-pill);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 200ms var(--ease-out), color 200ms var(--ease-out);
}

.lang-pill.active {
  background: var(--accent);
  color: var(--on-accent);
}

@media (max-width: 960px) {
  .app-header-inner {
    height: auto;
    flex-wrap: wrap;
    padding: 1rem 1.5rem;
    gap: 0.75rem;
  }
  .nav-links {
    display: none;
  }
}

/* ============================================================
   Page layout / show-hide state machine

   Whether the hero landing content or the conversation view (header +
   fixed input bar) is showing is driven entirely by Alpine's `started`
   flag on <body> (flipped true the instant a /chat request is fired,
   via htmx:before-request -- not when the response arrives, so the
   transition happens immediately on submit rather than after the
   answer finishes generating). See x-show="!started" / x-show="started"
   in chat.html; [x-cloak] above prevents a flash before Alpine
   initializes. No CSS-only mechanism (`:has()`, sibling combinators)
   is used here -- x-show is the single source of truth for visibility.
   ============================================================ */

/* ============================================================
   Hero landing section
   ============================================================ */

#hero-section {
  max-width: calc(var(--content-width) + 3rem);
  margin: 0 auto;
  padding: 4rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 3rem;
  animation: fade-in 320ms var(--ease-out) both;
}

.hero-row {
  display: flex;
  align-items: center;
  gap: 4rem;
}

.hero-text {
  flex: 1 0 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.25rem;
}

.eyebrow-badge {
  display: inline-flex;
  padding: 0.375rem 0.75rem;
  background: var(--bg-badge-gold);
  border: 1px solid var(--gold);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  animation: fade-slide-up 420ms var(--ease-out) both;
}

.hero-title {
  margin: 0;
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.15;
  color: var(--text-primary);
  animation: fade-slide-up 420ms var(--ease-out) both;
  animation-delay: 60ms;
}

.hero-title .accent {
  color: var(--accent);
}

.hero-subtext {
  margin: 0;
  max-width: 62ch;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.6;
  color: var(--text-secondary);
  animation: fade-slide-up 420ms var(--ease-out) both;
  animation-delay: 120ms;
}

/* ---- AI Core stat card ---- */

.stat-card {
  flex: none;
  width: 30rem;
  max-width: 100%;
  height: 15rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-float);
  animation: fade-slide-up 420ms var(--ease-out) both;
  animation-delay: 160ms;
}

.stat-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card-head-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 2s ease-in-out infinite;
}

.stat-card-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
}

.secure-badge {
  padding: 0.25rem 0.5rem;
  background: var(--bg-badge-green);
  border-radius: var(--radius-xs);
  color: var(--green);
  font-size: 0.625rem;
  font-weight: 700;
}

.graph-simulation {
  position: relative;
  flex: 1 0 0;
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

.graph-bar {
  width: 1.25rem;
  border-radius: 4px;
  background: var(--bg-surface-alt);
  transform-origin: bottom;
  animation: grow-bar 560ms var(--ease-out) both;
}

.graph-bar:nth-child(1) { height: 3.75rem; animation-delay: 260ms; }
.graph-bar:nth-child(2) { height: 5.625rem; animation-delay: 340ms; }
.graph-bar:nth-child(3) { height: 7.5rem; background: var(--gold); animation-delay: 420ms; }
.graph-bar:nth-child(4) { height: 9.375rem; background: var(--accent); animation-delay: 500ms; }

.sourcing-bubble {
  position: absolute;
  left: 9.375rem;
  top: 0.625rem;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-float);
  white-space: nowrap;
  animation: fade-slide-up 420ms var(--ease-out) both;
  animation-delay: 620ms;
}

.sourcing-bubble .label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gold);
}

.sourcing-bubble .value {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---- Hero search form ---- */

.hero-search-form {
  display: flex;
  padding: 1rem;
  background: var(--bg-surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-float);
  animation: fade-slide-up 420ms var(--ease-out) both;
  animation-delay: 200ms;
}

.hero-search-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.hero-search-row svg.search-icon {
  flex: none;
  color: var(--text-secondary);
}

.hero-search-row input[type="text"] {
  flex: 1 0 0;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--text-primary);
}

.hero-search-row input[type="text"]::placeholder {
  color: var(--text-secondary);
}

.mic-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}

.mic-btn.mic-circle {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
}

.mic-btn.mic-recording {
  color: var(--red, #d9534f);
  animation: mic-pulse 1s ease-in-out infinite;
}

.mic-btn.mic-error {
  color: var(--red, #d9534f);
}

/* Two icons live in each mic button: the mic glyph (idle/error) and a
   stop-square glyph, swapped via the .mic-recording class -- color/pulse
   alone on the same mic icon didn't read clearly enough as "tap again to
   stop", so recording now shows an unambiguous stop icon instead. */
.mic-icon-stop {
  display: none;
}

.mic-btn.mic-recording .mic-icon-default {
  display: none;
}

.mic-btn.mic-recording .mic-icon-stop {
  display: block;
}

@keyframes mic-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ask-ai-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 120ms var(--ease-out), transform 120ms var(--ease-out);
}

.ask-ai-btn:hover {
  filter: brightness(1.06);
}

.ask-ai-btn:active {
  transform: scale(0.97);
}

.ask-ai-btn.small {
  padding: 0 1rem;
  height: 2.5rem;
  font-size: 0.875rem;
}

/* ---- Popular queries ---- */

.section-label {
  margin: 0 0 1.25rem;
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.suggestion-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms var(--ease-out), transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
  animation: fade-slide-up 380ms var(--ease-out) both;
}

.suggestion-card:nth-child(1) { animation-delay: 260ms; }
.suggestion-card:nth-child(2) { animation-delay: 320ms; }
.suggestion-card:nth-child(3) { animation-delay: 380ms; }
.suggestion-card:nth-child(4) { animation-delay: 440ms; }
.suggestion-card:nth-child(5) { animation-delay: 500ms; }
.suggestion-card:nth-child(6) { animation-delay: 560ms; }

.suggestion-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-float);
}

.suggestion-card:active {
  transform: translateY(0);
}

.suggestion-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.suggestion-card svg {
  flex: none;
  color: var(--accent);
  transition: transform 160ms var(--ease-out);
}

.suggestion-card:hover svg {
  transform: translateX(3px);
}

/* ---- Trust / feature strip ---- */

.trust-section {
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.trust-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.trust-card {
  padding: 1.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fade-slide-up 380ms var(--ease-out) both;
}

.trust-card:nth-child(1) { animation-delay: 640ms; }
.trust-card:nth-child(2) { animation-delay: 700ms; }
.trust-card:nth-child(3) { animation-delay: 760ms; }

.trust-card-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.trust-icon {
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-badge-gold);
  border-radius: 50%;
  color: var(--gold);
}

.trust-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-primary);
}

.trust-card-desc {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-secondary);
}

@media (max-width: 960px) {
  .hero-row {
    flex-direction: column;
    align-items: stretch;
    gap: 2rem;
  }
  .stat-card {
    width: 100%;
  }
  .hero-title {
    font-size: 2.25rem;
  }
  .suggestions-grid,
  .trust-row {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Conversation header (back-to-start affordance)
   ============================================================ */

#conversation-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0;
}

.back-btn {
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-alt);
  border: none;
  border-radius: 50%;
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 120ms var(--ease-out);
}

.back-btn:hover {
  background: var(--border);
}

.conversation-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   Chat log & messages
   ============================================================ */

#chat-log {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-slide-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes grow-bar {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 35%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 0%, transparent); }
}

.message.user {
  align-self: flex-end;
  max-width: 70%;
  padding: 1rem 1.5rem;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  font-size: 1rem;
  font-weight: 600;
  animation: message-in 220ms var(--ease-out) both;
}

.message.user p {
  margin: 0;
  white-space: pre-wrap;
}

.ai-response-card {
  width: 100%;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-xl) 0;
  box-shadow: var(--shadow-float);
  animation: message-in 260ms var(--ease-out) both;
  animation-delay: 80ms;
}

.ai-response-card.no-citation-answer {
  background: transparent;
  border-style: dashed;
  box-shadow: none;
}

.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Groups the Listen button and (when present) the certified badge together
   as a single flex child, so .ai-header's justify-content: space-between
   only ever splits two things (identity vs. this group) -- with three
   separate top-level children, space-between used to land the Listen
   button squarely in the middle of the row instead of beside the badge. */
.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ai-identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ai-avatar {
  flex: none;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-radius: 50%;
  color: var(--on-accent);
}

.ai-name {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 800;
  color: var(--text-primary);
}

.ai-caption {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--gold);
}

.listen-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  cursor: pointer;
}

.listen-btn.listen-playing {
  background: var(--accent);
  color: var(--on-accent);
}

.certified-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: var(--bg-badge-green);
  border-radius: var(--radius-xs);
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- Level badge (kept for backward compat inside a card, unused when
   the header level-toggle is present, but harmless if included) ---- */

.level-badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* ---- Answer body ---- */

.message-body {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.6;
  color: var(--text-primary);
}

.message-body p {
  margin: 0 0 0.85em;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body ul,
.message-body ol {
  margin: 0.4em 0 0.85em;
  padding-left: 1.3em;
}

.message-body li {
  margin-bottom: 0.3em;
}

.message-body li:last-child {
  margin-bottom: 0;
}

.message-body strong {
  font-weight: 700;
}

.message-body a {
  color: var(--accent);
}

/* ---- Insight (key point) cards ---- */

.insight-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.insight-card {
  padding: 1.25rem;
  background: var(--bg-surface-alt);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  animation: fade-slide-up 320ms var(--ease-out) both;
}

.insight-card:nth-child(1) { animation-delay: 120ms; }
.insight-card:nth-child(2) { animation-delay: 200ms; }
.insight-card:nth-child(3) { animation-delay: 280ms; }

.insight-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.insight-num {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  border-radius: 50%;
  color: var(--on-accent);
  font-size: 0.75rem;
  font-weight: 800;
}

.insight-title {
  font-size: 0.875rem;
  font-weight: 800;
  color: var(--text-primary);
}

.insight-desc {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-secondary);
}

/* ---- Citation / sources ---- */

.sources-citation {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.verified-label {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 700;
}

.evidence-cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
}

.citation-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 0;
}

.citation-icon {
  flex: none;
  width: 2.3125rem;
  height: 2.3125rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
}

.citation-icon.video {
  color: var(--accent);
}

/* ---- Video citation: compact row, click-to-expand clip inline in the chat ----
   Collapsed state matches the article card's footprint exactly (same icon-slot
   size, same row layout) -- the thumbnail lives *inside* the icon slot instead of
   a big always-visible media block. The player only enters the DOM (and only
   starts loading/autoplaying) once clicked, via Alpine's <template x-if>. */

.citation-card.citation-video {
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  gap: 0;
}

.citation-video-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.citation-video-thumb-icon {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xs);
  padding: 0;
}

.citation-video-thumb-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.citation-video-play-badge {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1rem;
  height: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 85%, transparent);
  color: #fff;
}

.citation-video-player {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-top: 1px solid var(--border);
  overflow: hidden;
  background: #000;
}

.citation-video-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.citation-body {
  flex: 1 0 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.citation-title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 800;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.citation-card a.citation-title {
  display: block;
}

.citation-card a.citation-title:hover,
.citation-card a.citation-title:focus-visible {
  text-decoration: underline;
}

.citation-meta {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-secondary);
}

.confidence-badge {
  flex: none;
  margin-left: auto;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- No-citation state ---- */

.no-citation {
  padding: 0.625rem 0.875rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-style: italic;
}

/* ---- Handover card ---- */

.handover-card {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem 1.125rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text-primary);
  font-size: 0.875rem;
  animation: handover-pulse 2.2s ease-in-out infinite;
}

.handover-card svg {
  flex: none;
  color: var(--accent);
}

@keyframes handover-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 30%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 0%, transparent); }
}

/* ---- Calculator card ---- */

.calculator-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1.125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: inherit;
  text-decoration: none;
  transition: border-color 200ms var(--ease-out), transform 200ms var(--ease-out);
}

.calculator-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.calculator-card-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-xs);
  background: var(--accent-soft);
  color: var(--accent);
}

.calculator-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.calculator-card-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.calculator-card-blurb {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.calculator-card-arrow {
  flex: none;
  color: var(--accent);
}

/* ---- Quick reply chips ---- */

.quick-replies {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.quick-reply-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

@keyframes chip-in {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-pill);
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 120ms var(--ease-out), color 120ms var(--ease-out), transform 120ms var(--ease-out);
  animation: chip-in 220ms var(--ease-out) both;
}

.chip:hover,
.chip:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.chip:active {
  transform: scale(0.97);
}

.chip:nth-child(1) { animation-delay: 0ms; }
.chip:nth-child(2) { animation-delay: 60ms; }
.chip:nth-child(3) { animation-delay: 120ms; }
.chip:nth-child(4) { animation-delay: 180ms; }
.chip:nth-child(5) { animation-delay: 240ms; }
.chip:nth-child(6) { animation-delay: 300ms; }

/* ============================================================
   Typing indicator
   ============================================================ */

.typing-indicator {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  width: fit-content;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing-bounce 1s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.htmx-indicator {
  opacity: 0;
  transition: opacity 120ms var(--ease-out);
}
.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator {
  opacity: 1;
}

/* ============================================================
   Fixed bottom chat input bar (visible once conversation starts)
   ============================================================ */

.chat-input-area {
  display: block;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  padding: 1rem 1.5rem 1.5rem;
  background: var(--bg-page);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-bar);
}

.chat-input-bar {
  max-width: var(--content-width);
  margin: 0 auto;
  height: 3.5rem;
  padding: 0 0.75rem 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.chat-input-bar input[type="text"] {
  flex: 1 0 0;
  min-width: 0;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  padding: 0 0.5rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

.chat-input-bar input[type="text"]::placeholder {
  color: var(--text-secondary);
}

/* ============================================================
   Live voice page

   A single-purpose call screen, not a scrolling page -- the whole
   composition is one centered column so the "who am I talking to /
   what's happening right now" story reads at a glance. data-state on
   #live-shell (idle / connecting / listening / speaking / mic-error /
   connection-error)
   is the single source of truth driving which visuals are active,
   set by live.js -- mirrors this app's existing convention (Alpine's
   `started` flag) of one state flag driving multiple CSS hooks rather
   than toggling classes ad hoc all over the DOM.
   ============================================================ */

.live-shell {
  min-height: calc(100dvh - 5rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 3rem 1.5rem 4rem;
  text-align: center;
  background:
    radial-gradient(60% 45% at 50% 12%, color-mix(in srgb, var(--gold) 16%, transparent), transparent 70%),
    radial-gradient(65% 55% at 50% 92%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%);
}

/* ---- Persona identity chip -- the same AI mark used in the text
   chat's message bubbles, so Live reads as the same assistant rather
   than a separate, disconnected feature. ---- */

.live-persona {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1rem 0.625rem 0.625rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-card);
}

.live-persona-copy {
  text-align: left;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  color: var(--accent);
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.live-indicator-dot {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--accent);
  animation: live-dot-blink 1.4s ease-in-out infinite;
}

[data-state="idle"] .live-indicator {
  display: none;
}

/* ---- The orb -- the assistant's visual presence. Rings are silent
   (opacity 0) until a real state gives them a reason to move: gold
   while the assistant is waiting/listening, the brand accent while
   it's actually speaking. The core keeps a slow idle breathing motion
   so the screen never looks frozen/broken while connected. ---- */

.live-orb-wrap {
  position: relative;
  width: 10rem;
  height: 10rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.live-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  opacity: 0;
}

.live-ring-2 {
  animation-delay: 0.4s;
}

.live-ring-3 {
  animation-delay: 0.8s;
}

[data-state="connecting"] .live-ring {
  animation: live-ring-pulse 1.8s var(--ease-out) infinite;
}

[data-state="listening"] .live-ring {
  animation: live-ring-pulse 2.2s var(--ease-out) infinite;
}

[data-state="speaking"] .live-ring {
  border-color: var(--accent);
  animation: live-ring-pulse 1.3s var(--ease-out) infinite;
}

.live-orb-core {
  position: relative;
  z-index: 1;
  width: 5.5rem;
  height: 5.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--gold)));
  color: var(--on-accent);
  box-shadow: 0 16px 32px color-mix(in srgb, var(--accent) 30%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  animation: live-breathe 3.4s ease-in-out infinite;
}

[data-state="mic-error"] .live-orb-core,
[data-state="connection-error"] .live-orb-core {
  background: var(--text-secondary);
  box-shadow: none;
  animation: none;
}

/* ---- Waveform -- driven by real mic/playback amplitude from live.js
   (via the --amp custom property per bar), not a decorative loop. ---- */

.live-waveform {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  height: 2.25rem;
}

.live-waveform span {
  width: 0.25rem;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--border);
  transform: scaleY(var(--amp, 0.12));
  transform-origin: center;
  transition: transform 90ms linear, background-color 200ms var(--ease-out);
}

[data-state="listening"] .live-waveform span {
  background: var(--gold);
}

[data-state="speaking"] .live-waveform span {
  background: var(--accent);
}

.live-status-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-width: 32ch;
}

.live-status {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
}

.live-subtext {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

[data-state="mic-error"] .live-status,
[data-state="mic-error"] .live-subtext,
[data-state="connection-error"] .live-status,
[data-state="connection-error"] .live-subtext {
  color: var(--red, #d9534f);
}

/* ---- Controls -- idle shows one primary call button; once active,
   it's replaced by a compact call bar (duration + hangup), the same
   swap pattern telephony UIs use. ---- */

.live-controls {
  display: flex;
  align-items: center;
  justify-content: center;
}

.live-call-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  padding: 1rem 2rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--green);
  color: var(--on-accent);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 24px color-mix(in srgb, var(--green) 30%, transparent);
  transition: filter 120ms var(--ease-out), transform 120ms var(--ease-out);
}

.live-call-btn:hover {
  filter: brightness(1.06);
}

.live-call-btn:active {
  transform: scale(0.97);
}

.live-active-bar {
  display: none;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0.5rem 0.5rem 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-card);
}

.live-timer {
  font-variant-numeric: tabular-nums;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.live-hangup-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  transform: rotate(135deg);
  transition: filter 120ms var(--ease-out), transform 120ms var(--ease-out);
}

.live-hangup-btn:hover {
  filter: brightness(1.08);
}

.live-hangup-btn:active {
  transform: rotate(135deg) scale(0.92);
}

@keyframes live-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes live-ring-pulse {
  0% { transform: scale(0.75); opacity: 0.45; }
  100% { transform: scale(1.35); opacity: 0; }
}

@keyframes live-dot-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ============================================================
   Reduced motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  #hero-section,
  .eyebrow-badge,
  .hero-title,
  .hero-subtext,
  .stat-card,
  .graph-bar,
  .sourcing-bubble,
  .hero-search-form,
  .suggestion-card,
  .trust-card,
  .message.user,
  .ai-response-card,
  .insight-card,
  .chip,
  .stat-dot,
  .handover-card,
  .typing-indicator span,
  .live-orb-core,
  .live-ring,
  .live-indicator-dot {
    animation: none !important;
  }
  .graph-bar {
    transform: none;
  }
  .live-ring {
    opacity: 0 !important;
  }
}
