@import url('/fonts/fonts.css');

/* ─────────────────────────────────────────────────────────────────────────
   Hearth design tokens. Transcribed from the design system's token files
   (colors / typography / spacing / radius / shadows / motion) — values are
   verbatim, so a change upstream is a one-for-one edit here.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Paper — warm neutral surfaces, lightest to deepest */
  --paper-0: #FFFCF8;
  --paper-1: #FBF6EE;
  --paper-2: #F4EBDE;
  --paper-3: #EADCC9;
  --paper-4: #DFCCB4;

  /* Ink — warm brown-black text ramp */
  --ink-1: #33261F;
  --ink-2: #5C4A40;
  --ink-3: #8A776B;
  --ink-4: #B8A697;

  --line-1: #EDE0CE;
  --line-2: #E0CDB4;
  --line-3: #CDB596;

  /* Clay (primary accent — terracotta) */
  --clay-100: #FAE6DA;
  --clay-200: #F0C8B1;
  --clay-400: #D98A5E;
  --clay-500: #C4643C;
  --clay-600: #A8502D;
  --clay-700: #843D21;

  --honey-100: #FBEED4;
  --honey-300: #EFC981;
  --honey-500: #D69A3C;
  --honey-600: #B37A26;

  --sage-100: #EBEEDB;
  --sage-300: #B9C28C;
  --sage-500: #7E8A52;
  --sage-600: #65713D;

  --berry-100: #F8E2E6;
  --berry-300: #DFA5B0;
  --berry-500: #B4586B;
  --berry-600: #943F55;

  --sky-100: #E5EEF1;
  --sky-300: #A9C4CF;
  --sky-500: #6E93A6;
  --sky-600: #55788A;

  --surface-page: var(--paper-1);
  --surface-card: var(--paper-0);
  --surface-sunken: var(--paper-2);

  --text-heading: var(--ink-1);
  --text-body: var(--ink-2);
  --text-muted: var(--ink-3);
  --text-faint: var(--ink-4);
  --text-accent: var(--clay-600);
  --text-link: var(--clay-600);
  --text-link-hover: var(--clay-700);

  --border-soft: var(--line-1);
  --border-default: var(--line-2);
  --border-strong: var(--line-3);

  --accent: var(--clay-500);
  --accent-hover: var(--clay-600);
  --accent-press: var(--clay-700);
  --accent-soft: var(--clay-100);
  --accent-on: #FFF8F2;

  --success: var(--sage-500);
  --success-soft: var(--sage-100);
  --warning: var(--honey-500);
  --warning-soft: var(--honey-100);
  --danger: var(--berry-500);
  --danger-soft: var(--berry-100);
  --info: var(--sky-500);
  --info-soft: var(--sky-100);

  --focus-ring: color-mix(in oklab, var(--clay-500) 45%, transparent);
  --overlay: color-mix(in oklab, var(--ink-1) 45%, transparent);

  /* Type */
  --font-display: 'Quicksand', 'Trebuchet MS', system-ui, sans-serif;
  --font-text: 'Nunito Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Space Mono', 'SFMono-Regular', Menlo, monospace;

  --fs-11: 0.6875rem;
  --fs-12: 0.75rem;
  --fs-14: 0.875rem;
  --fs-16: 1rem;
  --fs-18: 1.125rem;
  --fs-20: 1.25rem;
  --fs-24: 1.5rem;
  --fs-30: 1.875rem;
  --fs-38: 2.375rem;

  --lh-tight: 1.12;
  --lh-snug: 1.28;
  --lh-normal: 1.5;
  --lh-relaxed: 1.65;

  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  --ls-display: -0.015em;
  --ls-label: 0.01em;
  --ls-caps: 0.08em;

  --type-h1: var(--fw-bold) var(--fs-38)/var(--lh-tight) var(--font-display);
  --type-h2: var(--fw-semibold) var(--fs-30)/var(--lh-snug) var(--font-display);
  --type-h3: var(--fw-semibold) var(--fs-20)/var(--lh-snug) var(--font-display);
  --type-body-lg: var(--fw-regular) var(--fs-18)/var(--lh-relaxed) var(--font-text);
  --type-body: var(--fw-regular) var(--fs-16)/var(--lh-normal) var(--font-text);
  --type-small: var(--fw-regular) var(--fs-14)/var(--lh-normal) var(--font-text);
  --type-label: var(--fw-semibold) var(--fs-14)/1.2 var(--font-text);
  --type-caption: var(--fw-regular) var(--fs-12)/1.35 var(--font-text);

  /* Spacing */
  --sp-1: 2px;  --sp-2: 4px;  --sp-3: 8px;  --sp-4: 12px;
  --sp-5: 16px; --sp-6: 20px; --sp-7: 24px; --sp-8: 32px;
  --sp-9: 40px; --sp-10: 56px; --sp-11: 72px; --sp-12: 96px;

  --field-pad-x: var(--sp-5);
  --control-h-sm: 34px;
  --control-h-md: 44px;
  --control-h-lg: 54px;
  --measure: 66ch;

  /* Radius */
  --r-xs: 6px;  --r-sm: 10px; --r-md: 14px; --r-lg: 20px;
  --r-xl: 28px; --r-2xl: 36px; --r-pill: 999px;
  --r-card: var(--r-lg);
  --r-control: var(--r-pill);
  --r-field: var(--r-md);
  --border-w: 1.5px;
  --border-w-strong: 2px;

  /* Shadows — brown-tinted and diffuse, never pure black */
  --shadow-sm: 0 1px 2px rgba(51, 38, 31, .05), 0 2px 8px rgba(51, 38, 31, .05);
  --shadow-md: 0 2px 4px rgba(51, 38, 31, .05), 0 8px 20px rgba(51, 38, 31, .07);
  --shadow-lg: 0 4px 8px rgba(51, 38, 31, .05), 0 18px 40px rgba(51, 38, 31, .10);
  --shadow-pop: 0 10px 30px rgba(51, 38, 31, .14), 0 2px 6px rgba(51, 38, 31, .06);
  --shadow-inset: inset 0 1px 2px rgba(51, 38, 31, .06);
  --shadow-press: 0 1px 1px rgba(51, 38, 31, .06);
  --ring: 0 0 0 3px var(--focus-ring);

  /* Motion */
  --dur-1: 120ms; --dur-2: 180ms; --dur-3: 240ms; --dur-4: 320ms;
  --ease-out: cubic-bezier(.22, .68, .32, 1);
  --ease-soft-spring: cubic-bezier(.34, 1.42, .64, 1);
  --t-hover: all var(--dur-2) var(--ease-out);
  --t-enter: opacity var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-soft-spring);

  /* iOS safe areas — 0 everywhere else */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-1: 1ms; --dur-2: 1ms; --dur-3: 1ms; --dur-4: 1ms; }
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/*
 * Hearth's muted ramp is deliberately soft: --text-muted lands at 3.96:1 on
 * paper, which clears WCAG AA for UI and large text but not for the 12px
 * captions it is used on. Rather than repaint the brand for everyone, darken
 * the ramp one step for readers who have asked their OS for more contrast.
 * Every value below is still a colour from the design system's own scale.
 */
