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

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

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