/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 *
 * Component styles below are adapted verbatim from the locked design system's reference
 * (.lila/components.html) — see .lila/USAGE.md. Only tokens declared in tokens.css are used.
 */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  margin: 0;
}
h1 { font-size: var(--text-3xl); font-weight: 700; letter-spacing: var(--tracking-display); }
h2 { font-size: var(--text-2xl); font-weight: 700; letter-spacing: var(--tracking-display); }
h3 { font-size: var(--text-lg); font-weight: 700; }
p { margin: 0; }
.body-muted { color: var(--muted); }
.body-sm { font-size: var(--text-sm); }

/* Links: terracotta, faint underline, swap to a terracotta-tinted background on hover
   instead of a heavier underline — .lila/DESIGN.md "Links" recipe. */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--accent), transparent 60%);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  border-radius: 3px;
}
a:hover {
  text-decoration: none;
  background: color-mix(in oklab, var(--accent), transparent 92%);
}

/* ─── Page shell (auth screens + authenticated home) ────────────── */
.page-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}
.stack-2 > * + * { margin-block-start: var(--space-2); }
.stack-3 > * + * { margin-block-start: var(--space-3); }
.stack-4 > * + * { margin-block-start: var(--space-4); }
.stack-6 > * + * { margin-block-start: var(--space-6); }

/* ─── Card ────────────────────────────────────────────────────── *
 * .lila/DESIGN.md "Cards": off-white surface, 16px radius, 24px+ padding,
 * hairline border, NO shadow at rest — only on hover (raised, per
 * .lila/DESIGN.md "Depth & Elevation"). */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 360px;
  box-shadow: var(--elev-flat);
  transition: box-shadow var(--motion-base) var(--ease-standard), border-color var(--motion-base) var(--ease-standard);
}
.card:hover { box-shadow: var(--elev-raised); border-color: color-mix(in oklab, var(--border), var(--accent) 25%); }

/* ─── Buttons ─────────────────────────────────────────────────── *
 * .lila/DESIGN.md "Buttons": flat fill, radius-md, generous inline padding,
 * primary = terracotta fill / off-white label, secondary = outlined. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  border: 1px solid transparent;
  transition:
    transform var(--motion-fast) var(--ease-standard),
    background-color var(--motion-fast) var(--ease-standard),
    border-color var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard);
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn-primary { background: var(--accent); color: var(--accent-on); width: 100%; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { background: var(--accent-active); transform: translateY(0); }
.btn-secondary { background: var(--surface); color: var(--fg); border-color: var(--border); box-shadow: var(--elev-ring); }
.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Form fields ─────────────────────────────────────────────── *
 * .lila/DESIGN.md "Inputs": underline only — no box, no shadow. 1px
 * muted baseline, terracotta baseline on focus, 16px vertical padding. */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field label { font-size: var(--text-sm); font-weight: 700; color: var(--fg-2); }
.field input {
  padding: var(--space-4) 2px;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--muted);
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: var(--text-base);
  outline: none;
  width: 100%;
  transition: border-color var(--motion-fast) var(--ease-standard), border-bottom-width var(--motion-fast) var(--ease-standard);
}
.field input:focus-visible { outline: none; border-bottom-color: var(--accent); border-bottom-width: 2px; padding-block-end: calc(var(--space-4) - 1px); }
.field input::placeholder { color: var(--muted); }

/* ─── Badges (status pills — flash messages, scores, run states) ── *
 * Editorial treatment: soft tint fill, uppercase micro-label, pill radius —
 * echoes the reference system's `.status` marker without borrowing its
 * mono font (mono stays reserved for code/eyebrows per DESIGN.md). */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: 100%;
}
.badge-success { color: var(--success); background: color-mix(in oklab, var(--success), transparent 90%); }
.badge-danger { color: var(--danger); background: color-mix(in oklab, var(--danger), transparent 90%); }
.badge-muted { color: var(--muted); background: color-mix(in oklab, var(--muted), transparent 88%); }
.badge-inline { display: inline-flex; width: auto; }

/* ─── Container / section (content screens, wider than the auth card) ──
 * Adapted verbatim from .lila/components.html's layout primitives. */
.container {
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--container-gutter-desktop);
  padding-block: var(--space-8);
}
@media (max-width: 1023px) { .container { padding-inline: var(--container-gutter-tablet); } }
@media (max-width: 639px) { .container { padding-inline: var(--container-gutter-phone); } }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
/* .lila/components.html .eyebrow recipe verbatim: mono micro-label in the meta tone. */
.eyebrow { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--meta); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 700; }

/* ─── Nav (top bar linking the content-pipeline screens) ─────────── *
 * flex-wrap lets the right-hand (email + logout) group drop to its own row
 * on narrow viewports instead of overflowing the 390px iPhone width. */
