/* memex web UI
 * Quiet, token-driven layer over vendored Pico.
 *
 * Theme palette (colors + --mx-* color tokens) lives in theme.css and
 * is loaded BEFORE this file by base.html. Everything in this file
 * consumes --mx-* tokens via var() — never hex values directly — so a
 * theme swap is a one-file change.
 */

:root {
  --mx-radius: 8px;
  --mx-radius-sm: 6px;
  --mx-gap: 16px;
  --mx-rail: 224px;
  --mx-rail-collapsed: 72px;
  --mx-mobile-tabbar-height: 60px;

  --pico-background-color: var(--mx-bg);
  --pico-card-background-color: var(--mx-surface);
  --pico-card-border-color: var(--mx-border);
  --pico-muted-border-color: var(--mx-border);
  --pico-color: var(--mx-text);
  --pico-muted-color: var(--mx-text-muted);
  --pico-primary: var(--mx-focus);
  --pico-primary-background: var(--mx-focus);
  --pico-primary-border: var(--mx-focus);

  /* Motion vocabulary — three durations + two easing curves. The
     ease-out curve is Apple's "spring" curve, used for everything that
     enters or exits the viewport. ease-standard is the symmetric curve
     for tiny in-place transitions (focus rings, chevron rotations).
     prefers-reduced-motion at the bottom of this file zeroes the
     durations so motion-sensitive operators get instant cuts. */
  --mx-ease-out: cubic-bezier(0.32, 0.72, 0, 1);
  --mx-ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --mx-motion-fast: 180ms;
  --mx-motion-medium: 280ms;
  --mx-motion-slow: 420ms;

  /* Lets the browser interpolate `height: auto` so native <details>
     elements can transition their body open/close. Safari 17.4+ /
     Chrome 129+; older clients hard-cut, no regression. */
  interpolate-size: allow-keywords;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--mx-bg);
  color: var(--mx-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--mx-focus);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--mx-text);
}

:focus-visible {
  outline: 3px solid var(--mx-focus);
  outline-offset: 2px;
}

button,
input,
select,
textarea {
  font: inherit;
}

input,
select,
textarea {
  background: var(--mx-surface);
  border-color: var(--mx-border);
  color: var(--mx-text);
}

textarea {
  min-height: 8rem;
  resize: vertical;
}

code,
kbd {
  background: var(--mx-surface-muted);
  border-radius: var(--mx-radius-sm);
  color: var(--mx-text);
  padding: 0.08rem 0.35rem;
}

/* Shell */

.desktop-rail {
  display: none;
}

.app-main {
  background: transparent;
  border: 0;
  box-shadow: none;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 96px;
}

.rail-header {
  display: grid;
  gap: 10px;
  margin-bottom: 26px;
}

.rail-topline {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.rail-brand {
  align-items: center;
  color: var(--mx-text);
  display: inline-flex;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 750;
  min-height: 40px;
  min-width: 0;
  text-decoration: none;
}

.rail-label,
.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-toggle {
  align-items: center;
  background: transparent;
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text-muted);
  display: inline-flex;
  flex: 0 0 auto;
  height: 40px;
  justify-content: center;
  margin: 0;
  padding: 0;
  width: 40px;
}

.rail-toggle:hover {
  background: var(--mx-surface-muted);
  border-color: var(--mx-border-strong);
  color: var(--mx-text);
}

.rail-context {
  display: flex;
  justify-content: center;
}

.rail-nav,
.sheet-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link,
.sheet-nav a,
.tab-link {
  color: var(--mx-text-muted);
  text-decoration: none;
}

.nav-link,
.sheet-nav a {
  align-items: center;
  border-radius: var(--mx-radius-sm);
  display: flex;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
}

.nav-icon {
  display: inline-block;
  flex: 0 0 auto;
  fill: none;
  height: 19px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 19px;
}

.nav-link:hover,
.sheet-nav a:hover,
.nav-link.is-active,
.sheet-nav a.is-active {
  background: var(--mx-surface-muted);
  color: var(--mx-text);
}

.rail-footer {
  border-top: 1px solid var(--mx-border);
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding-top: 16px;
}

.build-note {
  color: var(--mx-text-muted);
  font-size: 0.78rem;
}

.logout-form,
.sheet-logout {
  margin: 0;
}

.mobile-tabbar {
  align-items: center;
  background: color-mix(in srgb, var(--mx-surface) 96%, transparent);
  border-top: 1px solid var(--mx-border);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  left: 0;
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  position: fixed;
  right: 0;
  z-index: 40;
}

.tab-link {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--mx-radius-sm);
  color: var(--mx-text-muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.82rem;
  justify-content: center;
  line-height: 1.2;
  margin: 0;
  min-height: 48px;
  padding: 8px 4px;
}

.tab-link.is-active {
  background: var(--mx-surface-muted);
  color: var(--mx-text);
  font-weight: 650;
}

.tab-button {
  flex-direction: column;
  gap: 3px;
  width: 100%;
}

.tab-filter-indicator {
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 750;
  line-height: 1;
  padding: 2px 6px;
}

/* iOS-style modal sheet. Stays mounted in the DOM at all times so
   the slide-up animation can play; closed state lives offscreen with
   pointer-events disabled so clicks pass through to whatever's
   beneath. body.more-open flips the transform + opacity. */
.sheet-backdrop {
  background: rgba(0, 0, 0, 0.42);
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition: opacity var(--mx-motion-slow) var(--mx-ease-out);
  z-index: 50;
}

.more-sheet {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-top: 1px solid var(--mx-border-strong);
  border-radius: 18px 18px 0 0;
  bottom: 0;
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.06);
  left: 0;
  max-height: min(78vh, 560px);
  overflow-y: auto;
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
  pointer-events: none;
  position: fixed;
  right: 0;
  transform: translateY(100%);
  transition: transform var(--mx-motion-slow) var(--mx-ease-out);
  z-index: 60;
}

body.more-open {
  overflow: hidden;
}

body.more-open .sheet-backdrop {
  opacity: 1;
  pointer-events: auto;
}

body.more-open .more-sheet {
  pointer-events: auto;
  transform: translateY(0);
}

.sheet-handle {
  background: var(--mx-border-strong);
  border-radius: 999px;
  height: 4px;
  margin: 2px auto 14px;
  width: 44px;
}

.sheet-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-section {
  border-top: 1px solid var(--mx-border);
  margin-top: 12px;
  padding-top: 14px;
}

