/* Application styles — keep most styling in Tailwind utilities */

/* Shake animation for invalid magic link code */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
.animate-shake {
  animation: shake 0.3s ease-in-out;
}

/* Trix editor styling */
trix-editor {
  min-height: 12rem;
}

trix-editor.trix-content {
  overflow-y: auto;
}

/* plans/03 §7/§16 — Redline.html's word-level <ins>/<del> markup (attorney review
   "What changed" panel). Raw class names from app/lib/redline.rb, styled here
   since Tailwind can't safelist classes injected via server-rendered HTML.
   plans/06 P3 C1 (Tom's redline spec): insertions BLUE + BOLD, no underline;
   deletions red cross-out; MOVED text GREEN on both ends (struck where it left,
   plain where it landed). Exact blue shade may shift once Tom's black-line
   sample lands (C2). */
.redline-ins {
  background-color: #dbeafe;
  color: #1e3a8a;
  font-weight: 700;
  text-decoration: none;
}
.redline-del {
  background-color: #fee2e2;
  color: #7f1d1d;
  text-decoration: line-through;
}
.redline-replacement {
  display: block;
  margin: 0.7rem 0;
}
.redline-replacement > del,
.redline-replacement > ins {
  display: block;
  padding: 0.6rem 0.75rem;
  white-space: pre-wrap;
}
.redline-replacement > del { border-left: 3px solid #b91c1c; }
.redline-replacement > ins { margin-top: 0.35rem; border-left: 3px solid #2563eb; }
.redline-move {
  background-color: #dcfce7;
  color: #14532d;
}
del.redline-move-from {
  text-decoration: line-through;
}
ins.redline-move-to {
  text-decoration: none;
}

/* plan 04 §C2 / #523 — theme toggle icon visibility, keyed off data-theme on
   <html> (set by the <head> FOUC script + the toggle's Alpine click handler).
   Binary light ↔ dark only (no system/auto icon). <html> is never replaced by
   Turbo, so this survives Turbo visits with zero re-init flicker. */
.theme-toggle-btn .theme-icon {
  display: none;
}
html[data-theme="dark"] .theme-toggle-btn .theme-icon-dark {
  display: inline;
}
html:not([data-theme="dark"]) .theme-toggle-btn .theme-icon-light {
  display: inline;
}

/* WS1 (plan 09) — collapsible sidebar ICON RAIL. Width + label visibility are
   keyed off data-sidebar on <html> (set by the <head> FOUC script + the rail
   toggle), mirroring the theme/font no-flicker pattern: <html> is never replaced
   by Turbo, so the collapsed width survives a Turbo visit with zero flash.
   Everything is scoped under #app-sidebar so the mobile drawer (which reuses the
   same _nav_links markup) is never collapsed — it always shows full labels. */

/* The rail width. Expanded is the utility class on the aside (w-[248px]); the
   rail state overrides it. A transition softens the collapse. */
#app-sidebar { transition: width 0.15s ease; }
html[data-sidebar="rail"] #app-sidebar { width: 64px; }

/* Hide the text side of every nav row (label + count chip + section header) and
   any other expanded-only chrome (search box, firm name, profile name) in rail. */
html[data-sidebar="rail"] #app-sidebar .rail-hide { display: none !important; }

/* Center each icon in the rail: kill the row gap + horizontal padding so the
   lone icon sits centered in the 64px column. */
html[data-sidebar="rail"] #app-sidebar .nav-item,
html[data-sidebar="rail"] #app-sidebar .sb-row {
  justify-content: center;
  gap: 0;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

/* Rail-only affordances (the single Matters folder icon, the expand toggle icon):
   hidden by default, shown only when the sidebar is collapsed. */
.rail-only { display: none; }
html[data-sidebar="rail"] #app-sidebar .rail-only { display: flex; }

/* The collapse/expand toggle swaps its glyph with the state (same no-flicker
   idiom as the theme toggle icons). */
.rail-ico-collapse,
.rail-ico-expand { display: none; }
html[data-sidebar="expanded"] #app-sidebar .rail-ico-collapse,
html[data-sidebar="rail"] #app-sidebar .rail-ico-expand { display: inline-flex; }

/* b1-10 — sanitized-markdown chat bodies (the `render_markdown` helper output).
   Hand-rolled on the moonrise tokens — NOT @tailwindcss/typography — and scoped so
   it never leaks into the rest of the app. Colors reference the moonrise CSS vars,
   which flip automatically under <html.dark>. Tailwind preflight resets list styles,
   margins, and heading sizes; these unlayered rules re-establish them. Reused by the
   versions-diff feature — keep the class name exactly `md-prose`.
   Margins are tight so chat bubbles stay compact. */
.md-prose {
  overflow-wrap: anywhere;
}
.md-prose > :first-child { margin-top: 0; }
.md-prose > :last-child { margin-bottom: 0; }
.md-prose p { margin: 0.5em 0; }

.md-prose h1,
.md-prose h2,
.md-prose h3,
.md-prose h4,
.md-prose h5,
.md-prose h6 {
  margin: 0.75em 0 0.35em;
  font-weight: 600;
  line-height: 1.25;
  color: var(--color-ink);
}
.md-prose h1 { font-size: 1.25em; }
.md-prose h2 { font-size: 1.15em; }
.md-prose h3 { font-size: 1.05em; }
.md-prose h4,
.md-prose h5,
.md-prose h6 { font-size: 1em; }

/* Lists — restore markers + indent (preflight strips both). */
.md-prose ul,
.md-prose ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}
.md-prose ul { list-style: disc; }
.md-prose ol { list-style: decimal; }
.md-prose li { margin: 0.2em 0; }
.md-prose li > ul,
.md-prose li > ol { margin: 0.2em 0; }

/* Inline code + fenced blocks — subtle raised background, rounded, mono. */
.md-prose code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.875em;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-default);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.md-prose pre {
  margin: 0.5em 0;
  padding: 0.75em 0.9em;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-default);
  border-radius: 8px;
  overflow-x: auto;
}
.md-prose pre code {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.md-prose a {
  color: var(--color-steel);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* WS4 (F3) — the citation popover's primary "Go to document" CTA. It renders
   INSIDE .md-prose, whose `a { color: steel; text-decoration: underline }` above
   (unlayered) overrides Tailwind's LAYERED text-white/no-underline utilities —
   which left dark, underlined text on the blue fill (illegible: the "black on
   blue" bug). Pin the fill + white text here so it wins. The fill is a FIXED
   medium Charles-blue: the --color-charles TEXT token lightens in dark mode, which
   would kill white-text contrast, so white stays legible in BOTH themes. */
.cite-go,
.md-prose a.cite-go {
  background: #3f63a6;
  color: #fff;
  text-decoration: none;
}

/* Charles thinking orb. It appears only beside an empty answer target. Three
   translucent circles orbit one center, so waiting reads as active work rather
   than a generic typing ellipsis. Original CSS, dependency-free. */
.thinking-indicator { display: none; }
.md-prose:empty + .thinking-indicator {
  position: relative;
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 4px;
  padding: 4px 2px 4px 38px;
}
.thinking-indicator span {
  position: absolute;
  left: 12px;
  top: 10px;
  width: 13px;
  height: 13px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--color-charles) 72%, transparent);
  transform-origin: 1px 6px;
  animation: thinking-orbit 1.65s ease-in-out infinite;
}
.thinking-indicator span:nth-child(2) { animation-delay: -0.55s; opacity: 0.62; }
.thinking-indicator span:nth-child(3) { animation-delay: -1.1s; opacity: 0.36; }
.thinking-indicator small { color: var(--color-steel-muted); font-size: 0.7rem; }
@keyframes thinking-orbit {
  0%   { transform: rotate(0deg) translateX(7px) scale(0.72); }
  50%  { transform: rotate(180deg) translateX(7px) scale(1); }
  100% { transform: rotate(360deg) translateX(7px) scale(0.72); }
}
@media (prefers-reduced-motion: reduce) {
  .thinking-indicator span { animation: none; transform: none; }
  .thinking-indicator span:nth-child(2) { transform: translateX(5px); }
  .thinking-indicator span:nth-child(3) { transform: translateX(-5px); }
}

.md-prose blockquote {
  margin: 0.5em 0;
  padding-left: 0.9em;
  border-left: 3px solid var(--color-border-default);
  color: var(--color-steel-muted);
}

.md-prose strong { font-weight: 600; }
.md-prose em { font-style: italic; }
.md-prose del { text-decoration: line-through; }

.md-prose hr {
  margin: 0.9em 0;
  border: 0;
  border-top: 1px solid var(--color-border-default);
}

/* Tables — bordered cells; a wide table scrolls inside itself instead of blowing
   out the bubble. `display:block` + overflow-x makes the <table> its own scroll
   container, so no wrapper element is needed around the sanitized HTML. */
.md-prose table {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0.5em 0;
  font-size: 0.95em;
}
.md-prose th,
.md-prose td {
  border: 1px solid var(--color-border-default);
  padding: 0.35em 0.6em;
  text-align: left;
  vertical-align: top;
}
.md-prose thead th {
  background: var(--color-surface-raised);
  font-weight: 600;
}

/* ═══ WS2b (F1) — the client Preview pane: the document as ONE flowing, anchored
   HTML "page" (.paper), replacing the old paginated PDF iframe. Screen-only; the
   paginated look (@page, Page X of Y, the diagonal watermark, Changed-Pages-Only)
   lives SOLELY in the PDF export path. Paper is always light — it's paper — so it
   pins its own ink-on-white colors instead of the flipping moonrise tokens; a
   dark-mode viewer still reads a white document. Typography flows from the shared
   --doc-* tokens (print/tokens.css, which also rides into the Tailwind build) so
   the words match the exported PDF — "same words, different paper" — with only the
   base font-size differing. ══════════════════════════════════════════════════ */
.paper {
  position: relative;
  width: 100%;
  max-width: 816px;
  margin: 0 auto;
  background: #ffffff;
  color: #14202e;
  border-radius: 6px;
  box-shadow: 0 24px 60px -34px rgba(20, 34, 58, 0.34), 0 0 0 1px var(--color-border-default);
  overflow: hidden;
}

/* The repeating DRAFT band at the head and foot of the paper — the on-screen
   stand-in for the PDF's diagonal watermark. The view shows it only when
   watermark_label is present; the export path keeps the diagonal watermark. */
.draft-band {
  padding: 9px 0;
  text-align: center;
  font-family: var(--doc-font-family, "Times New Roman", Times, serif);
  letter-spacing: 14px;
  font-size: 15px;
  font-weight: 700;
  color: rgba(178, 44, 38, 0.34);
  user-select: none;
  overflow: hidden;
  white-space: nowrap;
  background: repeating-linear-gradient(90deg, transparent, transparent 4px, rgba(178, 44, 38, 0.05) 4px, rgba(178, 44, 38, 0.05) 8px);
}

/* The document body inside the paper. Reuses .md-prose for block structure, then
   overrides the compact chat rhythm with the shared document typography tokens.
   Extra left pad is the margin-flag gutter: flags sit at left:-52px on each
   section and must not clip under .paper { overflow: hidden }. */
.paper .md-prose {
  padding: clamp(28px, 6%, 104px);
  padding-top: 48px;
  padding-bottom: 56px;
  padding-left: clamp(64px, 10%, 120px);
  font-family: var(--doc-font-family, "Times New Roman", Times, Georgia, serif);
  font-size: 15px;
  line-height: var(--doc-line-height, 1.4);
  text-align: var(--doc-text-align, justify);
  color: #14202e;
}
.paper .md-prose h1,
.paper .md-prose h2,
.paper .md-prose h3,
.paper .md-prose h4,
.paper .md-prose h5,
.paper .md-prose h6 {
  color: #14202e;
  line-height: var(--doc-heading-line-height, 1.25);
  font-weight: var(--doc-heading-weight, 700);
}
.paper .md-prose h1 {
  font-size: var(--doc-h1-size, 1.6em);
  text-align: var(--doc-h1-align, center);
}
.paper .md-prose h2 { font-size: var(--doc-h2-size, 1.15em); }
.paper .md-prose h3 { font-size: var(--doc-h3-size, 1.05em); }
.paper .md-prose p { margin: 0 0 var(--doc-para-spacing, 0.7em); text-align: var(--doc-text-align, justify); }
.paper .md-prose a { color: #14202e; }

/* WS2b — each heading run is a <section id="sec-sN"> (MarkdownRenderer wraps them).
   Give each a scroll anchor margin so goToDoc()'s scrollIntoView doesn't tuck the
   heading under the sticky tab bar, and make it a positioning context for margin
   flags. Both the rendered sections and the mockup's .sec class are covered.
   .margin-flag-host wraps a heading-less body so orphan flags still pin at top. */
.sec,
.paper .md-prose > section,
.paper .md-prose .margin-flag-host {
  position: relative;
  scroll-margin-top: 1.5rem;
}

/* Preview margin flags (Tom Prototype 6) — hard-coded brass/green on always-white
   paper (same posture as .hl). Multi-flag stack uses inline top: 1 + i*36 px. */
.paper .flag {
  position: absolute;
  left: -52px;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  border: 1px solid;
  transition: 0.15s;
  cursor: pointer;
  padding: 0;
  margin: 0;
  line-height: 0;
  z-index: 2;
}
.paper .flag svg {
  width: 15px;
  height: 15px;
}
.paper .flag.open {
  color: #9a6f24;
  background: rgba(205, 159, 94, 0.18);
  border-color: rgba(205, 159, 94, 0.5);
}
.paper .flag.open:hover {
  background: rgba(205, 159, 94, 0.3);
}
.paper .flag.closed {
  color: #4f7a58;
  background: rgba(127, 168, 134, 0.16);
  border-color: rgba(127, 168, 134, 0.45);
}
.paper .flag.closed:hover {
  background: rgba(127, 168, 134, 0.26);
}

/* WS2b — the jump-and-flash pulse. goToDoc() adds .flash to the target section
   after a forced reflow (void el.offsetWidth) so a repeat jump to the SAME section
   re-triggers the animation (Tom's mockup mechanic). */
@keyframes flash {
  0%, 100% { background: transparent; }
  22% { background: rgba(205, 159, 94, 0.16); }
}
.sec.flash,
.paper .md-prose > section.flash {
  animation: flash 1.4s ease;
}

/* WS5 — the same jump-and-flash pulse for a question card, when goToQuestion() lands
   on it from a chat reference / persistent URL. Its own class (the .flash selectors
   above are preview-section-scoped); rounded to match the card. */
.q-flash {
  animation: flash 1.4s ease;
  border-radius: var(--radius-lg);
}

/* WS2b — persistent passage highlights WS4 (Charles citations) and WS5 (question
   anchors) wrap around a quoted span in the preview. Fixed amber (default) / green
   so they read on the always-white paper. */
.hl {
  background: rgba(205, 159, 94, 0.26);
  border-radius: 3px;
  padding: 0 2px;
  box-shadow: 0 0 0 1px rgba(205, 159, 94, 0.4);
}
.hl.green {
  background: rgba(127, 168, 134, 0.22);
  box-shadow: 0 0 0 1px rgba(127, 168, 134, 0.4);
}

/* ── Document Library table (ticket #230, Tom 2026-07-18 items #1/#2) ──────────
   Reference: docs/2026-07-14 Brenmere - Prototype 5 (client side) - Documents
   update.html (.dms-th / .dms-row).

   "each line is uniform height and if fields don't fit they are hidden with
   ellipses rather than wrapping onto a second line."

   Tailwind's `truncate` handles one element; a TABLE needs the rule on the cell
   itself, because a <td> is the wrapping box. Paired with table-layout:fixed and a
   width on every column (a <colgroup> in the view), so a long "Employment
   Agreement" ellipsizes inside its own column instead of shoving "Acme Law" out of
   the next one, and a narrow Notes column shows "Add a note…" rather than one
   character per line. Below the table's min-width the wrapper scrolls
   horizontally — overflow HIDDEN, per Tom, never jumbled.

   Cells opt out with .doc-cell-open (the kebab column, whose popover is teleported
   to <body> anyway).

   The ellipsis is on <td> ONLY. A filterable <th> holds shared/_filterable_th, whose
   root is an `inline-flex` wrapper around a `w-full justify-between` button with an
   opacity-0 hover chevron pinned to its right edge. That wrapper is an atomic inline
   box that overflows the header's line box (measured on Version: scrollWidth 108 vs
   clientWidth 78), so text-overflow painted a stray "…" over content that is
   invisible anyway — a floating dot sitting between VERSION and LAST MODIFIED in
   every header row. Header labels are short and already clip cleanly under
   overflow:hidden, so dropping the ellipsis there costs nothing. */
.doc-table th,
.doc-table td {
  overflow: hidden;
  white-space: nowrap;
}
.doc-table td {
  text-overflow: ellipsis;
}
.doc-table th.doc-cell-open,
.doc-table td.doc-cell-open {
  overflow: visible;
}

/* Uniform row height. Every row is one band tall whatever it holds — a status
   pill, the notes input, the kebab — so the eye tracks straight across. */
.doc-table tbody tr {
  height: 3.25rem;
}
