/* Inter (SIL OFL 1.1, see /fonts/LICENSE-Inter.txt), self-hosted: CSP allows fonts from 'self'
   only, and the service worker precaches it. Latin subset, variable weight, 48 KB. */
@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-latin-wght-normal.woff2') format('woff2-variations'), url('/fonts/inter-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 900; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
:root {
  --bg: #0b0b14;
  --panel: #14141f;
  --panel-2: #1b1b2b;
  --border: #2a2a40;
  --text: #e8e8f2;
  --muted: #9a9ab0;
  /* 5.2:1 on panels, 4.8:1 on panel-2 (was #7c6cf6: 4.3:1 as tag text). */
  --accent: #8577f7;
  --accent-2: #4f46e5;
  --green: #34d399;
  --blue: #60a5fa;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 10px;
  --r-sm: 6px; /* controls, chips, stats: small corners, not pills */
  font-size: 16px;
  /* Native controls (checkboxes, date pickers, scrollbars) follow the palette too. */
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f4fa;
    --panel: #ffffff;
    --panel-2: #eeeef6;
    --border: #d8d8e8;
    --text: #17172a;
    --muted: #5c5c74;
    /* The accent set above is tuned for dark panels; on white it falls under
       WCAG AA at tag/pill sizes (context tag measured 2.2:1). Same hues,
       darkened until small text passes. */
    --accent: #5a45dd;
    --green: #056046;
    --blue: #1a5fc4;
    --amber: #8a5a00;
    --red: #b42828; /* 4.8:1 on its own restricted-chip tint (was #c62f2f: 4.1:1) */
  }
}
/* Manual theme override (topbar toggle; theme.js applies it pre-paint).
   Attribute selectors outrank both blocks above, so a choice always wins over
   the OS. KEEP THESE IN SYNC with the two palettes above. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4fa;
  --panel: #ffffff;
  --panel-2: #eeeef6;
  --border: #d8d8e8;
  --text: #17172a;
  --muted: #5c5c74;
  --accent: #5a45dd;
  --green: #056046;
  --blue: #1a5fc4;
  --amber: #8a5a00;
  --red: #b42828; /* 4.8:1 on its own restricted-chip tint (was #c62f2f: 4.1:1) */
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b14;
  --panel: #14141f;
  --panel-2: #1b1b2b;
  --border: #2a2a40;
  --text: #e8e8f2;
  --muted: #9a9ab0;
  --accent: #8577f7;
  --green: #34d399;
  --blue: #60a5fa;
  --amber: #fbbf24;
  --red: #f87171;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.011em;
  /* Without these, macOS draws light text on dark heavier and softer than it is. */
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-weight: 600; letter-spacing: -0.018em; }
b, strong { font-weight: 600; }
/* Counts line up. */
.stat b, .badge, .rv-progress, .dg-line b, td { font-variant-numeric: tabular-nums; }
/* Monochrome stroke icons (app.js ICON) — they replaced emoji in the app's chrome. */
.ico { width: 1em; height: 1em; vertical-align: -0.14em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Modal open: freeze the page behind it (scroll-chaining out of a dialog is
   disorienting, and on iOS it strands the user mid-document on close). */
body.modal-open { overflow: hidden; }

/* ---- keyboard focus: one visible ring for every interactive element ---- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Honour the OS "reduce motion" setting: keep state changes, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Skip link — first tab stop, visible only when focused. */
.skip-link {
  position: fixed; top: 6px; left: 6px; z-index: 200;
  transform: translateY(-160%);
  background: var(--accent-2); color: #fff; text-decoration: none;
  padding: 9px 14px; border-radius: 8px; font-size: .9rem; font-weight: 600;
}
.skip-link:focus { transform: translateY(0); }
button {
  font: inherit; color: inherit; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 8px 14px; font-weight: 500;
}
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.danger { color: var(--red); }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 9px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 110px; line-height: 1.45; }
label { font-size: .8rem; color: var(--muted); display: block; margin: 12px 0 4px; }
/* The native file picker, dressed as the app's primary button (it's the section's one action). */
input[type="file"] { padding: 6px; color: var(--muted); cursor: pointer; }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 550; color: #fff; cursor: pointer;
  background: var(--accent-2); border: 1px solid var(--accent-2);
  border-radius: var(--r-sm); padding: 7px 14px; margin-right: 12px;
}
input[type="file"]::file-selector-button:hover { filter: brightness(1.1); }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; font-size: .9rem; }
.hidden { display: none !important; }
/* Links had no colour of their own: browser blue on the dark panel, 1.94:1. */
a { color: var(--accent); }
.warnbox a { color: inherit; text-decoration: underline; }
/* Placeholders fell back to the browser's #757575 (3.7:1 dark, 4.0:1 light). */
::placeholder { color: var(--muted); opacity: 1; }
/* Read by screen readers, not shown. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* The sticky header (and the phone tab bar) must not cover what keyboard focus scrolls to. */
html { scroll-padding-top: 80px; }
@media (max-width: 900px) { html { scroll-padding-top: 124px; } }
@media (max-width: 740px) { html { scroll-padding-top: 130px; scroll-padding-bottom: 80px; } }