@media (prefers-contrast: more) {
  :root {
    --text-muted: var(--ink-2);   /* 7.78:1 */
    --text-faint: var(--ink-3);   /* 3.96:1, from 2.30:1 */
    --border-soft: var(--line-2);
    --border-default: var(--line-3);
    --accent-on: #FFFFFF;
  }
}

/* ── Base ─────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html {
  /* 100dvh is what keeps the layout honest while Safari's toolbars move. */
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--surface-page);
  color: var(--text-body);
  font: var(--type-body);
  -webkit-font-smoothing: antialiased;
  text-wrap: pretty;
  /* Stops the whole page rubber-banding under the fixed nav on iOS. */
  overscroll-behavior-y: none;
}

h1, h2, h3 { color: var(--text-heading); margin: 0; text-wrap: balance; }
h1 { font: var(--type-h1); letter-spacing: var(--ls-display); }
h2 { font: var(--type-h2); letter-spacing: var(--ls-display); }
h3 { font: var(--type-h3); letter-spacing: var(--ls-display); }
p { margin: 0; }

a { color: var(--text-link); text-decoration: none; transition: var(--t-hover); }
a:hover { color: var(--text-link-hover); }

button, input, textarea, select { font: inherit; color: inherit; }
::selection { background: var(--clay-200); color: var(--ink-1); }

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-sm);
}

