/* UMVA - transcript page. Visual base: "Receipts, on paper" (paper/ink, Umva
   Blue, timbuktoo gradient, Fraunces/Instrument Sans/IBM Plex Mono).
   Every token here traces to DESIGN.md; deviations are QA-flagged in README. */

:root {
  /* Color (DESIGN.md > Color) */
  --paper: #F7F5EF;        /* background */
  --ink: #102033;          /* text */
  --accent: #4B8FE8;       /* Umva Blue: links, focus, bot name, selected */
  --programme-blue: #1D9FD9; /* reserved: timbuktoo wordmark / co-branding only */
  --muted: #5C6B7A;        /* meta text, timestamps, footers */
  --success: #25903F;
  --error: #B3261E;
  --info: #0468B1;

  /* The timbuktoo gradient - hairline scale ONLY (top rule, input focus ring,
     Sources left edge, favicon). Never on heroes, buttons, backgrounds, text. */
  --timbuktoo-gradient: linear-gradient(
    135deg,
    #0A9E8F 0%,
    #1E9ED9 35%,
    #0D6FA8 60%,
    #1A8A4A 80%,
    #C8D400 100%
  );

  /* Typography (DESIGN.md > Typography) */
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Instrument Sans", "Helvetica Neue", sans-serif;
  --font-mono: "IBM Plex Mono", Menlo, monospace;

  /* Type scale: 12 / 14 / 16 / 20 / 28 / 40 */
  --fs-mono-small: 12px;
  --fs-meta: 14px;
  --fs-body: 16px;
  --fs-section: 20px;
  --fs-title: 28px;
  --fs-wordmark: 40px;
  --lh-body: 1.6;
  --lh-display: 1.2;

  /* Spacing: base 8px, scale 4/8/16/24/32/48/64 (spacious) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 16px;
  --sp-4: 24px;
  --sp-5: 32px;
  --sp-6: 48px;
  --sp-7: 64px;

  /* Layout */
  --max-width: 720px;
  --radius-input: 4px; /* 4px inputs, 0 elsewhere */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-weight: 400;
  min-height: 100dvh; /* R5: real mobile viewport (keyboard + URL-bar aware) */
  /* No dark mode. Paper is the stance. */
}

::selection {
  background: rgba(75, 143, 232, 0.22); /* Umva Blue, selected state */
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 2px timbuktoo gradient top rule (hairline placement #1) */
.gradient-rule {
  height: 2px;
  width: 100%;
  background: var(--timbuktoo-gradient);
}

/* The page is a flex column that fills the viewport: header at the top, the
   transcript takes the remaining space and scrolls, the composer docks at the
   bottom. Input-first on phones (R1/R5). */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-3) 0;
  height: 100dvh; /* bounded so the transcript (not the body) scrolls */
  display: flex;
  flex-direction: column;
}

/* ---- Header lockup ---- */
.lockup {
  margin-bottom: var(--sp-4);
}

/* The Noticer (MARK.md): mark beside the wordmark, one small placement. */
.lockup-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.lockup-head .mark {
  display: block;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-wordmark);
  line-height: var(--lh-display);
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
}

.programme-line {
  font-family: var(--font-body);
  font-size: var(--fs-meta);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em; /* small caps treatment */
  color: var(--muted);
  margin: var(--sp-2) 0 0;
}

.cobrand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-2) 0 0;
  font-size: var(--fs-mono-small);
}

.cobrand-text {
  font-family: var(--font-body);
  color: var(--muted);
}

/* timbuktoo wordmark at small size; programme-blue is its reserved home */
.cobrand-logo {
  height: 18px;
  width: auto;
  display: block;
}

/* ---- Transcript ---- */
/* The scroll region. flex:1 so it fills between header and docked composer.
   padding-bottom keeps the newest turn clear of the sticky composer (R4/R5);
   JS keeps --composer-h in sync with the real composer height. */
.transcript {
  flex: 1 1 auto;
  min-height: 0; /* allow the flex child to shrink so it scrolls, not the body */
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--sp-4); /* small gap above the docked composer */
  scroll-behavior: auto; /* motion rules: no scroll animation */
}

.turn {
  padding: var(--sp-4) 0;
  scroll-margin-bottom: var(--sp-4);
}