/* ---- top bar ---- */
/* Safe areas, setup A: raw insets on the bar itself (top, left, right), no calc(); the
   breathing room is the inner row's own padding. */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-in { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -0.02em; }
.topbar .brand img { border-radius: 8px; }
/* The search box gives way, never the tabs: the strip used to shrink instead, and at
   768 px Capture, Exports and Settings were 0% visible. */
.topbar input[type="search"] { flex: 1 1 140px; min-width: 0; max-width: 340px; }
.topbar .spacer { flex: 1; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; flex: none; }
nav.tabs a {
  color: var(--muted); text-decoration: none; padding: 8px 12px;
  border-radius: var(--r-sm); white-space: nowrap; font-size: .92rem; font-weight: 500;
}
nav.tabs a.active { color: var(--text); background: var(--panel-2); }
/* Inside the strip's overflow box an outside ring was cut off top and bottom. */
nav.tabs a:focus-visible { outline-offset: -2px; }
/* More tabs past an edge: fade it, so a phone-width strip shows it scrolls. */
nav.tabs.more-right {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
}
nav.tabs.more-left {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
}
nav.tabs.more-left.more-right {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
}
.help-link {
  flex: none; width: 30px; height: 30px; border-radius: 50%; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-weight: 600;
  border: 1px solid var(--border); background: var(--panel);
}
.help-link:hover, .help-link.active { color: var(--text); border-color: var(--accent); }
.badge {
  background: var(--accent-2); color: #fff; border-radius: 999px;
  font-size: .68rem; font-weight: 600; padding: 1px 6px; margin-left: 4px; vertical-align: 1px;
}

/* ---- layout ---- */
main { max-width: 880px; margin: 0 auto; padding: 16px 14px 90px; }

/* ---- view header (orients you: where am I, what is this for) ---- */
.view-head { margin: 2px 0 16px; }
.view-head h1 { margin: 0; font-size: 1.3rem; letter-spacing: -.022em; font-weight: 650; }
.view-head h1:focus { outline: none; } /* focused on navigation, to move screen readers along — not a control */
.view-head p { margin: 4px 0 0; color: var(--muted); font-size: .88rem; line-height: 1.5; max-width: 62ch; }

/* ---- grouped export/settings sub-headings ---- */
.group-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin: 22px 2px 10px;
}
.group-head h2 { margin: 0; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.group-head .group-note { font-size: .8rem; color: var(--muted); font-weight: 400; }

/* Jump-links for long settings pages. */
.jumpnav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.jumpnav a {
  text-decoration: none; font-size: .8rem; color: var(--muted);
  border: 1px solid var(--border); background: var(--panel);
  border-radius: var(--r-sm); padding: 5px 12px;
}
.jumpnav a:hover { color: var(--text); border-color: var(--accent); }
/* Anchored sections must clear the sticky topbar when jumped to. */
.section[id] { scroll-margin-top: 96px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
/* A select grows to its longest option: one long context name made the phone page 505 px wide. */
select { max-width: 100%; }
.toolbar select { width: auto; min-width: 0; }
.chip {
  border: 1px solid var(--border); background: var(--panel);
  border-radius: var(--r-sm); padding: 5px 12px; font-size: .84rem; color: var(--muted); font-weight: 500;
}
.chip.on { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.ctx-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ctx-chips .chip { padding: 3px 10px; font-size: .78rem; cursor: pointer; }
/* Heads a group of preset buttons rather than one field, so it's not a <label>. */
.ct-presets-label { display: block; font-size: .8rem; color: var(--muted); margin: 12px 0 4px; }
.ct-presets { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.ct-preset {
  display: flex; flex-direction: column; gap: 2px; text-align: left; width: 100%;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px 12px;
}
.ct-preset.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--panel-2)); }

/* Search-match highlight in list results. */
mark {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  color: inherit; border-radius: 3px; padding: 0 1px;
}

/* Ask answers: light formatting — every line is a block; bullets hang-indent. */
.answer { line-height: 1.6; }
/* Ask receipts: the entries an answer drew from, each one clickable through to the entry. */
.ask-sources { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 16px; }
.ask-sources .muted { font-size: .78rem; margin-right: 2px; }
.ask-sources .chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; font-size: .78rem; cursor: pointer; }
.ask-sources .chip:hover { border-color: var(--accent); color: var(--text); }
.ask-sources .chip .tag.type { font-size: .68rem; padding: 1px 6px; }
.answer .ln { display: block; min-height: 1em; }
.answer .li { display: block; padding-left: 1.1em; text-indent: -1.1em; }