/* Never let a tap flash a blue box on iOS; we style :active ourselves. */
* { -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ── Type helpers ─────────────────────────────────────────────────────── */

.caps {
  font: var(--type-caption);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.muted { color: var(--text-muted); }
.small { font: var(--type-small); }
.caption { font: var(--type-caption); color: var(--text-muted); }
.quote { font: var(--type-small); color: var(--text-body); font-style: italic; }
.mono { font-family: var(--font-mono); }

.wordmark {
  font: var(--fw-bold) var(--fs-24)/1 var(--font-display);
  letter-spacing: var(--ls-display);
  color: var(--text-heading);
}
.wordmark .dot { color: var(--accent); }

/* ── Button ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  height: var(--control-h-md);
  padding: 0 var(--sp-7);
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: var(--fs-16);
  letter-spacing: var(--ls-label);
  border-radius: var(--r-control);
  border: var(--border-w) solid transparent;
  background: var(--accent);
  color: var(--accent-on);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--t-hover);
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.985); box-shadow: var(--shadow-press); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--sm { height: var(--control-h-sm); padding: 0 var(--sp-5); font-size: var(--fs-14); }
.btn--lg { height: var(--control-h-lg); padding: 0 var(--sp-8); font-size: var(--fs-18); }
.btn--block { width: 100%; }

.btn--secondary {
  background: var(--surface-card);
  color: var(--text-heading);
  border-color: var(--border-default);
}
.btn--secondary:hover:not(:disabled) { background: var(--paper-2); }

.btn--ghost {
  background: transparent;
  color: var(--text-accent);
  box-shadow: none;
}
.btn--ghost:hover:not(:disabled) { background: var(--accent-soft); }

.btn--soft {
  background: var(--accent-soft);
  color: var(--clay-700);
  box-shadow: none;
}
.btn--soft:hover:not(:disabled) { background: var(--clay-200); }

.btn--danger { background: var(--danger); color: var(--accent-on); }
.btn--danger:hover:not(:disabled) { background: var(--berry-600); }

/* ── Icon button ──────────────────────────────────────────────────────── */

.icon-btn {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  border-radius: var(--r-pill);
  border: var(--border-w) solid transparent;
  background: transparent;
  color: var(--text-body);
  cursor: pointer;
  transition: var(--t-hover);
}
.icon-btn:hover:not(:disabled) { background: var(--paper-2); }
.icon-btn:active:not(:disabled) { transform: scale(.93); }
.icon-btn--sm { width: 34px; height: 34px; }
.icon-btn--outline { background: var(--surface-card); border-color: var(--border-default); }
.icon-btn--soft { background: var(--accent-soft); color: var(--clay-700); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Badge ────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: var(--sp-3);
  padding: 3px var(--sp-4);
  border-radius: var(--r-pill);
  white-space: nowrap; flex: 0 0 auto;
  font: var(--type-caption);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-label);
  background: var(--paper-2); color: var(--ink-2);
  border: var(--border-w) solid var(--line-2);
}
.badge .dot { width: 6px; height: 6px; border-radius: var(--r-pill); background: currentColor; }
.badge--success { background: var(--success-soft); color: var(--sage-600); border-color: var(--sage-300); }
.badge--warning { background: var(--warning-soft); color: var(--honey-600); border-color: var(--honey-300); }
.badge--danger  { background: var(--danger-soft);  color: var(--berry-600); border-color: var(--berry-300); }
.badge--info    { background: var(--info-soft);    color: var(--sky-600);   border-color: var(--sky-300); }

/* ── Tag / chip ───────────────────────────────────────────────────────── */

.tag {
  display: inline-flex; align-items: center; gap: var(--sp-3);
  height: 30px; padding: 0 var(--sp-4);
  border-radius: var(--r-pill);
  font: var(--type-small); font-weight: var(--fw-semibold);
  background: var(--surface-card); color: var(--text-body);
  border: var(--border-w) solid var(--border-default);
  cursor: pointer; transition: var(--t-hover);
}
.tag:hover { background: var(--paper-2); }
.tag--on { background: var(--accent); color: var(--accent-on); border-color: var(--accent); }
.tag--soft { background: var(--accent-soft); color: var(--clay-700); border-color: var(--clay-200); }
.tag--soft:hover { background: var(--clay-200); }
.tag__x { display: inline-flex; opacity: .6; font-size: var(--fs-14); line-height: 1; }
.tag__x:hover { opacity: 1; }

.tag--dashed {
  background: transparent;
  border: var(--border-w-strong) dashed var(--line-3);
  color: var(--text-muted);
}
.tag--dashed:hover { background: var(--paper-2); color: var(--text-body); }

/* Larger chip used for the context list on the capture screen */
.chip {
  display: inline-flex; align-items: center; gap: var(--sp-3);
  height: 34px; padding: 0 var(--sp-5);
  border-radius: var(--r-pill);
  background: var(--surface-card);
  border: var(--border-w) solid var(--border-default);
  font: var(--type-small); font-weight: var(--fw-semibold);
  color: var(--text-heading);
  cursor: pointer; transition: var(--t-hover);
}
.chip:hover { background: var(--paper-2); }
.chip__count { font: var(--fw-bold) var(--fs-12)/1 var(--font-display); color: var(--text-muted); }
.chip--accent { background: var(--accent-soft); border-color: var(--clay-200); color: var(--clay-700); }
.chip--accent .chip__count { color: inherit; }

/* ── Field / input ────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: var(--sp-3); }
.field__label { font: var(--type-label); color: var(--text-heading); }
.field__hint { font: var(--type-caption); color: var(--text-muted); }
.field__error { font: var(--type-caption); color: var(--danger); }

.input-shell {
  display: flex; align-items: center; gap: var(--sp-3);
  height: var(--control-h-md);
  padding: 0 var(--field-pad-x);
  border-radius: var(--r-field);
  background: var(--surface-card);
  border: var(--border-w) solid var(--border-default);
  box-shadow: var(--shadow-inset);
  transition: var(--t-hover);
}
.input-shell--sm { height: var(--control-h-sm); }
.input-shell--lg { height: var(--control-h-lg); }
.input-shell:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.input-shell--error { border-color: var(--danger); }
.input-shell__icon { color: var(--text-muted); display: inline-flex; flex: 0 0 auto; }

.input-shell input,
.input-shell select {
  flex: 1; min-width: 0;
  border: 0; outline: none; background: transparent;
  /* 16px minimum, or iOS Safari zooms the viewport on focus. */
  font: var(--type-body);
  color: var(--text-heading);
}
.input-shell input::placeholder { color: var(--text-faint); }
/* Where a wrapper draws the focus ring on :focus-within, the control inside
   must not draw the global one too, or you get two concentric rings. */
