/* Memex Design System — colour, type, spacing, radii, shadows.
   Source of truth: ripple.css + brand brief, ported from
   memex-design-system/project/colors_and_type.css. */

@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Source+Sans+3:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Roboto:wght@500&display=swap');

:root {
  --paper:              #fbfaf7;
  --paper-raised:       #ffffff;
  --paper-sunken:       #f4f2ed;
  --paper-edge:         #ebe8e0;

  --ink:                #1a1a1a;
  --ink-soft:           #3d3a36;
  --ink-muted:          #6b6763;
  --ink-faint:          #b0adae;
  --ink-ghost:          #d9d5ce;

  --highlight:          #ffd200;
  --highlight-wash:     rgba(255, 210, 0, 0.38);
  --highlight-faint:    rgba(255, 210, 0, 0.16);

  --danger:             #8a2f2a;

  --font-serif:   "EB Garamond", "Garamond", "Georgia", ui-serif, serif;
  --font-sans:    "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --text-sm:     14px;
  --text-base:   16px;
  --text-md:     18px;
  --text-lg:     22px;
  --text-xl:     28px;
  --text-2xl:    36px;

  --leading-tight:  1.15;
  --leading-snug:   1.35;
  --leading-normal: 1.5;

  --tracking-snug:  -0.01em;
  --tracking-normal: 0;

  --radius-image: 1px;
  --radius-xs:  4px;
  --radius-sm:  6px;

  --dur-fast:    120ms;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}
/* Belt-and-suspenders: any user-supplied image (in note bodies,
   summaries, marginalia notes) is capped to its container so a
   native-sized photo can't blow the layout out. More specific rules
   in component scopes still win. */
img { max-width: 100%; height: auto; }

/* ---------- Top nav ---------- */
.nav {
  display: flex; align-items: center; gap: 4px;
  padding: 16px 40px;
  border-bottom: 1px solid var(--paper-edge);
  background: var(--paper);
  position: sticky; top: 0; z-index: 30;
}
.nav a.link {
  font-family: var(--font-sans); font-size: 13px; font-weight: 500;
  color: var(--ink-muted);
  padding: 6px 12px; border-radius: var(--radius-sm);
  text-decoration: none;
}
.nav a.link:hover { background: var(--paper-sunken); color: var(--ink); }
.nav a.link.active { color: var(--ink); background: var(--paper-sunken); }
.nav .spacer { flex: 1; }
.nav .signout {
  font-family: var(--font-sans); font-size: 13px; color: var(--ink-muted);
  text-decoration: none; padding: 6px 10px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; gap: 6px;
}
.nav .signout:hover { color: var(--ink); background: var(--paper-sunken); }

/* ---------- Mobile: hamburger + slide-down menu (spec 0033 responsive header) ----------
   Both hidden on desktop; the @media block at the end of this file switches the
   nav over below 760px (links + Sign out collapse into .nav-menu). */
.nav-hamburger {
  display: none; flex: none;
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid transparent; background: transparent;
  color: var(--ink-muted); cursor: pointer;
  align-items: center; justify-content: center;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.nav-hamburger:hover { background: var(--paper-sunken); color: var(--ink); }
.nav-menu {
  position: absolute; top: 100%; left: 0; right: 0;
  display: none;
  background: var(--paper);
  border-bottom: 1px solid var(--paper-edge);
  box-shadow: 0 14px 26px rgba(40, 34, 26, 0.07);
  padding: 6px 16px 12px;
}
.nav-menu a, .nav-menu .menu-signout {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 10px; border-radius: 8px;
  font-family: var(--font-sans); font-size: 15px; font-weight: 500;
  color: var(--ink-soft); text-decoration: none;
  background: none; border: 0; width: 100%; cursor: pointer; text-align: left;
}
.nav-menu a:hover, .nav-menu .menu-signout:hover { background: var(--paper-sunken); }
.nav-menu a.active { background: var(--paper-sunken); color: var(--ink); }
.nav-menu a i, .nav-menu .menu-signout i { color: var(--ink-muted); flex: none; }
.nav-menu .menu-sep { border: none; border-top: 1px solid var(--paper-edge); margin: 8px 2px; }
.nav-menu .menu-signout { color: var(--ink-muted); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-sans); font-size: 13px; font-weight: 500;
  padding: 7px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--paper-edge); background: var(--paper-raised);
  color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--dur-fast) ease;
  text-decoration: none;
}
.btn:hover { background: var(--paper-sunken); }
.btn:focus-visible { outline: 2px solid var(--ink-ghost); outline-offset: 2px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(138, 47, 42, 0.06); }

