/* 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&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 {
  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 { 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; }

/* ---------- 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;
}

/* ---------- 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);
}
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; }

/* ---------- 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);
  }
}