.input-shell input:focus-visible,
.input-shell select:focus-visible,
.capture-box textarea:focus-visible { box-shadow: none; }
.input-shell select { appearance: none; cursor: pointer; }

.select-shell { position: relative; display: flex; align-items: center; }
.select-shell .input-shell { width: 100%; padding-right: var(--sp-9); }
.select-shell__caret {
  position: absolute; right: var(--field-pad-x);
  pointer-events: none; color: var(--text-muted); display: inline-flex;
}

textarea.textarea {
  width: 100%;
  border-radius: var(--r-field);
  background: var(--surface-card);
  border: var(--border-w) solid var(--border-default);
  box-shadow: var(--shadow-inset);
  padding: var(--sp-5);
  font: var(--type-body);
  color: var(--text-heading);
  resize: vertical;
  outline: none;
  transition: var(--t-hover);
}
textarea.textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }

/* ── Switch ───────────────────────────────────────────────────────────── */

.switch { display: inline-flex; align-items: center; gap: var(--sp-4); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 46px; height: 28px; flex: 0 0 auto; padding: 2px;
  display: flex; align-items: center;
  border-radius: var(--r-pill);
  background: var(--paper-3);
  border: var(--border-w) solid var(--border-strong);
  box-shadow: var(--shadow-inset);
  transition: var(--t-hover);
}
.switch__thumb {
  width: 20px; height: 20px; border-radius: var(--r-pill);
  background: var(--paper-0); box-shadow: var(--shadow-sm);
  transition: transform var(--dur-2) var(--ease-soft-spring);
}
.switch input:checked + .switch__track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--ring); }