/* Icon button (square, transparent at rest, paper-raised on hover) */
.ibtn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent;
  color: var(--ink-ghost); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color var(--dur-fast) ease, background var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.ibtn:hover, .ibtn:focus-visible {
  color: var(--ink); background: var(--paper-raised);
  border-color: var(--paper-edge);
  outline: none;
}
.ibtn.danger:hover, .ibtn.danger:focus-visible {
  color: var(--danger); border-color: rgba(138, 47, 42, 0.25);
}
.ibtn.sm { width: 28px; height: 28px; }

/* ---------- Type indicator chip (kind) ---------- */
.kind {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-sans); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-muted);
  padding: 2px 8px; border-radius: var(--radius-xs);
  background: var(--paper-sunken);
  flex-shrink: 0;
}
.kind.note    { color: #6a4f0f; background: rgba(255, 210, 0, 0.18); }
.kind.pdf     { color: #5a4634; background: #efe9df; }
.kind.webpage { color: #4a4a4a; background: #ececec; }

.kind.processing {
  color: var(--ink-muted);
  background: var(--paper-sunken);
  animation: chip-pulse 1.6s ease-in-out infinite;
}
.kind.processing svg { animation: chip-spin 1.6s linear infinite; }
@keyframes chip-pulse {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 1; }
}
@keyframes chip-spin { to { transform: rotate(360deg); } }

/* ---------- Messages (Django flash messages) ---------- */
.message {
  font-family: var(--font-sans); font-size: 13px;
  padding: 10px 14px;
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  color: var(--ink);
  margin: 16px 40px 0;
}
.message.error { color: var(--danger); border-color: rgba(138, 47, 42, 0.25); }

/* ---------- Generic prose (used by note bodies and the summary) ---------- */
.prose {
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1.65;
  color: var(--ink);
}
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 1.05em; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  font-family: var(--font-serif);
  color: var(--ink-soft);
  font-weight: 500;
  line-height: var(--leading-snug);
  margin: 1.4em 0 0.5em;
}
.prose h1 { font-size: var(--text-2xl); }
.prose h2 { font-size: var(--text-xl); }
.prose h3 { font-size: var(--text-lg); }
.prose h4, .prose h5, .prose h6 { font-size: var(--text-md); }
.prose img {
  max-width: 100%;
  display: block;
  margin: 1.4em auto;
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-image);
  background: var(--paper-raised);
  padding: 6px;
}
.prose ul, .prose ol { padding-left: 1.5rem; margin: 0.75rem 0; }
.prose ul { list-style: disc; }
.prose ol { list-style: decimal; }
.prose li { margin-bottom: 0.35rem; }
.prose li p { margin: 0; }
.prose a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--ink-ghost);
  text-underline-offset: 3px;
}
.prose a:hover { text-decoration-color: var(--highlight); }
.prose .img-page {
  display: inline-block; margin-left: 0.5rem;
  font-family: var(--font-sans); font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.prose a.summary-img-link { display: inline-block; }
.prose code {
  font-family: var(--font-mono); font-size: 0.9em;
  background: var(--paper-sunken);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-xs);
  color: var(--ink-soft);
}
/* Inside <pre>, the inline-code styling above produces a per-line
   pill effect (one rectangle per visual line of preformatted content).
   Reset to a single block-level treatment on the <pre> itself. */