/* Intro entry (R1): reads as body text, scrolls away like any turn. No meta row. */
.turn--intro {
  padding-top: 0;
}

.turn--intro .message {
  max-width: 62ch;
}

/* Hairline rule between turns */
.turn + .turn {
  border-top: 1px solid rgba(16, 32, 51, 0.12);
}

.turn-meta {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  font-variant-numeric: tabular-nums;
}

/* Speaker labels are mono both sides (evidence furniture, receipts voice) -
   inherits mono from .turn-meta. R3. */
.sender {
  font-weight: 500;
  font-family: var(--font-mono);
}

/* User label: mono, muted. Bot label: mono, Umva Blue. */
.turn--user .sender {
  color: var(--muted);
}

.turn--bot .sender {
  color: var(--accent);
}

.timestamp {
  color: var(--muted);
}

.message {
  font-size: var(--fs-body);
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message a {
  color: var(--accent);
}

/* Thinking = plain word, not a spinner */
.turn--thinking .message {
  color: var(--muted);
}

/* Error state = plain */
.turn--error .message {
  color: var(--error);
}

/* I5 streaming: a caret rides at the end of the answer while tokens land, then
   disappears when the turn finishes. A filled block in Umva Blue suits the
   mono/paper voice (a documentary cursor, not a chat bubble spinner). */
.turn--streaming .message::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: umva-caret 1s steps(1, end) infinite;
}

@keyframes umva-caret {
  0%,
  50% {
    opacity: 1;
  }
  50.01%,
  100% {
    opacity: 0;
  }
}

/* Respect reduced-motion: keep the caret, drop the blink. */
@media (prefers-reduced-motion: reduce) {
  .turn--streaming .message::after {
    animation: none;
  }
}

/* ---- Retrieval trace (I1): plain-language "Checked ..." line, mono/muted ---- */
.trace {
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  color: var(--muted);
  margin: var(--sp-2) 0 0;
}

/* ---- Copy affordance (I2): quiet mono, no chrome. Always visible on mobile,
   surfaces on hover/focus on desktop (matches per-turn action convention). ---- */
.copy-answer {
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  color: var(--muted);
  background: none;
  border: none;
  padding: var(--sp-1) 0;
  margin-top: var(--sp-2);
  cursor: pointer;
}

.copy-answer:hover,
.copy-answer:focus-visible {
  color: var(--accent);
}

@media (hover: hover) and (pointer: fine) {
  /* Desktop: reveal on turn hover/focus to keep the transcript calm. */
  .turn--bot .copy-answer {
    opacity: 0;
    transition: opacity 150ms ease-out;
  }
  .turn--bot:hover .copy-answer,
  .turn--bot:focus-within .copy-answer {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .copy-answer { transition: none; }
}

/* ---- Sources block: gradient left edge (hairline placement #3) ---- */
.sources {
  margin-top: var(--sp-3);
  padding: var(--sp-2) 0 var(--sp-2) var(--sp-3);
  position: relative;
  animation: sources-fade 150ms ease-out; /* Sources fade in 150ms */
}

.sources::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--timbuktoo-gradient);
}

@keyframes sources-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .sources { animation: none; }
}

.sources-heading {
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 var(--sp-2);
}

.sources-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.source-row {
  padding: 2px 0;
  position: relative; /* anchors the UX1 hover preview */
}

/* UX1: desktop hover-preview card. Plain 1px ink border on paper, no shadow,
   no gradient - the quote in the Sources voice. Positioned above the row and
   kept within the content column. */
.source-preview {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 4px);
  z-index: 5;
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  color: var(--ink);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.source-preview[hidden] {
  display: none;
}

/* Each source row is tappable; date/who/type stay always-visible (R6). */
.source-summary {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  width: 100%;
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  background: none;
  border: none;
  padding: 2px 0;
  text-align: left;
  cursor: pointer;
}

/* Only show the caret / cursor when there is a quote to expand. */
.source-row--inert .source-summary {
  cursor: default;
}

.source-parts {
  flex: 1 1 auto;
}

/* UX4: mono row number, muted, with a small gap before the date. */
.source-num {
  color: var(--muted);
  margin-right: var(--sp-2);
}