/* ── Radio ────────────────────────────────────────────────────────────── */

.radio { display: flex; gap: var(--sp-4); align-items: flex-start; cursor: pointer; }
.radio input { position: absolute; opacity: 0; width: 0; height: 0; }
.radio__mark {
  width: 22px; height: 22px; flex: 0 0 auto; margin-top: 1px;
  border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-card);
  border: var(--border-w) solid var(--border-strong);
  box-shadow: var(--shadow-inset);
  transition: var(--t-hover);
}
.radio__mark::after {
  content: ''; width: 11px; height: 11px; border-radius: var(--r-pill);
  background: var(--accent); transform: scale(0);
  transition: transform var(--dur-2) var(--ease-soft-spring);
}
.radio input:checked + .radio__mark { border-color: var(--accent); box-shadow: none; }
.radio input:checked + .radio__mark::after { transform: scale(1); }
.radio input:focus-visible + .radio__mark { box-shadow: var(--ring); }
.radio__text { display: flex; flex-direction: column; gap: 2px; }
.radio__label { font: var(--type-body); color: var(--text-heading); }
.radio__desc { font: var(--type-caption); color: var(--text-muted); }

/* ── Tabs ─────────────────────────────────────────────────────────────── */

.tabs {
  display: inline-flex; gap: var(--sp-2); padding: var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: var(--sp-3);
  height: 36px; padding: 0 var(--sp-6);
  border: none; border-radius: var(--r-pill);
  background: transparent;
  font-family: var(--font-display); font-weight: var(--fw-bold); font-size: var(--fs-14);
  color: var(--text-muted);
  cursor: pointer; white-space: nowrap;
  transition: var(--t-hover);
}
.tab--on { background: var(--surface-card); color: var(--text-heading); box-shadow: var(--shadow-sm); }
.tab__count { font: var(--type-caption); color: var(--text-muted); }

/* ── Card ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface-card);
  border: var(--border-w) solid var(--border-soft);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
  display: flex; flex-direction: column; gap: var(--sp-4);
}
.card--warning { border-color: var(--honey-300); }
.card--tap { cursor: pointer; transition: var(--t-hover); text-align: left; width: 100%; }
.card--tap:hover { box-shadow: var(--shadow-md); border-color: var(--border-default); }
.card--tap:active { transform: scale(.99); }

.dashed {
  border: var(--border-w-strong) dashed var(--line-3);
  border-radius: var(--r-card);
  padding: var(--sp-5);
  text-align: center;
  font: var(--type-small);
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  width: 100%;
  transition: var(--t-hover);
}
.dashed:hover { background: var(--paper-2); color: var(--text-body); }
.dashed--field { border-radius: var(--r-field); padding: var(--sp-4); }

.rule { height: var(--border-w); background: var(--border-soft); border: 0; margin: 0; }

/* ── Avatar ───────────────────────────────────────────────────────────── */