.nav-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-4); padding-block-end: var(--space-5); border-bottom: 1px solid var(--border); margin-block-end: var(--space-8); }
.nav-links { display: flex; flex-wrap: wrap; gap: var(--space-5); align-items: center; }
/* Links: min-height 44px matches .btn's tap-target floor (iOS guidance) --
 * flex + center keeps the text vertically centered instead of just padding. */
.nav-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--fg); font-weight: 500; font-size: var(--text-sm); text-decoration: none; border-radius: 3px; padding: var(--space-1) var(--space-2); }
.nav-links a:hover { background: color-mix(in oklab, var(--accent), transparent 92%); color: var(--accent); }
.nav-links a.active { color: var(--accent); font-weight: 700; }
.nav-brand { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; letter-spacing: var(--tracking-display); }

/* ─── Cards used as list rows, not just the auth panel ───────────── */
.card-wide { max-width: none; }
.card-list > * + * { margin-block-start: var(--space-3); }

/* ─── Form fields: extend the input recipe to textarea/select/radio ──
 * Same underline recipe as .field input above — no new visual language.
 * Textarea keeps a hairline full-border since underline-only reads badly
 * on a multi-line block, but drops the box radius/shadow to stay flat. */
.field textarea {
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-family: inherit;
  font-size: var(--text-base);
  outline: none;
  width: 100%;
  resize: vertical;
  transition: border-color var(--motion-fast) var(--ease-standard);
}
.field select {
  padding: var(--space-4) 2px;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--muted);
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: var(--text-base);
  outline: none;
  width: 100%;
  transition: border-color var(--motion-fast) var(--ease-standard);
}
.field textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.field select:focus-visible { outline: none; border-bottom-color: var(--accent); border-bottom-width: 2px; }
.field-help { font-size: var(--text-xs); color: var(--muted); }

.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form-wide { max-width: 640px; }
.form-actions { display: flex; gap: var(--space-3); margin-block-start: var(--space-2); }

/* ─── Rubric / choice rows (radio + checkbox groups) ──────────────
 * Native controls tinted with --accent, laid out with the same field
 * label rhythm as text inputs — deliberately no custom-drawn control. */
.choice-group { display: flex; flex-direction: column; gap: var(--space-2); }
.choice-group legend, .field legend { font-size: var(--text-sm); font-weight: 500; padding: 0; margin-block-end: var(--space-2); }
.choice-row { display: flex; gap: var(--space-5); flex-wrap: wrap; }
.choice-option { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.choice-option input[type="radio"], .choice-option input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
fieldset.field { border: none; padding: 0; margin: 0; }

/* ─── Empty state ─────────────────────────────────────────────── */
.empty-state { text-align: center; padding: var(--space-8) var(--space-4); color: var(--muted); font-style: italic; }

/* ─── Phase B: interview / draft / council screens ────────────────
 * Additive only — same tokens/recipes as the rest of the design system. */
.quote-block {
  border-left: 3px solid var(--border);
  padding-inline-start: var(--space-4);
  color: var(--fg);
  font-style: italic;
}
.draft-text {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  white-space: pre-wrap;
  font-size: var(--text-base);
}
/* Numbers-that-matter get the display (serif) face — .lila/DESIGN.md
 * "Do's": "Use serif for numbers when they matter (pricing, stats)." */
.score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5em;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
}
.score-pill-pass { color: var(--success); background: color-mix(in oklab, var(--success), transparent 90%); }
.score-pill-mid { color: var(--warn); background: color-mix(in oklab, var(--warn), transparent 88%); }
.score-pill-low { color: var(--danger); background: color-mix(in oklab, var(--danger), transparent 90%); }
.lens-list { display: flex; flex-direction: column; gap: var(--space-2); padding: 0; margin: 0; list-style: none; }
.lens-list li { padding: var(--space-2) var(--space-3); background: var(--bg); border-radius: var(--radius-sm); }
.spinner-note { display: flex; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--text-sm); }
.spinner-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: spinner-pulse 1s var(--ease-standard) infinite;
}
@keyframes spinner-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
.divider { border: none; border-top: 1px solid var(--border); margin-block: var(--space-4); }

/* ─── Phase C: proposed-vs-posted diff, guardrail checks, voice lessons ──
 * Additive only — same tokens/recipes as the rest of the design system. */
.diff-text { line-height: var(--leading-body); }
.diff-removed, .diff-added {
  /* A removed/added pair sits in the same "slot" with no source whitespace between them
     (the space tokens on either side are unchanged and belong to the surrounding words) --
     without this the two runs visually collide (e.g. "EveryoneWe"). A hair of margin keeps
     each run legible as its own token without introducing a space that wasn't really posted. */
  margin-inline: 1px;
  padding-inline: 1px;
}
.diff-removed {
  color: var(--danger);
  background: color-mix(in oklab, var(--danger), transparent 90%);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  border-radius: 3px;
}
.diff-added {
  color: var(--success);
  background: color-mix(in oklab, var(--success), transparent 90%);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
  border-radius: 3px;
}