.src-sep {
  color: var(--muted);
  padding: 0 var(--sp-1);
}

/* UX3: quiet hover state on interactive rows (hover-capable devices only,
   no movement, tint only). Touch users lose nothing. */
@media (hover: hover) and (pointer: fine) {
  .source-summary:hover,
  .example:hover {
    background: rgba(16, 32, 51, 0.04);
  }
}

.source-caret {
  color: var(--muted);
  flex: 0 0 auto;
}

.source-row--inert .source-caret {
  visibility: hidden;
}

/* The quoted chunk (the receipt) - inline reveal, no popover. */
.source-quote {
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  color: var(--muted);
  line-height: 1.5;
  padding: var(--sp-2) 0 var(--sp-2) var(--sp-3);
  margin: var(--sp-1) 0 var(--sp-2);
  border-left: 1px solid rgba(16, 32, 51, 0.18);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.source-quote[hidden] {
  display: none;
}

/* ---- Composer dock ---- */
/* Docked at the bottom of the page column. Holds the composer, the empty-state
   examples, and the footer. The transcript reserves space for it (R4/R5). */
.composer-dock {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  background: var(--paper);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Jump to latest pill (R4): shown only when the user has scrolled up. */
.jump-latest {
  display: block;
  margin: 0 auto var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  color: var(--accent);
  background: var(--paper);
  border: 1px solid rgba(16, 32, 51, 0.18);
  border-radius: var(--radius-input);
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
}

.jump-latest[hidden] {
  display: none;
}

.composer {
  display: flex;
  gap: var(--sp-2);
  padding-top: var(--sp-4);
  border-top: 1px solid rgba(16, 32, 51, 0.12);
}

.composer-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  color: var(--ink);
  background: #fff;
  border: 1px solid rgba(16, 32, 51, 0.25);
  border-radius: var(--radius-input);
  padding: var(--sp-2) var(--sp-3);
  line-height: 1.4;
}

.composer-input::placeholder {
  color: var(--muted);
}

/* Focus ring in the gradient (hairline placement #2).
   A gradient can't be a border-color, so paint it as a 2px inset ring. */
.composer-input:focus {
  outline: none;
  border-color: transparent;
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 2px transparent;
  background:
    linear-gradient(#fff, #fff) padding-box,
    var(--timbuktoo-gradient) border-box;
  border: 2px solid transparent;
  padding: calc(var(--sp-2) - 1px) calc(var(--sp-3) - 1px);
}

/* Send action in Umva Blue. R7: quiet (muted outline) while the input is empty,
   active blue once there is text. Cheap state signal, WhatsApp muscle memory. */
.composer-send {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-input);
  padding: var(--sp-2) var(--sp-4);
  cursor: pointer;
  min-height: 44px; /* touch target */
  transition: background 150ms ease-out, color 150ms ease-out,
    border-color 150ms ease-out;
}

.composer-send:hover {
  background: #3f7fd1;
}

.composer.is-empty .composer-send {
  color: var(--muted);
  background: transparent;
  border-color: rgba(16, 32, 51, 0.25);
}

.composer-send:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.composer-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  .composer-send { transition: none; }
}

/* ---- Empty-state example asks (R2): mono, muted, no card chrome. ---- */
.examples {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-1);
  margin-top: var(--sp-3);
}

.examples[hidden] {
  display: none;
}

.example {
  font-family: var(--font-mono);
  font-size: var(--fs-mono-small);
  color: var(--muted);
  background: none;
  border: none;
  padding: var(--sp-1) 0;
  text-align: left;
  cursor: pointer;
}

.example::before {
  content: "\2192  "; /* → rendered via escape so the source stays ASCII */
  color: var(--accent);
}

.example:hover {
  color: var(--ink);
}

/* ---- Footer ---- */
.site-footer {
  margin-top: var(--sp-4);
  padding-bottom: var(--sp-4);
  font-size: var(--fs-mono-small);
  color: var(--muted);
  font-family: var(--font-body);
}

/* ---- Mobile-first is the base; widen the breathing room on larger screens ---- */
@media (min-width: 600px) {
  .page {
    padding: var(--sp-6) var(--sp-4) 0;
  }
}