.avatar {
  width: 42px; height: 42px; flex: 0 0 auto;
  border-radius: var(--r-pill);
  font: var(--fw-bold) var(--fs-18)/42px var(--font-display);
  text-align: center;
  background: var(--accent-soft); color: var(--clay-700);
}
.avatar--sm { width: 34px; height: 34px; font-size: var(--fs-14); line-height: 34px; }
/* Deterministic per-record tint so the same person keeps the same colour. */
.avatar--t1 { background: var(--accent-soft); color: var(--clay-700); }
.avatar--t2 { background: var(--sky-100); color: var(--sky-600); }
.avatar--t3 { background: var(--sage-100); color: var(--sage-600); }
.avatar--t4 { background: var(--honey-100); color: var(--honey-600); }
.avatar--t5 { background: var(--berry-100); color: var(--berry-600); }

/* ── Count pill (the inbox badge) ─────────────────────────────────────── */

.count-pill {
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-on);
  font: var(--fw-bold) var(--fs-11)/20px var(--font-display);
  text-align: center;
}

/* ── Highlight for search hits ────────────────────────────────────────── */

mark {
  background: var(--accent-soft);
  color: var(--clay-700);
  border-radius: 4px;
  padding: 0 3px;
}

/* ── App shell ────────────────────────────────────────────────────────── */

#app { min-height: 100dvh; }

.shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding: var(--sp-4) var(--sp-6) var(--sp-8);
  padding-top: calc(var(--sp-4) + var(--safe-top));
  padding-left: calc(var(--sp-6) + var(--safe-left));
  padding-right: calc(var(--sp-6) + var(--safe-right));
  /* Clears the fixed bottom nav plus the home indicator. */
  padding-bottom: calc(var(--sp-8) + 76px + var(--safe-bottom));
  animation: view-in var(--dur-3) var(--ease-out);
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.view__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4);
  padding-bottom: var(--sp-2);
}
.view__title { display: flex; flex-direction: column; gap: var(--sp-2); }

.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack--lg { gap: var(--sp-6); }
.stack--sm { gap: var(--sp-3); }
.row { display: flex; align-items: center; gap: var(--sp-4); }
.row--wrap { flex-wrap: wrap; gap: var(--sp-3); }
.row--between { justify-content: space-between; }
.row--baseline { align-items: baseline; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

/* ── Bottom navigation (phone) ────────────────────────────────────────── */

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: flex; align-items: stretch; justify-content: space-around;
  padding: var(--sp-4) var(--sp-6);
  padding-bottom: calc(var(--sp-4) + var(--safe-bottom));
  background: var(--paper-0);
  border-top: var(--border-w) solid var(--border-soft);
}
.tabbar__item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  flex: 1;
  padding: var(--sp-2) 0;
  border: 0; background: transparent;
  color: var(--text-muted);
  font: var(--type-caption); font-weight: var(--fw-semibold);
  cursor: pointer;
  position: relative;
  transition: color var(--dur-2) var(--ease-out);
}
.tabbar__item--on { color: var(--accent); font-weight: var(--fw-bold); }
.tabbar__badge { position: absolute; top: 0; right: 22%; }

/* ── Sidebar (desktop) ────────────────────────────────────────────────── */

.sidebar { display: none; }

.nav-item {
  display: flex; align-items: center; gap: var(--sp-4);
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border: var(--border-w) solid transparent;
  border-radius: var(--r-field);
  background: transparent;
  font: var(--type-label); color: var(--text-body);
  cursor: pointer; text-align: left;
  transition: var(--t-hover);
}
.nav-item:hover { background: var(--paper-1); }
.nav-item--on {
  background: var(--surface-card);
  border-color: var(--border-soft);
  box-shadow: var(--shadow-sm);
  color: var(--text-heading);
}
.nav-item__count { margin-left: auto; font: var(--type-caption); color: var(--text-muted); }
.nav-item__count--accent { color: var(--text-accent); font-weight: var(--fw-bold); }

/* ── Sheet (share, pickers) ───────────────────────────────────────────── */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in var(--dur-2) var(--ease-out);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 92dvh; overflow-y: auto;
  background: var(--surface-card);
  border-top: var(--border-w) solid var(--border-soft);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  padding: var(--sp-8) var(--sp-7);
  padding-bottom: calc(var(--sp-9) + var(--safe-bottom));
  display: flex; flex-direction: column; gap: var(--sp-6);
  animation: sheet-up var(--dur-3) var(--ease-out);
}
@keyframes sheet-up { from { transform: translateY(12%); opacity: .4; } to { transform: none; opacity: 1; } }