.prose pre {
  background: var(--paper-sunken);
  border-radius: var(--radius-xs);
  padding: 12px 14px;
  overflow-x: auto;
}
.prose pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}
.prose p:has(img + img) { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.prose p:has(img + img) img { flex: 1 1 calc((100% - 12px) / 2); max-width: calc((100% - 12px) / 2); height: auto; }

/* ---------- KaTeX math ----------
   Display math (`$$…$$` / `\[…\]`) is wrapped by the renderer in .math-block.
   KaTeX supplies its own typography via katex.min.css; we only need to keep a
   wide equation from breaking the page — scroll it instead. Applies on every
   surface that renders markdown (summaries, notes, agent answers). */
.math-block { overflow-x: auto; overflow-y: hidden; margin: 1.1em 0; }
.katex-display { margin: 0; }        /* our .math-block owns the vertical rhythm */
.katex { font-size: 1.05em; }        /* nudge to sit with EB Garamond body text */

/* ---------- Plain-text uploads ----------
   .txt files are rendered as escaped text inside this container so leading
   whitespace, asterisks, hashes, and brackets survive verbatim — no
   markdown2 interpretation. Monospace because .txt files commonly rely on
   column alignment (screenplays, ASCII tables, fixed-width logs). */
.plain-text {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ---------- Inline note editor (spec 0042) ----------
   The Milkdown editing surface reuses .prose (added in the template) so edit and
   read look identical. These classes style the Memex chrome around it (status,
   images drawer) with design tokens; Milkdown's own slash menu / toolbar / block
   handle come from editor.min.css (Crepe), lightly aligned to our paper/ink below. */
.note-editor {
  position: relative;
}
/* Autosave status lives in the page's top row (masthead meta-row / create-page
   eyebrow), not above the editor — set by note_editor.js. */
.note-editor-status {
  font-family: var(--font-sans);
  font-size: 12px; /* match the inline meta-row text exactly (same size/metrics → aligned) */
  color: var(--ink-faint);
  transition: color var(--dur-fast) ease;
}
.note-editor-status[data-state="error"] { color: var(--danger); }
/* Create page: "New note" eyebrow left, autosave status right, on one compact row. */
.note-create-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.note-editor-surface { outline: none; }
/* A UserItemNote (note on a PDF/webpage) is marginalia: the editor carries the
   same gray left rule as the 1A empty affordance and the rendered .note-block, so
   the bar stays consistent across empty → editing → saved. */
.note-editor--margin {
  border-left: 2px solid var(--ink-ghost);
  padding-left: 22px;
  margin: 0 0 32px;
}
/* Crepe paints its own frame + theme; strip the frame and align the EDITING
   content (not the menus/toolbar, which stay in Crepe's sans UI font) to the
   .prose type scale. Selectors are scoped under .note-editor so they out-specify
   Crepe's `.milkdown …` rules, which load after design.css. */
.note-editor .milkdown {
  background: transparent;
  box-shadow: none;
  --crepe-font-code: var(--font-mono);
  --crepe-color-background: transparent;
  --crepe-color-on-background: var(--ink);
}
/* Full-width editing surface — Crepe defaults to `padding:60px 120px`; drop the
   horizontal inset so the body fills the .prose column (the block handle then
   sits in the page's left margin). */
.note-editor .milkdown .ProseMirror {
  padding: 8px 0;
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1.65;
  color: var(--ink);
}
/* Mirror .prose block spacing so what you type renders identically to the display
   (Crepe's paragraph/heading sizes AND margins differ from .prose). */
.note-editor .milkdown .ProseMirror > :first-child {
  margin-top: 0;
}
/* Crepe sets `.ProseMirror p { font-size:16px; line-height:24px; padding:4px 0 }`
   directly on the paragraph, out-specifying the 19px on .ProseMirror above — so
   restate the .prose body metrics (19px / 1.65) on the paragraph itself, or note
   text renders two sizes smaller than summaries and highlights. Applies to list
   paragraphs too (they're `.ProseMirror p`), so bullet text matches as well. */
.note-editor .milkdown .ProseMirror p {
  font-size: 19px;
  line-height: 1.65;
  padding: 0;
  margin: 0 0 1.05em;
}
.note-editor .milkdown .ProseMirror h1,
.note-editor .milkdown .ProseMirror h2,
.note-editor .milkdown .ProseMirror h3,
.note-editor .milkdown .ProseMirror h4,
.note-editor .milkdown .ProseMirror h5,
.note-editor .milkdown .ProseMirror h6 {
  font-family: var(--font-serif);
  font-weight: 500;
  color: var(--ink-soft);
  line-height: var(--leading-snug);
  margin: 1.4em 0 0.5em;
  padding: 0;
}
.note-editor .milkdown .ProseMirror h1 { font-size: var(--text-2xl); }
.note-editor .milkdown .ProseMirror h2 { font-size: var(--text-xl); }
.note-editor .milkdown .ProseMirror h3 { font-size: var(--text-lg); }
.note-editor .milkdown .ProseMirror h4,
.note-editor .milkdown .ProseMirror h5,
.note-editor .milkdown .ProseMirror h6 {
  font-size: var(--text-md);
}
/* List markers. Baseline-align the row so an ordered number (real text) sits on
   the text baseline. Make the label a block with the .prose line-height so its
   baseline IS the text line's baseline. The unordered bullet is a 24×24 SVG with
   its dot centered (cy=12) — baseline-aligning would land the SVG's bottom edge on
   the text baseline and float the dot ~12px too high, so `vertical-align: middle`
   drops the dot onto the text's x-height. One rule set handles ol and ul. */
.note-editor .milkdown milkdown-list-item-block > .list-item {
  align-items: baseline;
}
.note-editor .milkdown milkdown-list-item-block li .label-wrapper {
  display: block;
  height: auto;
  padding: 0;
  line-height: 1.65;
  text-align: right;
}
.note-editor .milkdown milkdown-list-item-block li .label-wrapper .label {
  height: auto;
  padding: 0;
}
.note-editor .milkdown milkdown-list-item-block li .label-wrapper .label svg {
  vertical-align: middle;
}
/* List spacing: mirror `.prose` (`li p { margin: 0 }` + `li { margin-bottom:
   0.35rem }`). Without the paragraph reset, each list item's inner paragraph
   inherits the 1.05em block margin above and every bullet balloons apart — the
   summary prose packs tight, so the note editor should too. */
.note-editor .milkdown .ProseMirror milkdown-list-item-block p {
  margin: 0;
}
.note-editor .milkdown .ProseMirror milkdown-list-item-block {
  margin-bottom: 0.35rem;
}

/* Click-to-edit title (spec 0042). The h1 itself is the affordance. */
.editable-title {
  cursor: text;
  border-radius: var(--radius-xs);
  transition: background var(--dur-fast) ease;
}
.editable-title:hover { background: var(--paper-sunken); }
.editable-title.is-empty { color: var(--ink-faint); font-style: italic; }
.title-edit-input {
  font: inherit;
  /* The input lives inside the h1, which is still `.is-empty` (italic, muted)
     until a title is saved — reset both so typing renders as a normal title. */
  font-style: normal;
  color: var(--ink);
  width: 100%;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  outline: none;
}
.note-format-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.note-body-editor { margin: 16px 0; }

/* Design 1A "The empty note" — the Add-a-note affordance for saved items
   (spec 0042). An empty marginalia note: a left rule + serif-italic prompt that
   blooms to ink + a faint-highlight wash on hover, previewing what a filled note
   becomes. Rendered as a full-width button; reset the browser chrome. */
.note-empty {
  display: block;
  width: 100%;
  text-align: left;
  appearance: none;
  border: none;
  border-left: 2px solid var(--ink-ghost);
  background: transparent;
  padding: 10px 0 10px 22px;
  margin: 0 0 32px;
  cursor: text;
  transition: border-color 120ms ease, background 120ms ease;
}
.note-empty:hover {
  border-left-color: var(--ink);
  background: var(--highlight-faint);
}
.note-empty-inner {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 17px;
  line-height: 1.4;
  color: var(--ink-faint);
}
.note-empty-inner svg { flex: none; }

/* A written note-on-item is click-to-edit (like the title): the whole marginalia
   block opens the editor, blooming to an ink rule + faint-highlight wash on hover —
   the same gesture as the 1A empty affordance. No separate Edit button. */
.note-block--edit {
  cursor: text;
  transition: border-color 120ms ease, background 120ms ease;
}
.note-block--edit:hover,
.note-block--edit:focus-visible {
  border-left-color: var(--ink);
  background: var(--highlight-faint);
  outline: none;
}

/* ---------- Forms (overrides for design system) ---------- */
input[type="text"], input[type="url"], input[type="email"],
input[type="password"], input[type="file"], textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--ink);
}
textarea { min-height: 280px; font-family: var(--font-mono); font-size: 14px; line-height: 1.5; }
input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--ink-ghost); outline-offset: 1px;
}
label {
  display: block;
  font-family: var(--font-sans);
  font-size: 12px; font-weight: 500;
  color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.error { color: var(--danger); font-size: 13px; }
/* Checkboxes need to defeat the generic input + label rules above. */
.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
}
.checkbox-field label {
  display: inline;
  margin: 0;
  text-transform: none;
  letter-spacing: normal;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
}
/* Spec 0041: a disabled (unverified-email) opt-in reads muted, with a teaching
   hint below carrying an inline "Resend verification" button styled as a link
   (an explicit colour so it doesn't inherit the browser-default purple). */