.sheet-label {
  color: var(--mx-text-muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

@media (min-width: 860px) {
  .desktop-rail {
    background: var(--mx-surface);
    border-right: 1px solid var(--mx-border);
    bottom: 0;
    display: flex;
    flex-direction: column;
    left: 0;
    padding: 24px 16px;
    position: fixed;
    top: 0;
    width: var(--mx-rail);
  }

  .app-main {
    margin-left: var(--mx-rail);
    max-width: 1160px;
    padding: 32px;
    width: calc(100% - var(--mx-rail));
  }

  body.rail-collapsed .desktop-rail {
    align-items: center;
    padding-left: 12px;
    padding-right: 12px;
    width: var(--mx-rail-collapsed);
  }

  body.rail-collapsed .app-main {
    margin-left: var(--mx-rail-collapsed);
    width: calc(100% - var(--mx-rail-collapsed));
  }

  body.rail-collapsed .rail-topline {
    justify-content: center;
  }

  body.rail-collapsed .rail-brand,
  body.rail-collapsed .rail-label,
  body.rail-collapsed .nav-label,
  body.rail-collapsed .rail-footer {
    display: none;
  }

  body.rail-collapsed .rail-header {
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
  }

  body.rail-collapsed .rail-context {
    display: flex;
    justify-content: center;
    width: 100%;
  }

  body.rail-collapsed .rail-nav {
    align-items: center;
    width: 100%;
  }

  body.rail-collapsed .nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    width: 44px;
  }

  body.rail-collapsed .rail-toggle .nav-icon {
    transform: rotate(180deg);
  }

  .mobile-tabbar,
  .sheet-backdrop,
  .more-sheet {
    display: none !important;
  }
}

/* Shared primitives */

.page {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  display: grid;
  gap: 24px;
  margin: 0;
  padding: 0;
}

.page-header,
.detail-header {
  align-items: flex-start;
  background: transparent;
  border: 0;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0;
  padding: 0;
}

article.page > header {
  background: transparent;
  border: 0;
  margin: 0;
  padding: 0;
}

.page-header h1 {
  color: var(--mx-text);
  font-size: clamp(1.55rem, 3vw, 2.05rem);
  letter-spacing: 0;
  line-height: 1.12;
  margin: 0;
}

.find-panel h1 {
  color: var(--mx-text);
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  letter-spacing: 0;
  line-height: 1.16;
  margin: 0;
}

.page-header p,
.section-heading p,
.field-hint,
.muted-time,
.card-meta {
  color: var(--mx-text-muted);
}

.eyebrow {
  color: var(--mx-text-muted);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.page-section,
.workbench-section,
.home-search,
.home-capture,
.find-panel {
  display: grid;
  gap: 14px;
}

/* Visually-hidden but reachable for screen readers (used on the home
   capture form's section heading per §7 — accessibility is baseline). */
.visually-hidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.home-capture {
  margin-top: -4px;  /* sit close under the search row */
}
.quick-capture {
  align-items: stretch;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}
.quick-capture textarea {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  font-size: 0.95rem;
  margin: 0;
  min-height: 2.6rem;
  padding: 8px 12px;
  resize: vertical;
}
.quick-capture textarea:focus {
  border-color: var(--mx-focus);
  outline: none;
}
.quick-capture .button {
  align-self: stretch;
  margin: 0;
}

/* Flash banner shown on a successful capture-web redirect. */
.capture-flash {
  background: color-mix(in srgb, var(--mx-reference) 12%, var(--mx-surface));
  border: 1px solid color-mix(in srgb, var(--mx-reference) 50%, var(--mx-border));
  border-radius: var(--mx-radius);
  color: var(--mx-text);
  font-size: 0.95rem;
  margin-bottom: 14px;
  padding: 10px 14px;
}
.capture-flash a {
  color: var(--mx-focus);
}
.capture-flash-dup {
  background: var(--mx-surface-muted);
  border-color: var(--mx-border);
}

.section-heading {
  display: grid;
  gap: 2px;
}

.section-heading h2 {
  font-size: 1rem;
  letter-spacing: 0;
  line-height: 1.25;
  margin: 0;
}

.section-heading p,
.page-header p {
  margin: 0;
}

.button,
button.button,
a.button {
  align-items: center;
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.94rem;
  font-weight: 650;
  justify-content: center;
  line-height: 1.2;
  margin: 0;
  min-height: 44px;
  padding: 10px 14px;
  text-decoration: none;
  width: auto;
}

.button:hover,
button.button:hover,
a.button:hover {
  border-color: var(--mx-border-strong);
  color: var(--mx-text);
}

.button-primary,
button.button-primary,
a.button-primary {
  background: var(--mx-focus);
  border-color: var(--mx-focus);
  color: var(--mx-on-accent);
}

.button-primary:hover,
button.button-primary:hover,
a.button-primary:hover {
  background: color-mix(in srgb, var(--mx-focus) 84%, var(--mx-on-accent));
  border-color: color-mix(in srgb, var(--mx-focus) 84%, var(--mx-on-accent));
  color: var(--mx-on-accent);
}

.button-secondary,
button.button-secondary,
a.button-secondary {
  background: var(--mx-surface-muted);
  border-color: var(--mx-border);
  color: var(--mx-text);
}

.button-danger,
button.button-danger {
  background: var(--mx-system-soft);
  border-color: var(--mx-system);
  color: var(--mx-system);
}

.text-button,
button.text-button {
  background: transparent;
  border: 0;
  color: var(--mx-text-muted);
  cursor: pointer;
  margin: 0;
  min-height: 44px;
  padding: 8px 0;
}

.text-button:hover {
  color: var(--mx-text);
}

.empty-state {
  background: var(--mx-surface);
  border: 1px dashed var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text-muted);
  margin: 0;
  padding: 16px;
}

/* "Showing N of M open tasks · all tasks →" — appears when a home/list
   section is showing a truncated slice. Quiet by default so it doesn't
   compete with the actual content. */
.section-overflow-hint {
  color: var(--mx-text-muted);
  font-size: 0.84rem;
  margin: 8px 4px 0;
}
.section-overflow-hint a {
  color: var(--mx-text-muted);
}

.quiet-link {
  color: var(--mx-text-muted);
  justify-self: start;
}

/* Context switcher */

.context-switcher {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: 999px;
  display: inline-flex;
  gap: 2px;
  margin: 0;
  padding: 3px;
  width: max-content;
}

.ctx-label-compact {
  display: none;
}

.ctx-pill {
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--mx-text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1;
  margin: 0;
  min-height: 34px;
  padding: 8px 11px;
}

.ctx-pill.active {
  background: var(--mx-surface);
  color: var(--mx-text);
  box-shadow: var(--mx-shadow);
}

.ctx-pill-work.active {
  background: var(--mx-context-work-active);
  color: var(--mx-context-active-text);
}

.ctx-pill-life.active {
  background: var(--mx-context-life-active);
  color: var(--mx-context-active-text);
}

@media (min-width: 860px) {
  body.rail-collapsed .context-switcher {
    border-radius: 999px;
    display: grid;
    gap: 3px;
    justify-items: center;
    padding: 4px;
    width: 44px;
  }

  body.rail-collapsed .ctx-pill {
    align-items: center;
    display: inline-flex;
    height: 34px;
    justify-content: center;
    min-height: 34px;
    padding: 0;
    width: 34px;
  }

  body.rail-collapsed .ctx-label-full {
    display: none;
  }

  body.rail-collapsed .ctx-label-compact {
    display: inline;
  }
}

/* Home and find */

.home-page {
  gap: 30px;
}

.find-panel {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  box-shadow: var(--mx-shadow);
  padding: 18px;
}

.big-search {
  align-items: stretch;
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  display: flex;
  gap: 0;
  margin: 0;
  min-height: 56px;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.big-search:focus-within {
  border-color: color-mix(in srgb, var(--mx-focus) 58%, var(--mx-border));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--mx-focus) 22%, transparent);
  outline: 0;
}

.big-search input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  background-image: none;
  border: 0;
  border-radius: 0;
  flex: 1 1 auto;
  font-size: 1rem;
  margin: 0;
  min-height: 56px;
  min-width: 0;
  padding: 0 16px;
  width: 100%;
}

.big-search input[type="search"]:focus,
.big-search input[type="search"]:focus-visible {
  box-shadow: none;
  outline: 0;
}