/* ---- memory cards ---- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  cursor: pointer; transition: border-color .15s;
}
.card:hover { border-color: var(--accent); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-head :is(h2, h3) { margin: 0 0 6px; }
.card-ctx { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; flex-shrink: 0; max-width: 50%; }
.card-ctx .tag.ctx { font-size: .68rem; }
.card :is(h2, h3) { margin: 0 0 6px; font-size: .98rem; font-weight: 600; letter-spacing: -0.012em; display: flex; align-items: center; gap: 6px; overflow-wrap: anywhere; min-width: 0; }
.card .preview { color: var(--muted); font-size: .9rem; margin: 0 0 10px; line-height: 1.45; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .72rem; }
.tag { border-radius: 5px; padding: 2px 7px; background: var(--panel-2); color: var(--muted); font-weight: 500; }
.tag.type { color: var(--accent); }
.tag.ctx { color: var(--blue); }
.sens { border-radius: 5px; padding: 2px 7px; font-weight: 550; }
.sens.shareable { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.sens.personal { background: color-mix(in srgb, var(--blue) 18%, transparent); color: var(--blue); }
.sens.sensitive { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.sens.restricted { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); }
.pin { color: var(--amber); }
.dot-unreviewed { width: 8px; height: 8px; border-radius: 50%; display: inline-block; box-sizing: border-box; border: 1.5px solid var(--muted); }
/* v27: routine entries settle on their own (hollow dot); held ones wait for the owner (amber). */
.dot-unreviewed.held { background: var(--amber); border-color: var(--amber); }
.card.held { border-color: color-mix(in srgb, var(--amber) 38%, var(--border)); }
.hold-note {
  margin: 8px 0 8px; padding-left: 10px; font-size: .84rem; line-height: 1.45; color: var(--amber);
  border-left: 2px solid color-mix(in srgb, var(--amber) 55%, transparent);
}
.rv-hold { margin-top: 12px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }
/* Section heads inside a view sit below its title: the Inbox's were 24 px under a 20.8 px h1. */
h2.block-head { font-size: 1.02rem; }
/* Row actions on cards are secondary controls, not the page's main buttons. */
.card [data-actions] button { font-size: .85rem; padding: 6px 12px; }
.empty-ico { margin: 0 0 8px; color: var(--green); }
.empty-ico .ico { width: 30px; height: 30px; stroke-width: 1.6; }
.dg-i { color: var(--muted); }

/* ---- editor / modal ---- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 40; overflow-y: auto;
  background: rgba(0,0,0,.55); backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px 12vh;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 680px; padding: 20px 22px;
}
.modal h2 { margin: 0 0 4px; font-size: 1.1rem; }
/* Compact confirm/prompt dialog — replaces native confirm()/prompt(). */
.modal.dialog { max-width: 440px; }
.modal.dialog p { margin: 6px 0 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.modal.dialog .actions { margin-top: 16px; }
/* A fixed dark red, not --red: white on dark's #f87171 was 2.77:1 (Delete forever, Revoke…). */
.modal.dialog button.primary.danger { background: #b42828; border-color: #b42828; color: #fff; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.modal .actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.modal .actions .spacer { flex: 1; }
.warnbox {
  background: color-mix(in srgb, var(--amber) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent);
  color: var(--amber); border-radius: var(--r-sm); padding: 10px 12px; font-size: .85rem; margin-top: 12px;
}

/* ---- export cards / settings ---- */
.section { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.section h2, .section h3 { margin: 0 0 4px; font-size: 1rem; }
.section p { margin: 4px 0 10px; font-size: .88rem; color: var(--muted); line-height: 1.5; }
.section .btns { display: flex; gap: 8px; flex-wrap: wrap; }
pre.snippet {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 12px; font-size: .78rem; overflow-x: auto; line-height: 1.5;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  /* Break long tokens only where they must: break-all split words mid-way ("abou/t"). */
  white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere;
}
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: .75rem; }
/* A revoked key or disabled account: muted text, not opacity (which took it to 2.5:1). */
tr.dim td { color: var(--muted); }
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent-2); color: #fff; border: none;
  font-size: 26px; font-weight: 400; line-height: 1; box-shadow: 0 4px 16px rgba(0,0,0,.35);
}