.checkbox-field input[type="checkbox"]:disabled + label { color: var(--ink-faint); }
.checkbox-hint {
  margin: 6px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-muted);
}
.checkbox-hint .linklike {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink);
  text-decoration: underline;
  cursor: pointer;
}
.checkbox-hint .linklike:hover { color: var(--ink-soft); }
/* The "Sent ✓" acknowledgement after a resend. A fresh node is swapped in on
   every click, so this highlight-fade replays each time — the signal that a
   repeated "Send again" actually fired. */
.checkbox-hint .resend-flash {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 3px;
  border-radius: 3px;
  color: var(--ink);
  animation: resend-flash 0.8s ease-out;
}
@keyframes resend-flash {
  from { background-color: rgba(255, 210, 0, 0.6); }
  to { background-color: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .checkbox-hint .resend-flash { animation: none; }
}
form button[type="submit"] {
  margin-top: 16px;
  padding: 9px 18px;
  background: var(--ink); color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans); font-size: 14px; font-weight: 500;
  cursor: pointer;
}
form button[type="submit"]:hover { opacity: 0.92; }
form button[type="submit"]:disabled { opacity: 0.45; cursor: default; }

/* ---------- Generic page wrapper ---------- */
.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 36px 28px 96px;
}
.page-form {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 28px 96px;
}
.page-form h1 {
  font-family: var(--font-serif); font-weight: 500;
  font-size: var(--text-2xl); line-height: var(--leading-tight);
  letter-spacing: var(--tracking-snug);
  color: var(--ink-soft);
  margin: 0 0 8px;
}
.page-form .lede {
  font-family: var(--font-sans); font-size: 13px;
  color: var(--ink-muted);
  margin: 0 0 28px;
}
.page-form form > div { margin-bottom: 18px; }