.search-submit,
button.search-submit {
  align-items: center;
  appearance: none;
  background: transparent;
  background-image: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  color: var(--mx-focus);
  cursor: pointer;
  display: inline-flex;
  flex: 0 0 56px;
  height: auto;
  justify-content: center;
  min-height: 56px;
  margin: 0;
  padding: 0;
  width: 56px;
  --pico-background-color: transparent;
  --pico-border-color: transparent;
  --pico-button-box-shadow: none;
  --pico-button-hover-box-shadow: none;
  --pico-color: var(--mx-focus);
}

.search-submit:hover,
button.search-submit:hover,
.search-submit:active,
button.search-submit:active {
  background: transparent;
  background-image: none;
  border-color: transparent;
  box-shadow: none;
  color: var(--mx-text);
}

.search-submit:focus,
.search-submit:focus-visible,
button.search-submit:focus,
button.search-submit:focus-visible {
  background: transparent;
  background-image: none;
  box-shadow: none;
  outline: 0;
}

.big-search[role="search"] > input[type="search"],
.big-search[role="search"] > button.search-submit,
.big-search[role="search"] > input[type="search"]:first-child,
.big-search[role="search"] > button.search-submit:last-child {
  border-radius: 0;
  margin: 0;
}

.search-submit .nav-icon {
  display: block;
  height: 22px;
  width: 22px;
}

.big-search input[type="search"]::-webkit-search-decoration,
.big-search input[type="search"]::-webkit-search-cancel-button,
.big-search input[type="search"]::-webkit-search-results-button,
.big-search input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.review-callout {
  align-items: center;
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 14px;
  text-decoration: none;
}

.review-callout:hover {
  border-color: var(--mx-border-strong);
}

.recent-summary {
  align-items: center;
  appearance: none;
  background-color: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text);
  cursor: pointer;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  min-height: 52px;
  padding: 14px;
  text-align: left;
  width: 100%;
}

.recent-summary::after {
  align-items: center;
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text);
  content: "+";
  display: inline-flex;
  flex: 0 0 auto;
  font-weight: 800;
  height: 32px;
  justify-content: center;
  line-height: 1;
  width: 32px;
}

.recent-summary[aria-expanded="true"]::after {
  content: "-";
}

.recent-summary:hover {
  border-color: var(--mx-border-strong);
}

.recent-summary-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.recent-summary-open {
  display: none;
}

.recent-summary[aria-expanded="true"] .recent-summary-closed {
  display: none;
}

.recent-summary[aria-expanded="true"] .recent-summary-open {
  display: inline;
}

.recent-summary small {
  color: var(--mx-text-muted);
}

/* Grid-rows collapse trick: the wrapper has one row track that
   transitions between 0fr (closed) and 1fr (open). overflow:hidden
   clips the inner content during the in-between. The `.is-open` flip
   is driven by the toggle handler in base.html. */
.recent-content {
  display: grid;
  grid-template-rows: 0fr;
  overflow: hidden;
  transition: grid-template-rows var(--mx-motion-medium) var(--mx-ease-out);
}
.recent-content.is-open {
  grid-template-rows: 1fr;
}
.recent-content-inner {
  display: grid;
  gap: 10px;
  min-height: 0;  /* Required so the row track can actually collapse. */
}

/* Until JS runs and drops `hidden`, keep the closed state hidden so
   there's no flash of content. JS sets hidden=false on DOMContentLoaded;
   the CSS collapse takes over from there. */
.recent-content[hidden] {
  display: none;
}

.review-callout-main {
  display: grid;
  gap: 2px;
}

.callout-count,
.person-card small {
  color: var(--mx-text-muted);
}

.callout-count {
  font-size: 0.9rem;
}

.callout-action {
  color: var(--mx-focus);
  font-weight: 700;
}

.person-card {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text);
  display: grid;
  gap: 4px;
  padding: 14px;
  text-decoration: none;
}

.person-card:hover {
  border-color: var(--mx-border-strong);
  color: var(--mx-text);
}

/* Item cards */

.item-stack {
  display: grid;
  gap: 10px;
}

.item-card {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  box-shadow: var(--mx-shadow);
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px;
}

.item-card:hover {
  border-color: var(--mx-border-strong);
}

/* C3 — when HTMX swaps a card in after an action (Done, Snooze,
   Convert, …), the card template appends a one-shot script that adds
   `.card-flash` for ~600ms. Flash makes the state transition visible
   to a fast scanner without being noisy enough to demand attention. */
@keyframes mx-card-flash {
  0%   { background: color-mix(in srgb, var(--mx-reference) 18%, var(--mx-surface)); }
  100% { background: var(--mx-surface); }
}
.item-card.card-flash {
  animation: mx-card-flash var(--mx-motion-slow) var(--mx-ease-out);
}
@media (prefers-reduced-motion: reduce) {
  .item-card.card-flash { animation: none; }
}

/* Universal HTMX swap motion. HTMX automatically applies these
   lifecycle classes:
   - .htmx-swapping on the outgoing element (during swap:Xms)
   - .htmx-added on newly-added content (during settle:Xms)
   Templates pair their hx-swap with `swap:200ms settle:200ms` to give
   these animations room to play. Surfaces without those timings (e.g.
   initial page render) just skip the motion. */
@keyframes mx-swap-out {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.98); }
}
@keyframes mx-swap-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.htmx-swapping {
  animation: mx-swap-out var(--mx-motion-fast) var(--mx-ease-out) forwards;
}
.htmx-added {
  animation: mx-swap-in var(--mx-motion-medium) var(--mx-ease-out);
}
@media (prefers-reduced-motion: reduce) {
  .htmx-swapping,
  .htmx-added { animation: none; }
}

/* A4 — flash banner shown briefly above the edit form after a save
   redirect (?saved=1). Uses the same reference-accent palette as the
   settings-saved banner so the operator sees a familiar shape. */
/* Banners that appear on first paint after a redirect (save-flash on
   /items/<id>?saved=1, settings-saved on /settings, capture-flash on
   /?captured=...). Each gets a slide-down + fade-in via the
   mx-flash-slide-down keyframe so they ease in rather than snap. */
@keyframes mx-flash-slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.save-flash,
.settings-saved,
.capture-flash {
  animation: mx-flash-slide-down var(--mx-motion-medium) var(--mx-ease-out);
}

.save-flash {
  background: color-mix(in srgb, var(--mx-reference) 14%, var(--mx-surface));
  border: 1px solid color-mix(in srgb, var(--mx-reference) 55%, var(--mx-border));
  border-radius: var(--mx-radius);
  font-size: 0.9rem;
  margin: 0 0 16px;
  padding: 10px 14px;
}
.save-flash a {
  color: var(--mx-text-muted);
  font-size: 0.84rem;
  margin-left: 8px;
}

/* Original captured text disclosure on item_detail. raw_content is
   immutable replay log; the title above is the editable surface.
   Quiet by default so the eye reads "title + fields" and treats the
   capture source as an aside. */
.raw-content-disclosure {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  margin: 0 0 16px;
  padding: 0;
}
.raw-content-disclosure summary {
  color: var(--mx-text-muted);
  cursor: pointer;
  font-size: 0.86rem;
  padding: 8px 12px;
}
.raw-content-disclosure summary::-webkit-details-marker { display: none; }
/* Pico paints a right-side chevron via `summary::after` on its own
   details styles. We supply our own `::before` triangle below, so kill
   Pico's so the row doesn't show two disclosure indicators. */