/* ---- "this week in your memory" digest ---- */
.digest { border-color: color-mix(in srgb, var(--blue) 40%, var(--border)); }
.dg-lines { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.dg-line { display: flex; gap: 10px; align-items: baseline; font-size: .88rem; line-height: 1.5; }
.dg-line b { color: var(--text); font-weight: 600; }
.dg-i { flex: none; width: 1.3em; text-align: center; }
.dg-cta {
  display: block; margin-top: 12px; padding: 9px 12px; border-radius: var(--r-sm);
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); font-size: .85rem; text-decoration: none;
}
.dg-cta:hover { border-color: var(--accent); color: var(--text); }
.dg-cta b { color: var(--amber); }

/* ---- onboarding checklist ---- */
.onboard { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.onboard-bar {
  height: 5px; border-radius: 999px; background: var(--panel-2);
  margin: 12px 0 14px; overflow: hidden;
}
.onboard-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.onboard-step {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: transparent; border: none; border-radius: var(--r-sm); padding: 9px 8px;
}
.onboard-step:hover { background: var(--panel-2); }
.onboard-step.done { opacity: .55; }
.onboard-check {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); display: inline-flex; align-items: center; justify-content: center;
  font-size: .8rem; color: var(--green);
}
.onboard-step.done .onboard-check { border-color: var(--green); }

/* ---- login ---- */
/* Scrolls when its card is taller than the screen: the invite wizard's last step (847 px)
   was clipped at 375 × 667, with "Skip" out of reach. The card's auto margins still centre it. */
.login-overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--bg); overflow-y: auto;
  display: flex; align-items: flex-start; justify-content: center; padding: 20px;
}
.login-card { width: 100%; max-width: 340px; margin: auto 0; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 {
  margin: 0;
  background: linear-gradient(115deg, var(--accent), var(--blue));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; color: transparent;
}
.login-card p { margin: 0; }
.login-logo { margin: 0 auto; border-radius: 14px; }

/* ---- toast / offline ---- */
/* Centred with auto margins, not left:50% + translate: that capped them at half the screen,
   so at 375 px the update bar was 223 px wide, six lines tall, over the review buttons. */
.toast, .update-toast {
  left: 0; right: 0; margin: 0 auto; width: max-content; max-width: calc(100vw - 24px);
}
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 90;
  display: flex; align-items: center; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast button {
  background: transparent; border: none; padding: 2px 4px;
  color: var(--accent); font-weight: 600; font-size: .9rem; white-space: nowrap;
}
.update-toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 95;
  display: flex; align-items: center; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--accent);
  padding: 8px 10px 8px 16px; border-radius: 10px; font-size: .9rem;
  box-shadow: 0 8px 30px rgba(0,0,0,.45);
}
.update-toast button { padding: 6px 14px; }
.update-toast .ghost { padding: 4px 10px; font-size: 1.1rem; line-height: 1; }
.offline-banner {
  background: color-mix(in srgb, var(--amber) 15%, var(--panel));
  color: var(--amber); text-align: center; font-size: .82rem; padding: 6px;
}

/* ---- top loading bar (view switches slower than 180ms) ---- */
.loadbar {
  position: fixed; top: 0; left: 0; right: 0; height: 2.5px;
  z-index: 99; overflow: hidden; pointer-events: none;
}
.loadbar::after {
  content: ''; display: block; height: 100%; width: 40%;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  border-radius: 999px; animation: loadslide 1s ease-in-out infinite;
}
@keyframes loadslide {
  from { transform: translateX(-110%); }
  to { transform: translateX(360%); }
}