/* ---------- Form action row (submit + cancel) ---------- */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}
.form-actions a.cancel {
  font-family: var(--font-sans); font-size: 13px; font-weight: 500;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 8px 12px; border-radius: var(--radius-sm);
}
.form-actions a.cancel:hover { color: var(--ink); background: var(--paper-sunken); }

/* Surrounding form's default-styled submit button (set by the global
   `form button[type="submit"]` rule) needs no extra margin when it
   lives inside .form-actions. */
.form-actions form button[type="submit"],
.form-actions button[type="submit"] { margin-top: 0; }

/* Sign-in action row: providers on the left, primary actions kept right.
   margin-left:auto keeps the primary group right even when no provider is
   configured, so the base .form-actions justify-content is left untouched. */
.auth-providers { display: flex; align-items: center; gap: 12px; }
.form-actions .form-actions-primary {
  display: flex; align-items: center; gap: 12px; margin-left: auto;
}

/* On mobile the three sign-in actions (Google / Create account / Sign in)
   cram onto one row and wrap their labels ("Sign / in") — issue #211.
   Stack them full-width instead. */
@media (max-width: 640px) {
  .form-actions.auth-actions { flex-direction: column; align-items: stretch; gap: 12px; }
  .auth-actions .auth-providers,
  .auth-actions .form-actions-primary { flex-direction: column; align-items: stretch; margin-left: 0; gap: 12px; }
  .auth-actions .btn-google,
  .auth-actions .form-actions-primary button[type="submit"] { width: 100%; }
  .auth-actions .form-actions-primary a.cancel { text-align: center; }
}