.sheet__grip {
  width: 44px; height: 5px; border-radius: var(--r-pill);
  background: var(--border-strong); align-self: center; flex: 0 0 auto;
}

/* ── Toast ────────────────────────────────────────────────────────────── */

.toasts {
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: var(--sp-3);
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  border-radius: var(--r-pill);
  background: var(--ink-1); color: var(--paper-1);
  box-shadow: var(--shadow-pop);
  font: var(--type-small); font-weight: var(--fw-semibold);
  pointer-events: auto;
  animation: var(--t-enter);
  animation-name: toast-in;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
.toast--error { background: var(--berry-600); }
.toast--leaving { opacity: 0; transform: translateY(6px); transition: var(--t-hover); }

/* ── Capture screen ───────────────────────────────────────────────────── */

.capture-box {
  background: var(--surface-card);
  border: var(--border-w) solid var(--border-default);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-inset);
  padding: var(--sp-6);
  min-height: 168px;
  display: flex; flex-direction: column; gap: var(--sp-4);
  transition: var(--t-hover);
}
.capture-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.capture-box textarea {
  flex: 1; width: 100%; min-height: 120px;
  border: 0; outline: none; background: transparent; resize: none;
  font: var(--type-body); color: var(--text-heading);
  text-wrap: pretty;
}
.capture-box textarea::placeholder { color: var(--text-faint); }

.capture-thumbs { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.capture-thumb {
  position: relative; width: 64px; height: 64px;
  border-radius: var(--r-sm); overflow: hidden;
  border: var(--border-w) solid var(--border-soft);
}
.capture-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.capture-thumb button {
  position: absolute; top: 2px; right: 2px;
  width: 22px; height: 22px; border-radius: var(--r-pill);
  border: 0; background: var(--overlay); color: var(--paper-0);
  display: grid; place-items: center; cursor: pointer;
}

/* ── Record detail ────────────────────────────────────────────────────── */

.field-row { display: flex; flex-direction: column; gap: var(--sp-3); }
.field-row__value {
  font: var(--type-body); color: var(--text-heading);
  white-space: pre-wrap; word-break: break-word;
  min-height: 24px;
  cursor: text;
}
.field-row__value:empty::before { content: 'Empty'; color: var(--text-faint); }
.field-row__edit {
  width: 100%; min-height: 72px;
  border-radius: var(--r-field);
  background: var(--surface-card);
  border: var(--border-w) solid var(--accent);
  box-shadow: var(--ring);
  padding: var(--sp-4) var(--field-pad-x);
  font: var(--type-body); color: var(--text-heading);
  outline: none; resize: vertical;
}

.timeline { display: flex; flex-direction: column; gap: var(--sp-4); }
.timeline__row { display: flex; gap: var(--sp-5); }
.timeline__when {
  width: 62px; flex: 0 0 auto; padding-top: 2px;
  font: var(--type-caption); font-family: var(--font-mono); color: var(--text-muted);
}

/* ── Empty states ─────────────────────────────────────────────────────── */

.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-4);
  padding: var(--sp-10) var(--sp-6);
  text-align: center;
  color: var(--text-muted);
}
.empty__icon { color: var(--text-faint); }
.empty h3 { color: var(--text-body); }

/* ── Login ────────────────────────────────────────────────────────────── */

.login {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--sp-8) var(--sp-6);
  padding-top: calc(var(--sp-8) + var(--safe-top));
  padding-bottom: calc(var(--sp-8) + var(--safe-bottom));
}
.login__card {
  width: min(420px, 100%);
  display: flex; flex-direction: column; gap: var(--sp-6);
}
.login__code input {
  font-family: var(--font-mono);
  font-size: var(--fs-24);
  font-weight: var(--fw-bold);
  letter-spacing: 0.28em;
  text-align: center;
}

/* ── Offline banner ───────────────────────────────────────────────────── */