/* ---- at-a-glance strip (memories home) ---- */
.stat-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.stat {
  border: 1px solid var(--border); background: var(--panel);
  border-radius: var(--r-sm); padding: 5px 11px; font-size: .82rem; color: var(--muted);
}
.stat b { color: var(--text); font-weight: 600; }
a.stat-link {
  text-decoration: none;
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
a.stat-link:hover { border-color: var(--accent); color: var(--text); }

/* ---- connections status (settings) ---- */
.conn-list { display: flex; flex-direction: column; gap: 8px; }
.conn { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.conn-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.conn-dot.live { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.conn-dot.stale { background: var(--amber); }
.conn-dot.idle { background: transparent; border: 1.5px solid var(--border); }
.conn-name { font-weight: 600; font-size: .9rem; }
.conn-meta { font-size: .78rem; }
.conn-kind { font-weight: 400; font-size: .74rem; }
.conn-quiet { color: var(--amber); font-weight: 600; }
.conn-acts { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.conn-acts .conn-sees { margin-left: 0; }
/* A phone: name, then what it did, then its actions, each lined up under the name. */
@media (max-width: 640px) {
  .conn { gap: 2px 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
  .conn:last-child { border-bottom: 0; }
  .conn-meta, .conn-acts { flex-basis: 100%; margin-left: 19px; }
  .conn-acts .conn-sees:first-child { padding-left: 0; }
}
.conn-feed { display: flex; flex-direction: column; gap: 5px; }
.conn-ev { font-size: .82rem; }

@media (max-width: 640px) {
  main { padding: 14px 10px 90px; }
  .view-head h1 { font-size: 1.2rem; }
  /* Comfortable touch targets (was 30–34px in the top bar). 44px is the
     iOS/Android minimum; the small in-form context chips stay compact on purpose. */
  .jumpnav a, .toolbar .chip {
    min-height: 44px; display: inline-flex; align-items: center;
  }
  .jumpnav a, .toolbar .chip { padding: 0 14px; }
  .help-link { width: 44px; height: 44px; }
  .row { flex-direction: column; }
  /* Wide tables scroll inside their card instead of stretching the page. */
  .section table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  /* …except tables with row actions: those stack, one block per row, the buttons on their own
     line — scrolled sideways, every revoke and re-invite button started off-screen. */
  .section table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; white-space: normal; }
  table.stack tr:first-child { display: none; } /* the header row */
  table.stack tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  table.stack td { border: 0; padding: 2px 0; }
  table.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); }
  table.stack td:last-child:not(:empty) { padding-top: 6px; }
}

/* Tablet and in-between widths: [brand · tabs · … ? theme] / [search]. One row stops
   fitting just under 900 px. */
@media (max-width: 900px) {
  .topbar-in { flex-wrap: wrap; }
  .topbar input[type="search"] { order: 3; flex: 1 1 100%; max-width: none; }
}

/* Phones: the tabs become a fixed bottom bar, the header keeps [brand … ? theme] / [search].
   The scrolling strip put Exports and Settings off-screen and made the header 168 px tall. */
@media (max-width: 740px) {
  :root { --tabbar-h: 56px; }
  /* A fixed descendant is placed against its nearest ancestor with a backdrop-filter, so the
     header gives up its blur here — otherwise the tab bar would pin to the header, not the screen. */
  .topbar { backdrop-filter: none; background: var(--bg); }
  .topbar .spacer { display: none; }
  a.help-link { margin-left: auto; } /* the "?" leads the right-side pair; the theme button follows it */
  nav.tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0;
    overflow: visible; -webkit-mask-image: none; mask-image: none;
    background: var(--panel); border-top: 1px solid var(--border);
    /* Setup A: raw insets on the tab bar (bottom, left, right); the links' padding is the breathing room. */
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  nav.tabs a {
    min-height: var(--tabbar-h); padding: 6px 2px; border-radius: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: .72rem; text-align: center;
  }
  nav.tabs a.active { background: transparent; color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }
  nav.tabs .badge { margin-left: 0; font-size: .62rem; padding: 0 5px; vertical-align: 0; }
  main { padding-bottom: calc(var(--tabbar-h) + 96px); }
  .fab { bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom)); }
  .toast, .update-toast { bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); }
}

/* ---- a link that looks like a button ---- */
a.btn {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 550;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--r-sm); padding: 8px 14px; font-size: .92rem; min-height: 40px;
}
a.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
a.btn:hover { filter: brightness(1.08); }