/* ---------- Google sign-in button (Google brand guidelines, light theme) ----------
   The whites/greys here are Google's mandated identity colors, not theme tokens,
   so they're intentionally hardcoded. Selectors are container-scoped so they beat
   the global `form button[type="submit"]` dark styling on the POST-form variant. */
.btn-google,
.form-actions .btn-google,
.auth-card .btn-google {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 40px; padding: 0 12px; margin: 0;
  background: #ffffff; color: #1f1f1f;
  border: 1px solid #747775; border-radius: 6px;
  font-family: 'Roboto', var(--font-sans); font-weight: 500; font-size: 14px;
  letter-spacing: 0.25px; text-decoration: none; cursor: pointer;
  transition: background var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.btn-google:hover,
.form-actions .btn-google:hover,
.auth-card .btn-google:hover {
  background: #f7f8f8; box-shadow: 0 1px 2px rgba(60, 64, 67, 0.20);
}
.btn-google svg { display: block; flex: none; }

/* ---------- Sign in via Google (allauth socialaccount/login.html) ---------- */
.auth-card {
  width: 100%; max-width: 440px; margin: 24px auto 0;
  background: var(--paper-raised); border: 1px solid var(--paper-edge);
  border-radius: 8px; padding: 40px; text-align: center; box-sizing: border-box;
}
.auth-card .auth-bridge {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin-bottom: 26px;
}
.auth-card .auth-bridge .auth-wordmark {
  font-family: var(--font-serif); font-weight: 500; font-size: 24px;
  letter-spacing: -0.01em; color: var(--ink);
}
.auth-card h1 {
  font-family: var(--font-serif); font-weight: 500; font-size: 30px;
  line-height: 1.15; letter-spacing: -0.01em; color: var(--ink-soft);
  margin: 0 0 14px;
}
.auth-card .auth-lede {
  font-family: var(--font-sans); font-size: 15px; line-height: 1.55;
  color: var(--ink-muted); margin: 0 0 30px;
}
/* Full-width 44px continue variant (overrides the inline base sizing above). */
.auth-card .btn-google { width: 100%; height: 44px; padding: 0 16px; }
.auth-card .auth-cancel {
  display: inline-block; margin-top: 20px;
  font-family: var(--font-sans); font-size: 14px; font-weight: 500;
  color: var(--ink-muted); text-decoration: none;
}
.auth-card .auth-cancel:hover { color: var(--ink); }

/* ---------- Warning / dedup blocks on capture forms ---------- */
.warning {
  background: rgba(255, 210, 0, 0.10);
  border: 1px solid rgba(255, 210, 0, 0.4);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 24px;
}
.warning p:first-child { margin-top: 0; }
.warning p:last-child { margin-bottom: 0; }
.warning ul { padding-left: 1.25rem; margin: 8px 0; }
.warning a { color: var(--ink); text-decoration-color: var(--highlight); }

/* ── Global lexical search box, in the nav (spec 0033, Direction A) ─────── */
.nav-search { position: relative; flex: 1; min-width: 0; display: flex; justify-content: center; padding: 0 22px; }
.search-field { position: relative; display: flex; align-items: center; gap: 9px; width: 100%; max-width: 360px;
  background: var(--paper-raised); border: 1px solid var(--paper-edge); border-radius: 9px; padding: 7px 10px 7px 12px;
  cursor: text; transition: max-width 200ms cubic-bezier(.2,.7,.3,1), border-color 120ms ease, box-shadow 120ms ease; }
.search-field:hover { border-color: var(--ink-ghost); }
.nav-search.is-open .search-field { max-width: 600px; border-color: var(--ink-ghost); box-shadow: 0 0 0 4px var(--highlight-faint); }
.search-lead { color: var(--ink-faint); flex: none; display: inline-flex; transition: color 120ms ease; }
.nav-search.is-open .search-lead { color: var(--ink-muted); }
.search-input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font-family: var(--font-sans); font-size: 14px; line-height: 1.45; color: var(--ink); padding: 1px 0; }
.search-input::placeholder { color: var(--ink-faint); }
.search-kbd { flex: none; font-family: var(--font-sans); font-size: 11px; font-weight: 500; color: var(--ink-faint);
  border: 1px solid var(--paper-edge); border-radius: 5px; padding: 0 6px; line-height: 18px; min-width: 18px;
  text-align: center; background: var(--paper-sunken); }