.offline-bar {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  background: var(--honey-100);
  border-bottom: var(--border-w) solid var(--honey-300);
  color: var(--honey-600);
  font: var(--type-caption); font-weight: var(--fw-bold);
  padding-top: calc(var(--sp-3) + var(--safe-top));
}

/* ── Skeleton ─────────────────────────────────────────────────────────── */

.skeleton {
  border-radius: var(--r-card);
  background: linear-gradient(90deg, var(--paper-2) 25%, var(--paper-1) 50%, var(--paper-2) 75%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  height: 92px;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ── Spinner ──────────────────────────────────────────────────────────── */

.spin { animation: spin 900ms linear infinite; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────────────────────────────────────
   Desktop. Same data, more room: contexts on the left, list in the middle,
   the open record on the right.
   ───────────────────────────────────────────────────────────────────────── */

@media (min-width: 900px) {
  .shell { flex-direction: row; height: 100dvh; overflow: hidden; }

  .tabbar { display: none; }

  .sidebar {
    display: flex; flex-direction: column; gap: var(--sp-7);
    width: 236px; flex: 0 0 auto;
    padding: var(--sp-7) var(--sp-5);
    padding-left: calc(var(--sp-5) + var(--safe-left));
    background: var(--paper-2);
    border-right: var(--border-w) solid var(--border-soft);
    overflow-y: auto;
  }
  .sidebar .wordmark { font-size: var(--fs-20); padding: 0 var(--sp-3); }

  .view {
    padding: var(--sp-8) var(--sp-9);
    padding-bottom: var(--sp-9);
    overflow-y: auto;
    max-width: none;
  }

  /* Two-pane: record list beside the open record. */
  .panes { display: flex; flex: 1; min-height: 0; overflow: hidden; }
  .pane-list {
    width: 340px; flex: 0 0 auto;
    border-right: var(--border-w) solid var(--border-soft);
    padding: var(--sp-7) var(--sp-6);
    display: flex; flex-direction: column; gap: var(--sp-5);
    overflow-y: auto;
  }
  .pane-detail {
    flex: 1; min-width: 0; overflow-y: auto;
    padding: var(--sp-8) var(--sp-9);
    display: flex; flex-direction: column; gap: var(--sp-7);
  }

  .list-row {
    display: flex; flex-direction: column; gap: 2px;
    width: 100%; text-align: left;
    padding: var(--sp-4) var(--sp-5);
    border: var(--border-w) solid transparent;
    border-radius: var(--r-field);
    background: transparent; cursor: pointer;
    transition: var(--t-hover);
  }
  .list-row:hover { background: var(--paper-2); }
  .list-row--on {
    background: var(--surface-card);
    border-color: var(--clay-200);
    box-shadow: var(--shadow-sm);
  }
  .list-row__title { font: var(--type-label); color: var(--text-heading); }

  /* The 340px list pane is too narrow to scroll a tab strip comfortably with a
     mouse, so tabs wrap onto a second row instead of running off the edge. */
  .pane-list .tabs { flex-wrap: wrap; overflow-x: visible; border-radius: var(--r-lg); }

  .fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); }
  .inbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-6); }
  .inbox-grid .card { height: 100%; }
  .inbox-grid .card__actions { margin-top: auto; }

  .capture-row { display: flex; gap: var(--sp-5); align-items: flex-start; }
  .capture-row .capture-box { flex: 1; min-height: 96px; }
  .capture-row .capture-box textarea { min-height: 56px; }

  .timeline__when { width: 72px; }
  .toasts { bottom: var(--sp-8); left: auto; right: var(--sp-8); transform: none; }
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, calc(100vw - 64px));
    border-radius: var(--r-xl);
    border: var(--border-w) solid var(--border-soft);
    animation: sheet-pop var(--dur-3) var(--ease-out);
    padding-bottom: var(--sp-8);
  }
  @keyframes sheet-pop {
    from { transform: translate(-50%, -48%) scale(.97); opacity: 0; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  }
  .sheet__grip { display: none; }
}

@media (min-width: 1280px) {
  .view--wide { max-width: 1140px; }
}