.raw-content-disclosure summary::after { display: none; }
.raw-content-disclosure summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform var(--mx-motion-fast) var(--mx-ease-standard);
}
.raw-content-disclosure[open] summary::before { transform: rotate(90deg); }
.raw-content-source {
  background: var(--mx-surface);
  border-top: 1px solid var(--mx-border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.84rem;
  margin: 0;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.raw-content-disclosure .field-hint {
  margin: 6px 12px 10px;
}

.card-topline {
  align-items: center;
  display: flex;
  gap: 8px;
}

.when {
  color: var(--mx-text-muted);
  font-size: 0.78rem;
  margin-left: auto;
  white-space: nowrap;
}

/* Due-date chip on cards. Distinct color from `.when` (which is the
   captured-at muted gray) so the operator can spot the deadline at
   a glance. Color is constant regardless of whether the date is past
   or future — T5 / R-11.2: no shame counters, no red-overdue badges. */
.when + .when-due,
.when-due {
  color: var(--mx-task);
  margin-left: 0;
}
.when + .when {
  margin-left: 8px;
}

.card-link {
  color: var(--mx-text);
  text-decoration: none;
}

.card-link:hover {
  color: var(--mx-text);
}

.card-text {
  color: var(--mx-text);
  display: -webkit-box;
  font-size: 1.08rem;
  line-height: 1.46;
  margin: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.card-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  font-size: 0.82rem;
  gap: 8px;
}

.lozenge,
.status-pill,
.context-mark {
  align-items: center;
  border: 1px solid currentColor;
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  line-height: 1;
  min-height: 24px;
  padding: 5px 8px;
  text-transform: none;
  white-space: nowrap;
}

.lozenge-task {
  background: color-mix(in srgb, var(--mx-task) 14%, var(--mx-surface));
  color: var(--mx-task);
}

.lozenge-reference {
  background: color-mix(in srgb, var(--mx-reference) 14%, var(--mx-surface));
  color: var(--mx-reference);
}

.lozenge-idea {
  background: color-mix(in srgb, var(--mx-idea) 18%, var(--mx-surface));
  color: var(--mx-idea);
}

.lozenge-untyped {
  background: var(--mx-surface-muted);
  color: var(--mx-untyped);
}

.lozenge-draft {
  background: color-mix(in srgb, var(--mx-draft) 18%, var(--mx-surface));
  color: var(--mx-draft);
}

.lozenge-note {
  background: color-mix(in srgb, var(--mx-note) 18%, var(--mx-surface));
  color: var(--mx-note);
}

.markdown-body {
  margin: 1.5rem 0;
  line-height: 1.6;
}

.markdown-body p { margin: 0 0 0.9em; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin: 1.4em 0 0.4em;
  line-height: 1.25;
}
.markdown-body ul, .markdown-body ol { margin: 0 0 0.9em 1.4em; }
.markdown-body li { margin: 0.2em 0; }
.markdown-body code {
  background: var(--mx-surface-muted);
  padding: 0.1em 0.35em;
  border-radius: var(--mx-radius-sm);
  font-size: 0.92em;
}
.markdown-body pre {
  background: var(--mx-surface-muted);
  padding: 0.9em 1em;
  border-radius: var(--mx-radius);
  overflow-x: auto;
}
.markdown-body pre code { background: transparent; padding: 0; }
.markdown-body blockquote {
  border-left: 3px solid var(--mx-border-strong);
  margin: 1em 0;
  padding: 0.2em 1em;
  color: var(--mx-text-muted);
}
.markdown-body a { color: var(--mx-focus); }
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--mx-border);
  margin: 1.6em 0;
}

/* Milkdown editor host: a sibling <div> created by markdown-editor.js next
   to every <textarea data-md-editor>. The textarea is hidden on successful
   mount; if mount fails (network down, esm.sh unreachable), the textarea
   stays visible and the operator gets a plain markdown editor. */
.md-editor-host {
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  margin-bottom: 1rem;
  transition: border-color var(--mx-motion-fast) var(--mx-ease-standard);
  /* Crepe paints its own background on .milkdown and the toolbar,
     which would otherwise extend past the host's rounded corners. */
  overflow: hidden;
}
.md-editor-host:has(.ProseMirror:focus) {
  border-color: var(--mx-focus);
}
/* Crepe's default ProseMirror padding is `60px 120px` — way too much
   horizontal whitespace for memex's narrower content column.
   Override to roughly a quarter horizontally and a third vertically. */
.md-editor-host .milkdown .ProseMirror {
  padding: 1.25rem 1.5rem;
}
/* Milkdown's editing surface is a contenteditable <div>, which the
   global `:focus-visible { outline: 3px solid ... }` decorates with a
   thick outline when the operator types. The wrapper already shifts
   border-color to indicate focus, so suppress the inner outline. */
.md-editor-host .ProseMirror:focus,
.md-editor-host .ProseMirror:focus-visible {
  outline: none;
}
/* Crepe's slash-menu popup defaults to z-index: 10, which collides
   with `.sticky-actions` (also z-index: 10). The sticky bar wins by
   DOM order and clips the menu. Lift the menu above sticky regions. */
milkdown-slash-menu {
  z-index: 60;
}

.status-pill {
  background: var(--mx-surface-muted);
  color: var(--mx-text-muted);
}

.context-mark {
  background: var(--mx-surface-muted);
  color: var(--mx-text-muted);
}

.context-work {
  background: transparent;
  color: var(--mx-context-work-active);
}

.context-life {
  background: transparent;
  color: var(--mx-context-life-active);
}