.nav-search.is-open .search-kbd, .nav-search.has-text .search-kbd { display: none; }
.search-clear { display: none; flex: none; width: 22px; height: 22px; border-radius: 5px; border: 0; background: none;
  cursor: pointer; color: var(--ink-faint); align-items: center; justify-content: center; transition: background 120ms ease; }
.search-clear:hover { background: var(--paper-sunken); color: var(--ink-muted); }
.nav-search.has-text .search-clear { display: inline-flex; }

.search-panel { position: absolute; top: calc(100% + 9px); left: 50%; transform: translateX(-50%); z-index: 60;
  width: 600px; max-width: calc(100vw - 48px); max-height: min(74vh, 612px); overflow-y: auto;
  background: var(--paper-raised); border: 1px solid var(--paper-edge); border-radius: 13px;
  box-shadow: 0 16px 40px rgba(26,22,18,0.11), 0 3px 10px rgba(26,22,18,0.05); padding: 7px; }
.search-panel[hidden] { display: none; }

.search-panel .ask { display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: 9px;
  background: var(--highlight-wash); border: 1px solid rgba(202,168,58,0.4); text-decoration: none; }
.search-panel .ask .aico { color: #9a7d12; flex: none; display: inline-flex; }
.search-panel .ask .abody { flex: 1; min-width: 0; }
.search-panel .ask .aline { display: block; font-family: var(--font-sans); font-size: 14px; color: var(--ink-soft); }
.search-panel .ask .aline b { font-weight: 600; color: var(--ink); }
.search-panel .ask .asub { display: block; font-family: var(--font-sans); font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; }
.search-panel .ask .akbd kbd { font-family: var(--font-sans); font-size: 11px; border: 1px solid rgba(154,125,18,0.3);
  border-radius: 5px; background: var(--paper-raised); padding: 0 6px; line-height: 18px; color: #9a7d12; }

.search-panel .sec { padding: 4px 2px; }
.search-panel .ask + .sec, .search-panel .sec + .sec { border-top: 1px solid var(--paper-edge); margin-top: 5px; padding-top: 8px; }
.search-panel .shead { display: flex; align-items: baseline; gap: 8px; padding: 4px 10px 6px; }
.search-panel .slabel { font-family: var(--font-sans); font-size: 10.5px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-faint); }
.search-panel .scount { font-family: var(--font-sans); font-size: 11px; color: var(--ink-ghost); }

.search-panel .row { display: flex; gap: 11px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; text-decoration: none; }
.search-panel .row:hover, .search-panel .row.hi { background: var(--highlight-faint); }
.search-panel .ico { flex: none; width: 22px; color: var(--ink-muted); display: inline-flex; align-items: center; justify-content: center; margin-top: 1px; }
.search-panel .main { min-width: 0; flex: 1; }
.search-panel .trow { display: flex; align-items: center; gap: 8px; min-width: 0; }
.search-panel .title { font-family: var(--font-sans); font-weight: 500; font-size: 14px; line-height: 1.3; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-panel .snippet { font-family: var(--font-serif); font-size: 14px; line-height: 1.45; color: var(--ink-muted); margin: 2px 0 0; }
.search-panel .snippet mark, .search-panel .title mark { background: var(--highlight-wash); border-radius: 2px; padding: 0 1px; color: inherit; }
.search-panel .chip { flex: none; font-family: var(--font-sans); font-size: 9.5px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-muted); background: var(--paper-sunken); padding: 1px 6px; border-radius: 4px; }
.search-panel .chip.claim { color: #4a4a4a; background: #ececec; }
.search-panel .chip.highlight { color: #6a4f0f; background: rgba(255,210,0,0.2); }
.search-panel .chip.concept { color: #3f5c6b; background: rgba(63,92,107,0.1); }
.search-panel .quiet { display: flex; align-items: center; gap: 11px; padding: 10px; font-family: var(--font-sans);
  font-size: 13.5px; color: var(--ink-muted); }
.search-panel .thumb { flex: none; width: 110px; height: 110px; border: 1px solid var(--paper-edge);
  border-radius: 3px; overflow: hidden; background: var(--paper-sunken); }
.search-panel .thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
/* Image rows: larger thumbnail, title centered against it, allowed to wrap. */
.search-panel .row.image { align-items: center; }
.search-panel .row.image .title { white-space: normal; }

/* ── Responsive header (spec 0033): collapse to hamburger + full-width search ──
   Below 760px the inline links and Sign out hide; the hamburger reveals them in
   .nav-menu, and the search box fills the bar with its results as a pinned
   full-width sheet (not a field-centered popover). Placed last so these rules
   win on source order — media queries don't add specificity. */
@media (max-width: 760px) {
  .nav { padding: 12px 14px; gap: 8px; }
  /* Only the authenticated app nav collapses — the signed-out nav (Memex /
     Sign in) has no hamburger, so its link + Sign in must stay visible. */
  .nav-app > a.link { display: none; }
  .nav-app > .signout { display: none; }
  .nav-app .nav-hamburger { display: inline-flex; }
  .nav-app.menu-open .nav-menu { display: block; }

  .nav-search { padding: 0; }
  .nav-search .search-field,
  .nav-search.is-open .search-field { max-width: none; }

  /* Results become a full-width sheet pinned under the bar with equal gutters
     — not centered on the (right-shifted) field. --nav-h is set by nav_menu.js. */
  .search-panel {
    position: fixed;
    top: var(--nav-h, 61px);
    left: 10px; right: 10px;
    width: auto; max-width: none;
    transform: none;
    max-height: calc(100vh - var(--nav-h, 61px) - 16px);
  }

  /* Mobile browsers (iOS Safari especially) auto-zoom the viewport when a
     focused field's font-size is under 16px — which shoved the search results
     off the left edge. Render text-entry fields at exactly 16px on mobile to
     remove the zoom trigger; the deliberate 14px desktop sizing is untouched. */
  .search-input,
  input[type="text"], input[type="search"], input[type="url"],
  input[type="email"], input[type="password"], input[type="tel"],
  input[type="number"], textarea, select {
    font-size: 16px;
  }
}