/* ─── Chat pivot: conversation list + thread view ──────────────────
 * Additive only — same tokens/recipes as the rest of the design system. Chat bubbles reuse the
 * card surface/border recipe rather than inventing a new visual language; only layout (alignment,
 * max-width, gap) is new here. */
.chat-shell { display: flex; flex-direction: column; gap: var(--space-4); }
.message-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 320px;
  max-height: 65vh;
  overflow-y: auto;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
}
.message-row { display: flex; }
.message-row.role-user { justify-content: flex-end; }
.message-row.role-assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 72%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--elev-flat);
}
.chat-bubble p { white-space: pre-wrap; }
.chat-bubble-user {
  background: color-mix(in oklab, var(--accent), transparent 88%);
  border: 1px solid color-mix(in oklab, var(--accent), transparent 68%);
}
.chat-bubble-assistant { background: var(--surface); border: 1px solid var(--border); }
.message-meta { display: block; font-size: var(--text-xs); color: var(--muted); margin-block-end: var(--space-1); }
.chat-card { max-width: 88%; }
.chat-card .card { max-width: none; }

/* Composer: pinned form row under the scrolling message list. */
.composer { display: flex; gap: var(--space-3); align-items: flex-end; }
.composer .field { flex: 1; margin: 0; }
.composer .field label {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.composer textarea { min-height: 44px; max-height: 200px; }
/* .btn-primary defaults to width:100% for stacked single-button forms (e.g. sign-in) -- override
   back to intrinsic width here so it sits beside the textarea instead of fighting it for space. */
.composer .btn { flex-shrink: 0; width: auto; }

/* Conversation list rows (threads index). */
.conversation-row .row-between { align-items: flex-start; }

/* ─── Chat pivot (part 2): Topics tab ───────────────────────────── *
 * A topic row is a button_to wrapping a whole card so the entire row is clickable (opens/creates
 * its conversation) -- reset the generated <button> back to an unstyled block so the card inside
 * reads exactly like every other card, not like a form control. */
.card-link-button {
  display: block;
  width: 100%;
  max-width: 360px;
  padding: 0;
  border: none;
  background: none;
  text-align: inherit;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.card-link-button .card { max-width: none; }
.topic-row .row-between { align-items: flex-start; }

/* ─── Mobile audit fixes (installed-PWA-on-iPhone is the only surface that matters) ── */

/* A conversation's <h1> renders dynamic, potentially-long text (the topic name, or a truncated
   first message up to 60 chars) -- not a short static hero headline like "Sign In"/"Topics".
   The global 64px h1 turns a realistic title into 5-6 lines on a phone, pushing the whole thread
   (messages + composer) off the first screen. Same weight/family, a size that reads as a page
   title instead of a hero. */
.thread-title { font-size: var(--text-xl); }

/* Free-text messages (flash alerts/notices, the guardrail warning sentence) were being rendered
   with .badge's status-pill treatment: pill radius, all-caps, tight letter-spacing. That reads
   fine for a two-word label ("Pass", "checking…") but at mobile width a full sentence wraps to
   several lines and the 9999px radius collapses into a lopsided blob that eats into the text,
   plus all-caps over a whole sentence is hard to read. Keep the same color tint, drop the
   pill/shout treatment for anything that's actually a sentence. */
.badge-block {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  font-size: var(--text-sm);
  line-height: var(--leading-body);
  text-align: left;
}

/* Long unbroken tokens (a pasted URL, a long slug) shouldn't be able to force horizontal scroll
   inside a card or bubble on a 390px-wide screen. Conversation titles fall back to the raw first
   message (see Conversation#title) so .thread-title needs the same guard as the bubbles below it.
   `anywhere`, not `break-word`: these titles/badges sit in flex row (.row-between) items, and
   per spec `break-word` doesn't shrink a flex item's automatic min-width, so the overflow still
   pushed the row wider than the viewport -- `anywhere` also counts toward min-content sizing, so
   the flex item can actually shrink down to the container instead of forcing horizontal scroll. */
.card, .chat-bubble, .draft-text, .thread-title { overflow-wrap: anywhere; }
.row-between > * { min-width: 0; }

/* Composer: stick to the bottom of the viewport instead of sitting in normal document flow,
   so it stays reachable on a tall thread and doesn't get lost below the fold when the iOS
   keyboard opens (the visual viewport shrinks and the sticky element re-anchors to the new
   bottom edge). The safe-area inset keeps it clear of the home-indicator area on an iPhone;
   requires `viewport-fit=cover` on the viewport meta tag, set in the layout. */
.composer {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding-block: var(--space-3);
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  margin-inline: calc(-1 * var(--container-gutter-phone));
  padding-inline: var(--container-gutter-phone);
}
@media (min-width: 640px) {
  .composer { margin-inline: calc(-1 * var(--container-gutter-tablet)); padding-inline: var(--container-gutter-tablet); }
}
@media (min-width: 1024px) {
  .composer { margin-inline: calc(-1 * var(--container-gutter-desktop)); padding-inline: var(--container-gutter-desktop); }
}