/* ---- review mode: one entry at a time ---- */
.review { max-width: 720px; margin: 0 auto; }
.rv-progress { display: flex; align-items: center; gap: 12px; font-size: .82rem; color: var(--muted); margin-bottom: 12px; }
.rv-progress a { color: var(--muted); }
.rv-bar { flex: 1; height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; }
.rv-bar > span { display: block; height: 100%; background: var(--accent); transition: width .3s ease; }
.rv-card {
  position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; touch-action: pan-y; transition: transform .22s ease, opacity .22s ease, border-color .15s;
}
.rv-card.dragging { transition: none; }
.rv-card[data-swipe="approve"] { border-color: var(--green); }
.rv-card[data-swipe="archive"] { border-color: var(--red); }
.rv-kicker { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .78rem; color: var(--muted); margin-bottom: 10px; }
.rv-badge { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 1px 8px; color: var(--text); }
.rv-card h2 { margin: 0 0 8px; font-size: 1.15rem; line-height: 1.35; overflow-wrap: anywhere; }
.rv-card h2:focus { outline: none; }
.rv-body { white-space: pre-wrap; line-height: 1.55; margin: 0 0 12px; overflow-wrap: anywhere; }
.rv-hint { margin-top: 12px; }
.rv-merge { border-top: 1px dashed var(--border); margin-top: 14px; padding-top: 10px; font-size: .86rem; }
.rv-merge ul { margin: 6px 0 10px 18px; padding: 0; color: var(--muted); }
.rv-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.rv-actions button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; font-weight: 550; }
.rv-actions kbd {
  font: inherit; font-size: .7rem; font-weight: 500; opacity: .75;
  border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; line-height: 1.3;
}
.rv-batch { text-align: center; margin: 10px 0 0; }
.rv-swipe-note { display: none; text-align: center; font-size: .78rem; margin-top: 8px; }
body[data-view="review"] .fab { display: none; } /* it would sit on top of the action bar */
@media (hover: none) and (pointer: coarse) {
  .rv-actions kbd { display: none; }
  .rv-swipe-note { display: block; }
}
@media (max-width: 640px) {
  .rv-card { padding: 16px; }
  /* Sticks just above the tab bar (and the home indicator); it used to sit behind both. */
  .rv-actions { position: sticky; bottom: calc(var(--tabbar-h, 0px) + env(safe-area-inset-bottom)); background: var(--bg); padding: 10px 0 12px; margin-top: 10px; }
  .review-cta a.btn { flex: 1 1 100%; justify-content: center; min-height: 44px; }
}
@media (max-width: 480px) {
  /* Four review buttons don't fit 320 px with their key hints: Skip and Approve sat past the edge. */
  .rv-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- librarian activity ---- */
.ops { list-style: none; margin: 10px 0 0; padding: 0; }
.op { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.op:first-child { border-top: 0; padding-top: 4px; }
.op.more { display: none; }
.ops.all .op.more { display: flex; }
.op-i { flex: none; width: 1.4em; text-align: center; }
.op-body { flex: 1; min-width: 0; font-size: .9rem; line-height: 1.45; overflow-wrap: anywhere; }
.op-meta { font-size: .78rem; margin-top: 2px; }
.op-state { flex: none; font-size: .78rem; max-width: 10em; text-align: right; }
.op-src summary { cursor: pointer; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.op-src ul { margin: 4px 0 0 18px; padding: 0; font-size: .82rem; color: var(--muted); }
.op-src ul.op-items { list-style: none; margin-left: 0; }
.op-items li { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 4px 0; }
.op-items li + li { border-top: 1px solid var(--border); }
.op-items li > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.op-items .chip { flex: none; padding: 2px 8px; font-size: .76rem; }

/* ---- chat-history import ---- */
.h-filters input[type="search"] { flex: 1 1 200px; width: auto; }
.h-since { display: flex; gap: 6px; align-items: center; font-size: .82rem; }
.h-since input { width: auto; }
.h-list { list-style: none; margin: 8px 0 12px; padding: 0; max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: var(--r-sm); }
.h-list li + li { border-top: 1px solid var(--border); }
.h-list label { display: flex; gap: 10px; align-items: baseline; padding: 8px 12px; margin: 0; cursor: pointer; font-size: .88rem; }
.h-list input { width: auto; flex: none; }
.h-t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.h-m { flex: none; font-size: .78rem; }
.h-run { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.h-run .rv-bar { width: 100%; }

/* ---- "what it sees" ---- */
.modal.dialog.reach { max-width: 560px; }
.reach-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: var(--r-sm); }
.reach-list li { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 7px 10px; font-size: .86rem; }
.reach-list li + li { border-top: 1px solid var(--border); }
.reach-t { flex: 1 1 60%; min-width: 0; overflow-wrap: anywhere; }
.conn-sees { margin-left: auto; padding: 2px 8px; font-size: .78rem; }
