/*
 * Nudge design language. Warm, calm, anti-corporate — Inter, an indigo→violet
 * accent, generous whitespace, soft rounded surfaces. Shared across every
 * screen; the Conversation bubbles and PWA polish build on these tokens
 * (OTH-78 / OTH-80).
 */

:root {
  --indigo: #6366f1;
  --violet: #8b5cf6;
  --accent-grad: linear-gradient(135deg, var(--indigo) 0%, var(--violet) 100%);

  --ink: #1e1b2e;
  --ink-soft: #4b4860;
  --muted: #8b8a9c;
  --line: #ece9f5;
  --surface: #ffffff;
  --bg: #faf9fe;
  --bg-tint: #f3f1fb;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow: 0 10px 40px -12px rgba(99, 102, 241, 0.25);
  --shadow-sm: 0 2px 12px -4px rgba(30, 27, 46, 0.12);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

/* Cross-document fade between screens (supporting browsers) — no hard cuts. */
@view-transition { navigation: auto; }

main.page { animation: page-in 0.24s ease both; }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  main.page, .bubble { animation: none; }
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Header / nav ---- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  max-width: 880px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-pill);
  background: var(--accent-grad);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

.site-nav { display: flex; align-items: center; gap: 8px; }

.nav-link {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}
.nav-link:hover { background: var(--bg-tint); color: var(--ink); }

.nav-button {
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}
form.button_to { display: inline; margin: 0; }

/* ---- Page + cards ---- */
.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 32px;
  max-width: 420px;
  margin: 6vh auto 0;
}

.card h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.card .lede { margin: 0 0 24px; color: var(--ink-soft); }

/* ---- Forms ---- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.14);
  background: var(--surface);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 13px 18px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent-grad);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }

.form-foot {
  margin-top: 20px;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}
.form-foot a { color: var(--indigo); font-weight: 600; text-decoration: none; }
.form-foot a:hover { text-decoration: underline; }

/* ---- Flash ---- */
.flash-stack {
  max-width: 420px;
  margin: 12px auto 0;
  padding: 0 24px;
}
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  margin-bottom: 8px;
}
.flash-notice { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-alert  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ---- Hero / landing / waiting ---- */
.hero { text-align: center; max-width: 560px; margin: 10vh auto 0; }
.hero h1 {
  font-size: 2.6rem;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin: 0 0 16px;
}
.hero .gradient-text {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p { font-size: 1.15rem; color: var(--ink-soft); margin: 0 0 28px; }
.hero .btn { width: auto; padding: 14px 28px; }

.waiting { text-align: center; max-width: 460px; margin: 12vh auto 0; }
.waiting .pulse {
  width: 64px; height: 64px;
  margin: 0 auto 24px;
  border-radius: var(--radius-pill);
  background: var(--accent-grad);
  box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
  animation: pulse 2.2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.35); }
  70%  { box-shadow: 0 0 0 22px rgba(99, 102, 241, 0); }
  100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}
.waiting h1 { font-size: 1.7rem; letter-spacing: -0.02em; margin: 0 0 10px; }
.waiting p { color: var(--ink-soft); font-size: 1.05rem; }

/* ---- Conversation ---- */
.app .page { max-width: none; padding: 0; }

.conversation {
  display: flex;
  flex-direction: column;
  /* Fill the viewport below the header (≈68px) so the composer pins to the
     bottom and only the messages scroll. */
  height: calc(100dvh - 68px);
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 4px 8px;
  scroll-behavior: smooth;
}

/* Typing indicator — a skeleton for the reply before the first token lands,
   so there is never a blank bubble or spinner-then-dump. */
.typing { display: inline-flex; gap: 4px; padding: 2px 0; }
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.bubble {
  max-width: 78%;
  padding: 11px 15px;
  border-radius: 20px;
  font-size: 1rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: bubble-in 0.18s ease-out;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bubble-user {
  align-self: flex-end;
  color: #fff;
  background: var(--accent-grad);
  border-bottom-right-radius: 6px;
}
.bubble-nudge {
  align-self: flex-start;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

/* Blinking caret while the reply streams in. */
.bubble-nudge.is-streaming::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 2px;
  background: var(--violet);
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
}
.empty-state[hidden] { display: none; }
.empty-avatar {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: var(--radius-pill);
  background: var(--accent-grad);
  box-shadow: var(--shadow);
}
.empty-state p { font-size: 1.05rem; }

.conv-error {
  align-self: center;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.92rem;
}
.conv-retry {
  margin-left: 6px;
  border: none;
  background: #991b1b;
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 8px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  position: sticky;
  bottom: 0;
}
.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 11px 16px;
  max-height: 140px;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}
.composer button {
  flex: none;
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--radius-pill);
  color: #fff;
  background: var(--accent-grad);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s, opacity 0.15s;
}
.composer button:hover { filter: brightness(1.05); }
.composer button:active { transform: scale(0.94); }
.composer button:disabled { opacity: 0.5; cursor: default; }

/* ---- History ---- */
.history, .history-transcript { max-width: 640px; margin: 0 auto; }

.history-head h1, .transcript-title {
  font-size: 1.7rem;
  letter-spacing: -0.02em;
  margin: 8px 0 4px;
}
.history-head p { color: var(--ink-soft); margin: 0 0 20px; }

.session-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.session-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--ink);
  transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s;
}
.session-card:hover {
  transform: translateY(-1px);
  border-color: #d9d3f3;
  box-shadow: var(--shadow);
}
.session-title { font-weight: 600; }
.session-date { color: var(--muted); font-size: 0.88rem; }

.transcript-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.back-link { color: var(--indigo); font-weight: 600; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.readonly-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--bg-tint);
  border-radius: var(--radius-pill);
  padding: 4px 11px;
}

.messages-static {
  flex: none;
  overflow: visible;
  height: auto;
  padding: 8px 0 4px;
}

.transcript-foot { margin: 24px 0 40px; text-align: center; }
.btn-inline { display: inline-flex; width: auto; padding: 11px 22px; }
.text-link { color: var(--indigo); font-weight: 600; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