.item-actions {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.more-actions {
  display: grid;
  gap: 8px;
  margin: 0;
  max-width: 100%;
  min-width: 0;
}

.more-actions summary {
  list-style: none;
  width: max-content;
}

.more-actions summary::-webkit-details-marker {
  display: none;
}

.more-actions summary::before,
.more-actions summary::after {
  content: none !important;
  display: none !important;
}

.more-actions-panel {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  display: grid;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
  padding: 12px;
  width: min(360px, 100%);
}

.more-actions[open] {
  flex-basis: min(360px, 100%);
  max-width: 100%;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-group-label {
  color: var(--mx-text-muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.action-note {
  color: var(--mx-text-muted);
  font-size: 0.86rem;
  margin: 0;
}

/* Lists and filters */

.segmented-control {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: 999px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
}

.segmented-control a {
  border-radius: 999px;
  color: var(--mx-text-muted);
  font-size: 0.86rem;
  min-height: 36px;
  padding: 8px 12px;
  text-decoration: none;
}

.segmented-control a.is-active {
  background: var(--mx-surface-muted);
  /* Outline the selected pill so the active state survives the dark
     pill-on-dark-bar contrast (Catppuccin Mocha base + surface-muted
     differ by only a few luminance steps — easy to miss at a glance). */
  box-shadow: inset 0 0 0 1px var(--mx-border-strong);
  color: var(--mx-text);
  font-weight: 700;
}

.pagination {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* Workbench/detail */

.detail-page {
  max-width: 880px;
}

.detail-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.detail-actions-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.detail-actions-panel .detail-meta {
  margin-top: 0;
}
.detail-actions-panel .item-actions {
  margin: 0;
}
.snoozed-until-pill {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: 999px;
  color: var(--mx-text-muted);
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  text-transform: uppercase;
}

.detail-header h1 {
  font-size: clamp(1.35rem, 2vw, 1.85rem);
  line-height: 1.2;
  max-width: 48ch;
}

.muted-time {
  font-size: 0.86rem;
  text-align: right;
}

/* Detail header can show due-at above captured-at when the task has
   a due date set. Stack them vertically; constant due-color regardless
   of past/future (T5). */
.muted-time-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.muted-time-due {
  color: var(--mx-task);
}

.workbench-section {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  box-shadow: var(--mx-shadow);
  padding: 16px;
}

/* Quiet the section heading inside a workbench card. Pico's default
   h2 (~1.5rem) reads as page-level on item / list / settings detail
   pages and competes with the actual page H1. Section labels are
   group-level UI, not headlines. (DESIGN_LANGUAGE §4.1.) */
.workbench-section > h2:first-child,
.workbench-section > legend.settings-group-legend {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 12px;
}

.raw-content {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  line-height: 1.58;
  padding: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.field {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  color: var(--mx-text);
  font-size: 0.88rem;
  font-weight: 700;
}

.field-hint {
  display: block;
  font-size: 0.86rem;
  margin-top: 4px;
}

.field-inline {
  align-items: center;
  display: flex;
  gap: 10px;
  margin: 0;
}

.field-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

.datetime-control {
  align-content: start;
  min-width: 0;
}

.datetime-pair {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.datetime-pair .field {
  margin: 0;
  min-width: 0;
}

.datetime-pair input[type="date"],
.datetime-pair input[type="time"] {
  min-width: 0;
  width: 100%;
}

.task-field-grid {
  grid-template-columns: 1fr;
}

.context-field-grid {
  grid-template-columns: 1fr;
}

/* Notes edit form: title + context side-by-side on desktop, stacked
   on mobile (inherits from .field-grid's 720px breakpoint). Title
   takes the wider column. */
@media (min-width: 720px) {
  .notes-edit-meta {
    grid-template-columns: minmax(0, 1fr) 220px;
  }
}

.task-estimate-field {
  max-width: 520px;
}

.birthday-control {
  align-content: start;
}

.birthday-no-year {
  color: var(--mx-text-muted);
  font-size: 0.92rem;
}

@media (min-width: 720px) {
  .field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-grid-span-2 {
    grid-column: 1 / -1;
  }
}

@media (min-width: 900px) {
  .datetime-pair {
    grid-template-columns: minmax(0, 1fr) minmax(160px, 220px);
  }
}

@media (min-width: 1180px) {
  .context-field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 12px;
}

/* Used on the MCP consent screen where Deny/Allow flank the dialog —
   the destructive-and-affirmative pair reads better with space between
   them than crammed against the right edge. */
.form-actions-split {
  justify-content: space-between;
}

.sticky-actions {
  background: var(--mx-bg);
  border-top: 1px solid var(--mx-border);
  bottom: calc(var(--mx-mobile-tabbar-height) + env(safe-area-inset-bottom));
  margin: 12px -16px 0;
  padding: 12px 16px;
  position: sticky;
  z-index: 10;
}

@media (min-width: 860px) {
  .sticky-actions {
    border-top: 0;
    bottom: 0;
    margin-left: 0;
    margin-right: 0;
    padding: 8px 0;
  }
}

.maintenance-section {
  border-color: color-mix(in srgb, var(--mx-system) 42%, var(--mx-border));
}

.linked-items,
.people-chips,
.draft-attachments {
  list-style: none;
  margin: 0;
  padding: 0;
}

.linked-items li,
.draft-attachments li {
  border-bottom: 1px solid var(--mx-border);
  padding: 10px 0;
}

.linked-items li:last-child,
.draft-attachments li:last-child {
  border-bottom: 0;
}

.people-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.people-chips li {
  align-items: center;
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: 999px;
  display: inline-flex;
  gap: 4px;
  padding: 4px 6px 4px 12px;
}

.chip-name {
  color: var(--mx-text);
  text-decoration: none;
}

.chip-remove {
  background: transparent;
  border: 0;
  color: var(--mx-text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  margin: 0;
  min-height: 34px;
  padding: 4px 8px;
}

.add-person {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}

.add-person input[type="text"] {
  flex: 1 1 220px;
  margin: 0;
}

.suggestions {
  flex-basis: 100%;
}

.suggestion-list {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  display: grid;
  gap: 2px;
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
}

.suggestion {
  background: transparent;
  border: 0;
  border-radius: var(--mx-radius-sm);
  color: var(--mx-text);
  cursor: pointer;
  margin: 0;
  min-height: 40px;
  padding: 8px 10px;
  text-align: left;
}

.suggestion:hover {
  background: var(--mx-surface);
}

.suggestion-empty {
  color: var(--mx-text-muted);
  margin: 6px 0 0;
}

.linked-people .error {
  color: var(--mx-system);
}

/* People */

.person-grid {
  display: grid;
  gap: 10px;
}

.person-card {
  align-items: center;
  grid-template-columns: minmax(0, 1fr);
}

.person-card > span:first-child,
.person-card-side {
  display: grid;
  gap: 3px;
}

.person-card-side {
  align-items: start;
  /* Mobile: pin children (context lozenge, item-count) to the column
     start so the lozenge stays content-sized instead of stretching into
     a CTA-looking pill. Desktop reverts to `end` so the card's
     two-column layout reads correctly. */
  justify-items: start;
}

@media (min-width: 720px) {
  .person-card {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .person-card-side {
    justify-items: end;
  }
}

/* Settings and diagnostics */

.setting-field {
  border-bottom: 1px solid var(--mx-border);
  padding-bottom: 14px;
}

.setting-field + .setting-field {
  margin-top: 14px;
}

/* Schedules editor (structured rows for cron settings) */
.schedules-field .schedules-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0;
}
.schedule-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  background: var(--mx-surface);
}
.schedule-row input[type=time] {
  margin: 0;
  width: 8em;
}
.schedule-row .schedule-context {
  margin: 0;
  width: auto;
}
.schedule-days {
  display: flex;
  gap: 2px;
}
.schedule-day {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius-sm);
  cursor: pointer;
  font-size: 0.78em;
  font-weight: 600;
  color: var(--mx-text-muted);
  user-select: none;
}
.schedule-day input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.schedule-day:has(input:checked) {
  background: var(--mx-accent-soft, var(--mx-accent));
  color: var(--mx-accent, white);
  border-color: var(--mx-accent);
}
.schedule-remove {
  margin-left: auto;
  font-size: 1.1em;
  line-height: 1;
  padding: 2px 8px;
}
.schedules-add {
  margin-top: 4px;
}

/* Grouped fieldsets on /settings. Each group is a thin card with a
   semantic <legend> for screen readers and a one-line rubric. */
.settings-group {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  display: grid;
  gap: 14px;
  margin: 0 0 16px;
  padding: 14px 16px;
}
.settings-group-legend {
  display: grid;
  gap: 2px;
  padding: 0 4px;
}
.settings-group-label {
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.25;
}

/* Advanced section — visually quieter than a regular group; collapsed
   by default. Operators can still expand and edit, but it's out of
   the day-to-day attention path. */
.settings-advanced {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  margin: 0 0 16px;
  padding: 0;
}
.settings-advanced summary {
  cursor: pointer;
  display: grid;
  gap: 2px;
  list-style: none;
  padding: 12px 16px;
}
.settings-advanced summary::-webkit-details-marker { display: none; }
.settings-advanced summary::before {
  content: "▸";
  color: var(--mx-text-muted);
  display: inline-block;
  margin-right: 8px;
  transition: transform var(--mx-motion-fast) var(--mx-ease-standard);
}
.settings-advanced[open] summary::before { transform: rotate(90deg); }
.settings-advanced-label {
  font-size: 0.95rem;
  font-weight: 650;
}
.settings-advanced-body {
  border-top: 1px solid var(--mx-border);
  display: grid;
  gap: 14px;
  padding: 14px 16px;
}

.settings-saved,
.settings-error {
  border-radius: var(--mx-radius);
  padding: 12px 14px;
}

.settings-saved {
  background: color-mix(in srgb, var(--mx-reference) 14%, var(--mx-surface));
  border: 1px solid color-mix(in srgb, var(--mx-reference) 55%, var(--mx-border));
}

.settings-error {
  background: var(--mx-system-soft);
  border: 1px solid var(--mx-system);
  color: var(--mx-system);
}

.diagnostic-list {
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  overflow: hidden;
}

.diagnostic-row,
.detail-list {
  background: var(--mx-surface-muted);
}

.diagnostic-row {
  align-items: center;
  border-bottom: 1px solid var(--mx-border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 12px;
}

.diagnostic-row:last-child {
  border-bottom: 0;
}

.diagnostic-row time {
  color: var(--mx-text-muted);
  font-size: 0.84rem;
  text-align: right;
}

.detail-list {
  border-radius: var(--mx-radius);
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  margin: 0;
  padding: 12px;
}

.detail-list dt {
  color: var(--mx-text-muted);
  font-weight: 700;
  padding: 6px 12px 6px 0;
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  padding: 6px 0;
}

/* Login */

.login-wrap {
  margin: 12vh auto 0;
  max-width: 360px;
}

.login-wrap h2 {
  margin-top: 0;
}

@media (max-width: 520px) {
  .page-header,
  .detail-header {
    display: grid;
  }

  .muted-time {
    text-align: left;
  }

  .more-actions[open] {
    flex-basis: 100%;
  }

  .button,
  button.button,
  a.button {
    width: 100%;
  }

  .big-search .search-submit,
  .big-search button.search-submit {
    width: 56px;
  }

  .item-actions .button,
  .item-actions button.button,
  .item-actions a.button {
    flex: 1 1 auto;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --mx-motion-fast: 0.01ms;
    --mx-motion-medium: 0.01ms;
    --mx-motion-slow: 0.01ms;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}


/* -----------------------------------------------------------------
   Chat home (PR 3 of chat-as-home). Replaces the old home-search +
   home-capture sections. The composer docks at the bottom; the
   transcript fills the space between; embedded item cards sit
   beneath assistant bubbles as first-class chat content.
   ----------------------------------------------------------------- */

.chat-page {
  display: grid;
  gap: 14px;
  /* Reserve space for the fixed-bottom composer + the mobile tabbar
     so the last bubble isn't hidden behind them. The composer is
     positioned in normal flow on desktop, fixed on mobile. */
  padding-bottom: 12px;
}

.chat-header {
  align-items: center;
  display: flex;
  justify-content: flex-end;
}
.chat-clear-form {
  margin: 0;
}
.chat-clear-btn {
  font-size: 0.82rem;
}

.chat-transcript {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 30vh;
  padding: 4px 0;
}

.chat-turn {
  display: grid;
  gap: 10px;
}
.chat-turn-user {
  /* Right-align user bubbles to mirror the conversational mental
     model the operator already has from Claude, iMessage, etc. */
  justify-items: end;
}
.chat-turn-assistant {
  justify-items: stretch;
}

.chat-bubble {
  border-radius: var(--mx-radius);
  max-width: 88ch;
  padding: 10px 14px;
}
.chat-bubble-user {
  background: color-mix(in srgb, var(--mx-focus) 12%, var(--mx-surface));
  border: 1px solid color-mix(in srgb, var(--mx-focus) 30%, var(--mx-border));
}
.chat-bubble-user p {
  margin: 0;
  white-space: pre-wrap;
}
.chat-bubble-assistant {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
}
.chat-prose {
  /* render_markdown puts content in a div; tighten its default
     paragraph margins so the bubble feels conversational, not
     document-like. */
}
.chat-prose > :first-child {
  margin-top: 0;
}
.chat-prose > :last-child {
  margin-bottom: 0;
}
.chat-prose p {
  margin: 0.4em 0;
}
.chat-prose ul,
.chat-prose ol {
  margin: 0.4em 0;
  padding-left: 1.5em;
}

.chat-error {
  color: var(--mx-system);
  margin: 8px 0 0;
}

.chat-cards {
  display: grid;
  gap: 10px;
}

.chat-undo-row {
  margin: 8px 0 0;
}
.button-quiet {
  background: transparent;
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text-muted);
  font-size: 0.84rem;
  margin: 0;
  padding: 4px 10px;
}
.button-quiet:hover {
  border-color: var(--mx-border-strong);
  color: var(--mx-text);
}

.chat-composer {
  align-items: stretch;
  background: var(--mx-bg);
  border-top: 1px solid var(--mx-border);
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  margin: 8px 0 0;
  padding: 10px 0 6px;
}
.chat-composer textarea {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  font-size: 0.95rem;
  margin: 0;
  min-height: 2.6rem;
  padding: 8px 12px;
  resize: vertical;
}
.chat-composer textarea:focus {
  border-color: var(--mx-focus);
  outline: none;
}
.chat-send {
  align-self: stretch;
  margin: 0;
}
/* "Thinking…" indicator. Stays in the DOM at opacity:0 so we can
   fade it in/out via class toggle instead of the harsh `hidden`
   attribute. The JS handler on the composer flips .is-visible. */
.chat-thinking {
  color: var(--mx-text-muted);
  font-size: 0.84rem;
  grid-column: 1 / -1;
  margin: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity var(--mx-motion-fast) var(--mx-ease-out),
    transform var(--mx-motion-fast) var(--mx-ease-out);
}
.chat-thinking.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Slide-up entry for new chat bubbles. HTMX adds the .htmx-added
   class while content is settling; we time the animation to land
   within the settle:300ms window declared on the composer's
   hx-swap so the class is still present when the animation runs. */
@keyframes mx-chat-turn-slide-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* Chat-turn slide-in is more pronounced than the generic htmx-added
   animation (12px vs 4px) because new bubbles need to feel like they
   came from the composer below; the !important wins specificity over
   the universal `.htmx-added` rule earlier in the file. */
.chat-turn.htmx-added {
  animation: mx-chat-turn-slide-in var(--mx-motion-medium) var(--mx-ease-out) !important;
}
@media (prefers-reduced-motion: reduce) {
  .chat-turn.htmx-added { animation: none !important; }
}

/* Mobile: dock the composer above the tabbar. The tabbar height is
   var(--mx-mobile-tabbar-height); we add it so the composer doesn't
   collide with the nav. */
@media (max-width: 720px) {
  .chat-composer {
    background: var(--mx-bg);
    border-top: 1px solid var(--mx-border);
    bottom: calc(var(--mx-mobile-tabbar-height) + env(safe-area-inset-bottom));
    left: 0;
    margin: 0;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    z-index: 30;
  }
  .chat-page {
    /* Reserve scroll-tail so the last bubble isn't hidden under the
       fixed composer + tabbar stack. */
    padding-bottom: calc(var(--mx-mobile-tabbar-height) + 120px);
  }
}


/* -----------------------------------------------------------------
   Shopping / errand lists.
   - Index page (lists.html): create form + nested tree.
   - Detail page (list_detail.html): wraps _list_card.html + add form.
   - _list_card.html: the card itself, reused on the chat embed.
   ----------------------------------------------------------------- */

.lists-page,
.list-detail-page {
  display: grid;
  gap: 18px;
}

.lists-create-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 160px;
}
.lists-create-aliases {
  grid-column: 1 / -1;
}

/* Single-item add: Item input + small Qty + Add button, all on one
   row when there's room. Items input grows, Qty stays compact, Add
   sits flush right. align-items: end so the inputs and button bottom-
   align (the label text adds an extra row above the input). */
/* Add-item bar on /lists/<id>. Three columns stretch to the tallest
   child's height so the input / select / button line up cleanly.
   Pico defaults a bottom margin on form fields — stripped here so the
   row doesn't push the section padding around. The qty column is wide
   enough for the "Qty" placeholder + select arrow chrome. */
.list-add-grid {
  align-items: stretch;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) 110px auto;
}
.list-add-grid-noqty {
  grid-template-columns: minmax(0, 1fr) auto;
}
.list-add-grid > * { margin: 0; }
.list-add-grid input,
.list-add-grid select {
  margin: 0;
  min-width: 0;
}
.list-add-qty { text-align: center; }
.list-add-grid .button {
  align-self: stretch;
  margin: 0;
  white-space: nowrap;
}

/* Drill-in disclosure for forms we want collapsed by default — eg.
   /lists "New list" and /lists/<id> "Edit list". The form is power
   that doesn't deserve a permanent slot on the page (chat agent +
   quick-add are the high-frequency creation surfaces); the disclosure
   gets the operator there in one tap without crowding the steady
   state. DESIGN_LANGUAGE §2.3 (power-behind-drill-in). */
.form-disclosure {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  box-shadow: var(--mx-shadow);
  padding: 0;
}
.form-disclosure > summary {
  align-items: center;
  color: var(--mx-text);
  cursor: pointer;
  display: flex;
  font-size: 1rem;
  font-weight: 700;
  gap: 10px;
  justify-content: space-between;
  list-style: none;
  min-height: 44px;
  padding: 12px 16px;
}
.form-disclosure > summary::-webkit-details-marker { display: none; }
.form-disclosure > summary::after { display: none; }
.form-disclosure > summary::before {
  color: var(--mx-text-muted);
  content: "▸";
  display: inline-block;
  font-size: 0.78rem;
  transition: transform var(--mx-motion-fast) var(--mx-ease-standard);
}
.form-disclosure[open] > summary::before { transform: rotate(90deg); }
.form-disclosure[open] > summary {
  border-bottom: 1px solid var(--mx-border);
}
.form-disclosure > .form-disclosure-body {
  padding: 16px;
}

/* Quick-add bar at the top of /lists. Input + Add button on one row,
   no labels (the input's purpose is obvious from page context). */
.lists-quick-add-form {
  align-items: stretch;
  display: flex;
  gap: 10px;
  margin: 0;
}
.lists-quick-add-form input[name="text"] {
  flex: 1 1 auto;
  margin: 0;
  min-width: 0;
}
.lists-quick-add-form .button {
  align-self: stretch;
  /* basis: max-content forces the Add button to size to its label even
     when Pico's `button[type="submit"] { width: 100% }` rule otherwise
     wins the cascade (specificity tied with .button, source-order
     normally favors memex.css but flex-basis resolution still grabs
     the 100% via `width`). With basis: max-content, the button is
     content-sized and the input keeps the rest of the row. */
  flex: 0 0 max-content;
  margin: 0;
}

/* Per-row inline edit — collapsed by default behind a small ⋯ summary
   button. Opens to a grid that mirrors the add-row layout so the
   operator's eye doesn't have to retrain. */
.list-row-edit {
  margin-left: 8px;
}
.list-row-edit > summary {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--mx-radius-sm);
  color: var(--mx-text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  list-style: none;
  padding: 2px 8px;
}
.list-row-edit > summary::-webkit-details-marker { display: none; }
/* Pico paints a right-aligned chevron via `summary::after` on its own
   details styles. The row already shows an explicit `⋯` glyph; the
   extra chevron reads as a "tap to navigate" hint when the row's tap
   target actually toggles the checkbox. Suppress it. */
.list-row-edit > summary::after { display: none; }
.list-row-edit > summary:hover {
  background: var(--mx-surface-muted);
  color: var(--mx-text);
}
.list-row-edit[open] > summary {
  background: var(--mx-surface-muted);
  border-color: var(--mx-border);
  color: var(--mx-text);
}
.list-row-edit-form {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius-sm);
  box-shadow: var(--mx-shadow);
  display: grid;
  gap: 8px;
  /* Pop out below the row, spanning full row width, so the form isn't
     clipped to the narrow 4th column the summary lives in. The row's
     position:relative is the containing block. */
  left: 0;
  margin-top: 4px;
  padding: 10px;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 5;
}
.list-row-edit-grid {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 2fr) 80px minmax(0, 3fr);
}
.list-row-edit-grid-noqty {
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
}
.list-row-edit-grid input,
.list-row-edit-grid select { min-width: 0; }
.list-row-edit-notes::placeholder { font-style: italic; }
.list-row-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.list-row-edit-actions .button { margin: 0; }

/* Children chip strip on a parent list's detail view. One tap takes
   the operator into a child list without bouncing back to /lists. */
.list-children-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
}
.list-children-chip {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: 999px;
  color: var(--mx-text);
  font-size: 0.82rem;
  padding: 4px 12px;
  text-decoration: none;
  transition: border-color var(--mx-motion-fast) var(--mx-ease-standard);
}
.list-children-chip:hover {
  border-color: var(--mx-border-strong);
  color: var(--mx-text);
}

@media (max-width: 520px) {
  .lists-create-grid { grid-template-columns: 1fr; }
  .list-add-grid {
    grid-template-columns: 1fr 110px;
  }
  .list-add-grid-noqty {
    grid-template-columns: 1fr;
  }
  /* Add button drops to its own row beneath the inputs on mobile. */
  .list-add-grid .button {
    grid-column: 1 / -1;
    justify-self: stretch;
  }
  .list-row-edit-grid,
  .list-row-edit-grid-noqty {
    grid-template-columns: 1fr;
  }
}

/* Tree on /lists. Two levels max in MVP. */
.lists-tree {
  display: grid;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.lists-tree-node {
  margin: 0;
}
.lists-tree-link {
  align-items: center;
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  color: var(--mx-text);
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  text-decoration: none;
  transition: border-color var(--mx-motion-fast) var(--mx-ease-standard);
}
.lists-tree-link:hover {
  border-color: var(--mx-border-strong);
  color: var(--mx-text);
}
.lists-tree-name {
  font-weight: 650;
}
.lists-tree-count {
  color: var(--mx-text-muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}
.lists-tree-aliases {
  color: var(--mx-text-muted);
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.lists-tree-aliases small {
  background: var(--mx-surface-muted);
  border-radius: 999px;
  font-size: 0.7rem;
  padding: 1px 8px;
}
.lists-tree-parent .lists-tree-children {
  display: grid;
  gap: 4px;
  list-style: none;
  margin: 6px 0 0 18px;
  padding: 0;
  /* Visual hint that these are nested under the parent. */
  border-left: 2px solid var(--mx-border);
  padding-left: 12px;
}
.list-card {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius);
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 14px 16px;
}

.list-card-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--mx-border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding-bottom: 10px;
}

.list-card-titles {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  min-width: 0;
}

.list-card-name {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0;
}

.list-card-breadcrumb {
  color: var(--mx-text-muted);
  font-size: 0.82rem;
  margin: 0;
}

.list-card-aliases {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
}

.list-alias {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: 999px;
  color: var(--mx-text-muted);
  display: inline-block;
  font-size: 0.7rem;
  padding: 1px 8px;
}

.list-card-clear-form { margin: 0; }
.list-clear-btn { font-size: 0.82rem; }

.list-rows {
  display: grid;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.list-row {
  align-items: center;
  cursor: pointer;
  display: grid;
  gap: 10px;
  grid-template-columns: auto 1fr auto auto;
  padding: 6px 4px;
  position: relative;
  /* The whole row is tappable — JS in base.html delegates clicks to
     the inner toggle form. Hover gives a subtle background hint so
     it reads as interactive. */
  border-radius: var(--mx-radius-sm);
  transition: background var(--mx-motion-fast) var(--mx-ease-standard);
}
.list-row:hover {
  background: var(--mx-surface-muted);
}

.list-row-toggle { margin: 0; }

/* Bumped specificity (.list-row-toggle .list-checkbox) so we beat
   Pico's `button[type=submit] { width: 100% }`. Without that bump the
   button stretches to 100% of its form, which is auto-sized to its
   button content, which collapses both to ~2px (pipe-shaped). */
.list-row-toggle .list-checkbox {
  align-items: center;
  background: var(--mx-surface);
  border: 1.5px solid var(--mx-border-strong);
  border-radius: 6px;
  box-sizing: border-box;
  color: transparent;
  cursor: pointer;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 0.84rem;
  font-weight: 700;
  height: 24px;
  justify-content: center;
  line-height: 1;
  margin: 0;
  min-width: 24px;
  padding: 0;
  transition:
    background var(--mx-motion-fast) var(--mx-ease-standard),
    border-color var(--mx-motion-fast) var(--mx-ease-standard),
    color var(--mx-motion-fast) var(--mx-ease-standard);
  width: 24px;
}
.list-row-toggle .list-checkbox:hover {
  border-color: var(--mx-focus);
}
.list-row-toggle .list-checkbox.is-checked {
  background: var(--mx-focus);
  border-color: var(--mx-focus);
  color: var(--mx-context-active-text);
}

.list-row-body {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.list-row-text {
  font-size: 0.95rem;
}
.list-row-qty {
  background: var(--mx-surface-muted);
  border-radius: var(--mx-radius-sm);
  color: var(--mx-text);
  font-size: 0.78rem;
  font-weight: 650;
  margin-right: 4px;
  padding: 1px 6px;
}
.list-row-notes {
  color: var(--mx-text-muted);
  display: block;
  font-size: 0.82rem;
  font-style: italic;
  margin-top: 2px;
}
.list-row-checked .list-row-text {
  color: var(--mx-text-muted);
  text-decoration: line-through;
  text-decoration-color: var(--mx-border-strong);
}
.list-row-checked .list-row-qty {
  opacity: 0.6;
}

/* The "this came from a different list" lozenge — driven by the
   spec-locked behavior that viewing a parent shows every child's
   items with their origin indicated. */
.list-row-source {
  background: var(--mx-surface-muted);
  border: 1px solid var(--mx-border);
  border-radius: 999px;
  color: var(--mx-text-muted);
  font-size: 0.7rem;
  padding: 2px 8px;
  white-space: nowrap;
}

/* List-detail tabs (Current / History). Thin underline indicates the
   active surface; keeps the page header visually quiet so the list
   contents own the eye. */
.list-tabs {
  border-bottom: 1px solid var(--mx-border);
  display: flex;
  gap: 4px;
  margin: 0 0 14px;
}
.list-tab {
  border-bottom: 2px solid transparent;
  color: var(--mx-text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: -1px;  /* overlap the parent border for the active line */
  padding: 8px 14px;
  text-decoration: none;
  transition:
    border-color var(--mx-motion-fast) var(--mx-ease-standard),
    color var(--mx-motion-fast) var(--mx-ease-standard);
}
.list-tab:hover {
  color: var(--mx-text);
}
.list-tab.is-active {
  border-bottom-color: var(--mx-focus);
  color: var(--mx-text);
}

/* History tab. Each row is text + meta on the left, Re-add button
   right. Quieter than the active list rows because the operator is
   browsing, not acting. */
.list-history-rows {
  display: grid;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.list-history-row {
  align-items: center;
  border-radius: var(--mx-radius-sm);
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
  padding: 8px 4px;
}
.list-history-body {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.list-history-text {
  font-size: 0.95rem;
}
.list-history-meta {
  color: var(--mx-text-muted);
  display: inline-flex;
  flex-wrap: wrap;
  font-size: 0.78rem;
  gap: 8px;
}
.list-history-when {
  color: var(--mx-text-muted);
}
.list-history-count {
  color: var(--mx-text-muted);
}
.list-history-readd { margin: 0; }
.list-history-readd .button { margin: 0; }
.list-history-readd.readd-done .button {
  background: color-mix(in srgb, var(--mx-focus) 18%, var(--mx-surface));
  border-color: color-mix(in srgb, var(--mx-focus) 55%, var(--mx-border));
  color: var(--mx-text);
  cursor: default;
}

/* ---- Meetings + projects (read views) ---------------------------- */
.meeting-block {
  margin-top: 24px;
}
.meeting-block-title {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--mx-text-muted);
  margin: 0 0 8px;
}
.meeting-block-raw {
  margin-top: 24px;
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius, 10px);
  padding: 10px 14px;
  background: var(--mx-surface);
}
.meeting-block-raw > summary {
  cursor: pointer;
  color: var(--mx-text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.meeting-raw-pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 12px 0 0;
  font-size: 0.9rem;
  color: var(--mx-text);
}

/* Provenance highlight (==mark== from meeting Process; app-wide). Calm
   yellow tint, dark text — NOT a green/red signal (deuteranomaly). */
.markdown-body mark {
  background: color-mix(in srgb, var(--ctp-yellow) 32%, var(--mx-surface));
  color: var(--mx-text);
  padding: 0 3px;
  border-radius: 4px;
}

/* ---- Meeting / project edit affordances -------------------------- */
.meeting-actions { margin-top: 12px; }
.meeting-edit { margin-top: 14px; }
.meeting-edit > summary {
  cursor: pointer;
  color: var(--mx-text-muted);
  font-size: 0.85rem;
}
.meeting-edit.inline-create > summary { list-style: none; display: inline-block; }
.meeting-edit.inline-create > summary::-webkit-details-marker { display: none; }
.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  max-width: 640px;
}
.stacked-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--mx-text-muted);
}
.stacked-form input[type="text"],
.stacked-form select,
.stacked-form textarea {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  background: var(--mx-surface);
  color: var(--mx-text);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius, 8px);
}
.stacked-form textarea { resize: vertical; min-height: 90px; }
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.inline-form select,
.inline-form input[type="text"] {
  font: inherit;
  padding: 6px 9px;
  background: var(--mx-surface);
  color: var(--mx-text);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius, 8px);
}
.autosave-status { font-size: 0.78rem; color: var(--mx-text-muted); }
.text-danger { color: var(--ctp-red, #e64553); }
.meeting-banner {
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: var(--mx-radius, 8px);
  background: color-mix(in srgb, var(--mx-focus) 14%, var(--mx-surface));
  border: 1px solid color-mix(in srgb, var(--mx-focus) 40%, var(--mx-border));
  color: var(--mx-text);
}
.project-member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.project-member-row .card-link { flex: 1; }
.project-chip-row { margin: 8px 0 4px; align-items: center; }
.project-chip-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--mx-text-muted);
}
