@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/fraunces-latin-600.woff2') format('woff2');
}

@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('/fonts/outfit-latin-var.woff2') format('woff2');
}

:root {
  color-scheme: light;
  --bg: #f5efe6;
  --surface: #faf6ee;
  --elev: #fcfcfc;
  --text: #2c241b;
  --text-2: #6b5c4c;
  --text-3: #9a8a7a;
  --line: #e8ddd0;
  --line-soft: #ede5d8;
  --fill: rgba(44, 36, 27, 0.06);
  --hover: rgba(44, 36, 27, 0.04);
  --accent: #111111;
  --accent-hover: #333333;
  --accent-contrast: #faf6ee;
  --red: #c53030;
  --rose: #b23a48;
  --orange: #9a6700;
  --yellow: #8a6d00;
  --lime: #5f7d00;
  --green: #2d8a56;
  --teal: #0f766e;
  --cyan: #0e7490;
  --blue: #2f6f9f;
  --indigo: #4f46a3;
  --purple: #6b46a3;
  --pink: #c2185b;
  --brown: #8a6a4a;
  --slate: #5b6b7a;
  --gray: #8a8a8a;
  --shadow-card: 0 1px 2px rgba(44, 36, 27, 0.04);
  --radius: 14px;
  --radius-sm: 6px;
  --control-height: 40px;
  --control-height-touch: 44px;
  --icon-size: 36px;
  --icon-size-touch: 40px;
  --settings-control-width: 170px;
  --sidebar-width: 280px;
  --list-red: var(--red);
  --list-rose: var(--rose);
  --list-orange: var(--orange);
  --list-yellow: var(--yellow);
  --list-lime: var(--lime);
  --list-green: var(--green);
  --list-teal: var(--teal);
  --list-cyan: var(--cyan);
  --list-blue: var(--blue);
  --list-indigo: var(--indigo);
  --list-purple: var(--purple);
  --list-pink: var(--pink);
  --list-brown: var(--brown);
  --list-slate: var(--slate);
  --list-gray: var(--gray);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #101010;
  --elev: #1c1c1c;
  --text: #e4e4e4;
  --text-2: #a0a0a0;
  --text-3: #737373;
  --line: #2a2a2a;
  --line-soft: #1e1e1e;
  --fill: rgba(228, 228, 228, 0.07);
  --hover: rgba(228, 228, 228, 0.05);
  --accent: #f5f5f5;
  --accent-hover: #cccccc;
  --accent-contrast: #101010;
  --red: #f87171;
  --rose: #fda4af;
  --orange: #fbbf24;
  --yellow: #fde047;
  --lime: #d9f99d;
  --green: #4ade80;
  --teal: #5eead4;
  --cyan: #67e8f9;
  --blue: #7cb3e0;
  --indigo: #a5b4fc;
  --purple: #a78bfa;
  --pink: #f9a8d4;
  --brown: #c9a27e;
  --slate: #94a3b8;
  --gray: #9a9a9a;
  --shadow-card: none;
}

* { box-sizing: border-box; }

::view-transition-old(root),
::view-transition-new(root) { animation-duration: 180ms; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 0s; }
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  overflow: hidden;
}

[hidden] { display: none !important; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

button, a, input, select, textarea, [tabindex] { touch-action: manipulation; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 22px; height: 22px; flex: none; }

/* ---------- Auth ---------- */

.auth {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: min(300px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}

.auth-mark { border-radius: 8px; }

.auth-card h1 {
  margin: 0;
  font-family: 'Fraunces', serif;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-sub {
  margin: 0 0 2px;
  font-size: 0.8rem;
  color: var(--text-2);
}

.auth-card input {
  width: 100%;
  height: var(--control-height);
  min-height: var(--control-height);
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.875rem;
  color: var(--text);
}

.auth-card input::placeholder { color: var(--text-3); }
.auth-card input:focus { outline: none; border-color: var(--accent); }

.auth-error {
  margin: 0;
  font-size: 0.78rem;
  color: var(--red);
}

/* One-time username gate for existing installs. */
.gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.gate-card {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

.gate-card h2 {
  margin: 0;
  font-family: 'Fraunces', serif;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gate-card p {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-2);
}

.gate-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gate-card input {
  width: 100%;
  height: var(--control-height);
  min-height: var(--control-height);
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.875rem;
  color: var(--text);
}

.gate-card input::placeholder { color: var(--text-3); }
.gate-card input:focus { outline: none; border-color: var(--accent); }
.gate-card .primary-btn { margin-top: 2px; }

body.gate-open {
  position: fixed;
  inset: 0;
  width: 100%;
  overscroll-behavior: none;
}

/* Keep the gate's two fields above the iPhone keyboard rather than centring
   the card underneath it. */
@media (max-width: 899px) {
  .gate-overlay {
    align-items: start;
    padding-top: calc(env(safe-area-inset-top) + 56px);
  }
}

.primary-btn {
  border: 0;
  border-radius: 5px;
  padding: 9px 16px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 550;
  font-size: 0.875rem;
  min-height: var(--control-height);
}

.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.secondary-btn {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 8px 16px;
  background: transparent;
  color: var(--text-2);
  font-weight: 550;
  font-size: 0.8125rem;
  min-height: var(--control-height);
}

.secondary-btn:hover { background: var(--fill); color: var(--text); }
.danger-text { color: var(--red); }

/* ---------- Shell ---------- */

.shell {
  display: flex;
  height: 100dvh;
  width: 100%;
}

.sidebar {
  width: var(--sidebar-width);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 12px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-right: 1px solid var(--line-soft);
  overflow-y: auto;
}

.sidebar-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding: 0;
}

.sidebar-head .tenant-switch { flex: 1; min-width: 0; margin: 0; }
.sidebar-head .head-actions { gap: 12px; align-self: center; }

.search-bar-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px 0 10px;
  background: var(--surface);
  border-radius: 10px;
  clip-path: inset(0 0 0 100%);
  opacity: 0;
  pointer-events: none;
  transition: clip-path 0.22s ease, opacity 0.16s ease;
}

.search-bar-overlay.open {
  clip-path: inset(0);
  opacity: 1;
  pointer-events: auto;
}

.search-overlay-ic { flex: none; width: 16px; height: 16px; color: var(--text-3); }

.search-bar-overlay input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--elev);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
  -webkit-appearance: none;
  appearance: none;
}

.search-bar-overlay input::placeholder { color: var(--text-3); }
.search-bar-overlay input:focus { outline: none; border-color: var(--accent); }
.search-bar-overlay input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-bar-close {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-3);
  font-family: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

.search-bar-close:hover { background: var(--hover); color: var(--text); }

.head-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: none;
}

/* Header actions are bare glyphs, Scrawl-style: no filled hover box. */
.head-actions .icon-btn {
  position: relative;
  width: auto;
  height: auto;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-2);
  opacity: 0.75;
  transition: opacity 0.15s, color 0.15s;
}

.head-actions .icon-btn:hover,
.head-actions .icon-btn:focus-visible {
  background: transparent;
  color: var(--text);
  opacity: 1;
}

.head-actions .icon-btn .ic { width: 18px; height: 18px; }

/* A non-overlapping invisible pad (32px) around each bare glyph. */
.head-actions .icon-btn::after { content: ""; position: absolute; inset: -7px; }

#view-menu { font-size: 1.25rem; line-height: 1; font-weight: 600; letter-spacing: 0.06em; }

#sidebar-menu-btn { display: grid; }

.wordmark {
  margin: 0;
  font-family: 'Fraunces', serif;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.icon-btn {
  position: relative;
  width: var(--icon-size);
  height: var(--icon-size);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-2);
  transition: all 0.15s;
}

.icon-btn:hover { background: var(--fill); color: var(--text); }
.icon-btn .ic { width: 17px; height: 17px; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small .ic { width: 15px; height: 15px; }

.refresh-btn { flex: none; }
.refresh-btn:disabled { opacity: 0.45; }
.refresh-btn.loading .ic { animation: spin 0.7s linear infinite; transform-origin: center; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .refresh-btn.loading .ic { animation: none; }
}

/* ---------- Pull to refresh (touch phones) ----------
   The refresh glyph is a desktop/web affordance: touch devices in the mobile
   layout pull down at the top of a scroller instead. The pill is fixed and
   slides into view as the pull progresses. */
@media (max-width: 899px) and (pointer: coarse) {
  .refresh-btn { display: none; }
}

.pull-refresh {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 6px);
  left: 50%;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--elev);
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -36px);
  transition: transform 0.22s ease, opacity 0.18s ease;
  will-change: transform, opacity;
}

.pull-refresh .ic { width: 15px; height: 15px; }
.pull-refresh.armed { color: var(--text); }
.pull-refresh.pulling { transition: none; }
.pull-refresh.refreshing .ic { animation: spin 0.7s linear infinite; transform-origin: center; }

@media (prefers-reduced-motion: reduce) {
  .pull-refresh { transition: none; }
  .pull-refresh.refreshing .ic { animation: none; }
}

/* ---------- Touch targets (coarse pointers) ----------
   Visual sizes stay as above; an invisible ::after pad expands the tap area
   to 44px without shifting layout or neighbours. */
@media (pointer: coarse) {
  .icon-btn::after,
  .back-btn::after,
  .check::after,
  .row-copy::after,
  .row-edit::after,
  .row-delete::after,
  .list-grip::after,
  .new-list-btn::after,
  .history-undo::after,
  .sort-completed-filter::after,
  .swatch::after {
    content: "";
    position: absolute;
    pointer-events: auto;
  }
  .icon-btn::after { inset: -4px; }
  .icon-btn.small::after { inset: -6px; }
  .back-btn { position: relative; }
  .back-btn::after { inset: -2px -6px; }
  .history-undo { position: relative; }
  .history-undo::after { inset: -10px -6px; }
  .check::after { inset: -10px; }
  .sort-completed-filter::after { inset: -8px -4px; }
  .row-copy::after { inset: -5px; }
  .row-edit::after { inset: -5px; }
  .row-delete::after { inset: -5px; }
  .list-grip::after { inset: -11px; }
  .new-list-btn::after { inset: -11px; }
  .swatch::after { inset: -5px; }
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0;
}

.search-ic {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
}

.search input {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 10px 9px 32px;
  background: var(--elev);
  color: var(--text);
  font-size: 0.8125rem;
  -webkit-appearance: none;
  appearance: none;
  appearance: none;
}

.search input::placeholder { color: var(--text-3); }
.search input:focus { outline: none; border-color: var(--accent); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }



/* ---------- Day Peek ---------- */

.day-peek {
  display: flex;
  flex: none;
  flex-direction: column;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: color-mix(in srgb, var(--text) 5%, var(--surface));
  overflow: hidden;
}

.day-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  padding: 6px;
}

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 1px;
  min-width: 0;
  padding: 7px 2px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  outline: 1.5px solid transparent;
  outline-offset: 1px;
  transition: background 200ms ease, outline-color 200ms ease, color 200ms ease;
}

@media (hover: hover) {
  .day-cell:hover { background: var(--hover); }
}

.day-cell.is-today {
  background: color-mix(in srgb, var(--text) 12%, var(--surface));
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.day-cell.is-selected { outline-color: var(--accent); }

.day-weekday {
  max-width: 100%;
  overflow: hidden;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-transform: uppercase;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.75;
}

.day-cell.is-selected .day-weekday { font-weight: 700; opacity: 1; }

.day-date {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.day-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 10px;
  min-width: 12px;
  margin-top: 1px;
  font-size: 0.5625rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.day-dot {
  width: 4px;
  height: 4px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
}

.day-indicator.is-count { opacity: 0.85; }

.day-card {
  overflow: hidden;
  border: 0;
  border-top: 1px solid var(--line-soft);
  border-radius: 0;
  background: var(--surface);
}

.day-card-head {
  padding: 11px 14px 9px;
  border-bottom: 1px solid var(--line-soft);
}

.day-card-title {
  margin: 0;
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.day-card-meta {
  margin: 2px 0 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.day-card-list .reminder { border-bottom: 1px solid var(--line); }
.day-card-list .reminder:last-child { border-bottom: 0; }

.day-peek-empty {
  margin: 0;
  padding: 26px 14px;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-3);
}

@media (prefers-reduced-motion: reduce) {
  .day-cell { transition: none; }
  .badge.value-pop,
  .view-count.value-pop,
  .day-indicator.value-pop,
  .day-strip.rolling .day-cell,
  .empty { animation: none; }
  .list-progress-fill,
  .list-ring { transition: none; }
}

.nav { display: flex; flex-direction: column; gap: 1px; }

.nav-row, .list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  border-radius: 5px;
  padding: 6px 8px;
  background: transparent;
  text-align: left;
  font-size: 0.875rem;
  color: var(--text);
}

.nav-row:hover, .list-row:hover { background: var(--hover); }
.nav-row.active, .list-row.active { background: var(--fill); }

.nav-ic {
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--text-3);
}

.nav-ic .ic { width: 17px; height: 17px; }
.nav-row.active .nav-ic { color: var(--accent); }

.nav-row::after {
  content: "";
  width: 22px;
  height: 22px;
  flex: none;
}

.nav-label { flex: 1; font-weight: 500; padding-left: 2px; }
.nav-row.active .nav-label { font-weight: 600; }

.badge {
  min-width: 20px;
  flex: none;
  text-align: right;
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.badge-overdue { color: var(--red); font-weight: 600; }

/* A bare plus matching the list grips: same 22px box and right edge. */
.new-list-btn {
  position: relative;
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-3);
  opacity: 0.55;
  transition: opacity 0.15s;
}

.new-list-btn .ic { width: 15px; height: 15px; }
/* A bare glyph like the grips: no boxed hover fill or colour jump. */
.new-list-btn:hover,
.new-list-btn:focus-visible { opacity: 0.9; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* 8px matches .list-row's right padding so the plus lines up with the grips. */
  padding: 0 8px 0 0;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.lists { display: flex; flex-direction: column; gap: 1px; }

.list-row .list-dot {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 50%;
  background: var(--c);
  margin: 0 10px 0 0;
}

.list-row .list-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

/* Apple-style list rows: divider between every row and a tall,
   fat-finger-proof touch target. */
.list-row {
  min-height: 56px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
}

.list-row .list-dot {
  width: 14px;
  height: 14px;
}

.list-row .badge { font-size: 0.8125rem; }

/* Sidebar list progress (bar with counts / ring on the dot). */
.list-row { flex-wrap: wrap; }

.list-progress {
  flex-basis: 100%;
  height: 3px;
  margin: 5px 4px 0 34px;
  border-radius: 2px;
  background: var(--fill);
  overflow: hidden;
}

.list-progress-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--c);
  transition: width 0.28s ease;
}

.list-progress-counts {
  flex-basis: 100%;
  margin: 4px 4px 0 34px;
  font-size: 0.72rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

@property --p {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

.list-ring {
  position: relative;
  transition: --p 0.28s ease;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0 2px 0 0;
  display: grid;
  place-items: center;
}

.list-ring::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--fill) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
}

.list-ring .list-dot {
  position: relative;
  width: 14px;
  height: 14px;
  margin: 0;
}

.list-grip {
  position: relative;
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 5px;
  color: var(--text-3);
  opacity: 0.55;
  cursor: grab;
  touch-action: none;
  transition: opacity 0.15s, background 0.15s;
}

.list-grip .ic { width: 15px; height: 15px; }
.list-row:hover .list-grip { opacity: 0.9; }
.list-row:focus-visible .list-grip { opacity: 1; }
.list-grip:hover { background: var(--fill); }

.list-lock {
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--text-3);
  opacity: 0.5;
}
.list-lock .ic { width: 14px; height: 14px; }

.list-row.dragging {
  opacity: 0.3;
  background: var(--fill);
}

.list-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.list-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }

.list-drag-ghost {
  position: fixed;
  z-index: 100;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.26);
  opacity: 0.97;
  pointer-events: none;
}

.list-drag-ghost .list-grip { opacity: 0.75; }

body.list-dragging {
  user-select: none;
  cursor: grabbing;
}

body.list-dragging .list-grip { cursor: grabbing; }

@media (hover: none) {
  .list-grip { opacity: 0.55; }
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
  display: none;
  flex-direction: column;
  gap: 1px;
}

.text-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  padding: 6px 8px;
  min-height: 40px;
  border-radius: 5px;
  font-size: 0.8125rem;
  color: var(--text-2);
  text-align: left;
  transition: all 0.15s;
}

.text-btn:hover { background: var(--hover); color: var(--text); }
.text-btn:disabled { opacity: 0.4; cursor: default; background: transparent; color: var(--text-2); }
.text-btn .foot-ic {
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.text-btn .foot-ic .ic { width: 17px; height: 17px; }

/* ---------- Main ---------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  /* Same canvas as Home so both screens share one background. */
  background: var(--surface);
}

.main-head {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 22px 36px 10px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.back-btn {
  display: none;
  align-items: center;
  gap: 2px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 0.875rem;
  padding: 10px 0;
  margin-right: -6px;
}

.back-btn .ic { width: 18px; height: 18px; }
.back-btn:hover { color: var(--text); }

.title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.title-wrap h2 {
  margin: 0;
  font-family: 'Fraunces', serif;
  font-size: 1.375rem;
  font-weight: 600;
  font-optical-sizing: none;
  font-variation-settings: 'opsz' 22;
  letter-spacing: -0.025em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-count {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.main-search { display: none; }
.main-search input { flex: 1; min-width: 0; }

.sort-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 12px;
  width: auto;
  max-width: 100%;
  margin: 12px 24px 0;
  padding: 0;
  font-size: 0.75rem;
  color: var(--text-3);
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  padding: 0;
  flex: none;
}

.sort-control > span {
  flex: none;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-3);
}

.sort-control select {
  width: auto;
  max-width: 150px;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 0.75rem;
  padding: 0 2px;
}

.sort-control select:focus { outline: none; color: var(--text); }

/* Completed filter: a compact check + count at the far right of the sort bar. */
.sort-completed-filter {
  position: relative;
  margin-left: auto;
  gap: 3px;
  min-width: 0;
  height: 28px;
  padding: 0 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.sort-completed-filter .ic { width: 13px; height: 13px; }

.sort-completed-filter[aria-pressed="true"] {
  background: var(--fill);
  color: var(--text);
}

.sort-completed-filter:disabled {
  opacity: 0.45;
  cursor: default;
}

@media (hover: hover) {
  .sort-completed-filter:hover { background: var(--fill); color: var(--text); }
  .sort-completed-filter[aria-pressed="true"]:hover {
    background: color-mix(in srgb, var(--text) 10%, transparent);
    color: var(--text);
  }
}

.content {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 36px 120px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Thin, faint scrollbars in place of the OS default: a quiet position cue
   that stays out of the way in both light and dark mode. */
.content,
.sheet-card {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.content::-webkit-scrollbar,
.sheet-card::-webkit-scrollbar { width: 6px; height: 6px; }
.content::-webkit-scrollbar-track,
.sheet-card::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb,
.sheet-card::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.content::-webkit-scrollbar-thumb:hover,
.sheet-card::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ---------- Mobile screen transition ---------- */

.nav-snapshot {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  pointer-events: none;
}

.nav-snapshot.sidebar,
.nav-snapshot.main { display: flex !important; }

.nav-snapshot.sidebar {
  width: 100%;
  overflow-y: auto;
  scrollbar-width: none;
}

.nav-snapshot.sidebar::-webkit-scrollbar { display: none; }

.main.nav-incoming { position: relative; z-index: 30; }

body.nav-animating .shell { pointer-events: none; }

/* ---------- Motion shared ---------- */

body.flipping .reminder-group { overflow: visible; }

.completed-section { display: flow-root; }

.completed-retention {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--text-2);
}

.completed-retention.generic { justify-content: flex-start; margin-top: 0; }

.completed-retention-edit {
  flex: none;
  padding: 2px 0;
  font-size: 0.8125rem;
  color: var(--accent);
}

.completed-retention-edit:hover {
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
}

.flip-moving { position: relative; z-index: 2; }

@keyframes value-pop {
  from { opacity: 0.35; transform: translateY(-2px); }
  to { opacity: 1; transform: none; }
}

.badge.value-pop,
.view-count.value-pop,
.day-indicator.value-pop { animation: value-pop 0.22s ease-out; }

@keyframes day-cell-roll {
  from { opacity: 0.25; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.day-strip.rolling .day-cell { animation: day-cell-roll 0.24s ease-out both; }

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

.empty { animation: empty-in 0.22s ease-out; }

/* ---------- Reminders ---------- */

.reminder-group {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 15px;
}

.reminder {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  cursor: default;
  touch-action: pan-y;
}

.reminder:last-child { border-bottom: 0; }

/* Swipe layer: the content slides left, revealing Delete underneath.
   (Completion lives on the checkbox, so there is no Done swipe action.) */
.swipe-bg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

/* Never show the action color through a resting row's edge. It appears only
   while the card is actually being swiped or parked open. */
.reminder.swipe-active .swipe-bg,
.reminder.swipe-open .swipe-bg { opacity: 1; }

.swipe-act {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 18px;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  border: 0;
  cursor: pointer;
  pointer-events: auto;
}

.swipe-act .ic { width: 18px; height: 18px; }
.swipe-act.del { background: var(--red); width: min(140px, 45%); justify-content: flex-end; }

.swipe-content {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 64px;
  padding: 14px;
  background: var(--surface);
  transition: transform 0.18s ease;
  will-change: transform;
}

.swipe-content.swiping { transition: none; user-select: none; -webkit-user-select: none; }

/* Title-only rows centre the check; rows with a note/link/meta keep it on the title line. */
.reminder--single .swipe-content { align-items: center; }
.reminder--single .check { margin-top: 0; }

.reminder:hover .swipe-content { background: var(--elev); }

.reminder.has-long-note { cursor: pointer; }

.check {
  position: relative;
  flex: none;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  padding: 0;
  border: 1.5px solid var(--text-3);
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
  display: grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}

.check .ic {
  width: 13px;
  height: 13px;
  opacity: 0;
  transition: opacity 0.15s;
}

.reminder:hover .check,
.check:focus-visible {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 10%, transparent);
  color: var(--c);
}

.row-tools {
  display: flex;
  align-items: center;
  align-self: center;
  flex: none;
  gap: 8px;
}

.row-copy,
.row-edit {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-3);
  opacity: 0.6;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.row-copy .ic,
.row-edit .ic { width: 15px; height: 15px; }

.reminder:hover .row-copy,
.row-copy:focus-visible,
.reminder:hover .row-edit,
.row-edit:focus-visible { opacity: 0.9; }

.row-copy:hover,
.row-edit:hover { background: var(--fill); color: var(--text); opacity: 1; }

.row-delete {
  position: relative;
  flex: none;
  align-self: center;
  min-width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-3);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s, width 0.15s, padding 0.15s;
}

.row-delete .ic { width: 15px; height: 15px; }

.reminder:hover .row-delete,
.row-delete:focus-visible { opacity: 0.8; }

.row-delete:hover { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); opacity: 1; }

.row-delete.confirming {
  width: auto;
  padding: 0 12px;
  background: color-mix(in srgb, var(--red) 14%, transparent);
  color: var(--red);
  opacity: 1;
}

/* Series-delete warning: persistent, in-row, and it must not shift the row's
   height in a way that moves the buttons under the finger (it grows downward
   from the row's own body, and only once per tap). */
.row-series-warn {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--red) 8%, transparent);
}

.row-series-warn-text {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--red);
}

.row-series-warn-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.mini-btn.danger-mini {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 40%, transparent);
  background: color-mix(in srgb, var(--red) 10%, transparent);
}

/* Deleting collapses the row after the inline confirm. */
.reminder.removing {
  overflow: hidden;
  transition: height 0.22s ease, opacity 0.18s ease;
}

/* Keep the browser from changing the scroll position while a row collapses. */
html.deleting-row,
html.deleting-row body,
html.deleting-row #content { overflow-anchor: none; }

.reminder.removing .swipe-content {
  transform: translateX(-100%);
  opacity: 0;
}

@media (hover: none) {
  .row-delete { display: none; }
}

.reminder.done .check {
  background: var(--c);
  border-color: var(--c);
  color: var(--accent-contrast);
}
.reminder.done .check .ic { opacity: 1; }
/* Completed rows keep the normal title size and step down by colour: the
   title takes the list-note colour, and every secondary line drops to the
   muted level. The completing state mirrors this while the check request is
   in flight, so nothing jumps when the row re-renders. The filled check
   remains the completion marker. */
.reminder.done .reminder-title,
.reminder.completing .reminder-title { color: var(--text-2); }
.reminder.done .reminder-notes,
.reminder.completing .reminder-notes { color: var(--text-3); }
.reminder.done .link-chip,
.reminder.completing .link-chip { color: var(--text-3); font-weight: 500; }
.reminder.done .link-chip:hover,
.reminder.completing .link-chip:hover { color: var(--text-2); }
.reminder.done .reminder-due,
.reminder.completing .reminder-due { color: var(--text-3); font-weight: 400; }

/* Un-completing previews the empty ring while the PATCH is in flight, so the
   check visibly clears before the row animates back to the open group. */
.reminder.uncompleting .check {
  background: transparent;
  border-color: var(--text-3);
  color: var(--text-3);
}
.reminder.uncompleting .check .ic { opacity: 0; }

.reminder-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.reminder-title {
  font-size: 0.9375rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.reminder-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-3);
}

.meta-list { display: inline-flex; align-items: center; gap: 5px; }

.meta-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c);
}

.reminder-due {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  justify-self: start;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
}
.reminder-due .ic { width: 12px; height: 12px; }
/* The clock time belongs to the date: same weight and colour as it (inherit),
   including the red overdue pill. Only the relative countdown stays quiet. */
.reminder-due .due-time { color: inherit; font-weight: inherit; }
.reminder-due .due-in { color: var(--text-3); font-weight: 400; }
.reminder-due.overdue {
  color: var(--red);
  background: color-mix(in srgb, var(--red) 10%, transparent);
  border-radius: 4px;
  padding: 1px 6px;
}
.meta-urgent { display: inline-flex; align-items: center; gap: 5px; color: var(--red); }
.meta-urgent .ic { width: 12px; height: 12px; }
.meta-repeat { display: inline-flex; align-items: center; gap: 5px; }
.meta-repeat .ic { width: 12px; height: 12px; }
.meta-model { display: inline-flex; align-items: center; color: var(--text-3); }
.meta-edited { font-style: italic; }
.meta-snoozed { display: inline-flex; align-items: center; gap: 5px; }
.meta-snoozed .ic { width: 12px; height: 12px; }
.meta-completed { display: inline-flex; align-items: center; gap: 5px; }
.meta-completed .ic { width: 12px; height: 12px; }

.reminder-notes {
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
}

.reminder-notes.is-expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
  white-space: pre-line;
}

.note-wrap {
  position: relative;
  min-width: 0;
}

.reminder-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 3px;
}

.link-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 180px;
  margin: 0 2px;
  padding: 1px 8px 1px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 550;
  text-decoration: none;
  vertical-align: -3px;
}

.link-chip .ic { width: 12px; height: 12px; flex: none; }

.link-chip .link-domain {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

/* Desktop: a reminder card is wide, so its contextual actions (Snooze /
   Reschedule) use the blank right side instead of stacking under the text.
   Title/meta/notes keep the left column; each action group is one compact
   line on the right, wrapping underneath only when the card gets narrow.
   Mobile keeps the stacked full-width layout above. */
@media (min-width: 769px) {
  .reminder-body {
    display: grid;
    /* The text column keeps at least 220px; when the chips would squeeze
       it, Next occurrence drops to its own line in the action column. */
    grid-template-columns: minmax(220px, 1fr) auto;
    /* Text rows are content-height; the spare height goes to the last
       (flexible) track so the action block never stretches the title row. */
    grid-template-rows: repeat(5, auto) 1fr;
    column-gap: 20px;
    align-items: start;
  }
  .reminder-body > .reminder-due,
  .reminder-body > .reminder-title,
  .reminder-body > .reminder-meta,
  .reminder-body > .reminder-notes,
  .reminder-body > .note-wrap,
  .reminder-body > .reminder-links { grid-column: 1; }
  /* One block holds Snooze and Reschedule: its top lines up with the
     title and its groups sit 8px apart, the same as the chip gap. */
  .reminder-body > .row-action-stack {
    grid-column: 2;
    grid-row: 1 / -1;
    align-self: start;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
  }
  .row-action-stack > .row-actions {
    margin-top: 0;
    justify-content: flex-end;
  }
  .row-action-stack > .row-actions .row-actions-label { flex-basis: auto; }
}

/* Mobile and narrow widths: the wrapper is transparent, groups stack as before. */
.row-action-stack { display: contents; }

.snooze-hours { display: inline-flex; gap: 8px; }

.row-actions-label {
  flex-basis: 100%;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}

.mini-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 550;
  padding: 6px 12px;
  min-height: 36px;
}

.mini-btn:hover { background: var(--fill); color: var(--text); }

.group-title {
  margin: 22px 0 4px;
  font-family: 'Fraunces', serif;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}


.overdue-title { color: var(--red); }

.toggle-completed {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-2);
  text-align: left;
  font-size: 0.8125rem;
  padding: 12px 0;
}

.toggle-completed:hover { color: var(--text); }

.toggle-completed + .group-title { margin-top: 14px; }

.search-status {
  margin: 0 0 12px;
  font-size: 0.78rem;
  color: var(--text-3);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 64px 20px;
  color: var(--text-3);
  text-align: center;
}

.empty .ic { width: 36px; height: 36px; opacity: 0.6; }
.empty-heading { margin: 4px 0 0; font-family: 'Fraunces', serif; font-size: 1.0625rem; color: var(--text); }
.empty p { margin: 0; font-size: 0.875rem; max-width: 300px; }
.empty .primary-btn { margin-top: 8px; }

/* ---------- Floating add button ---------- */

.fab {
  position: fixed;
  right: 28px;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 40;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.12);
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

body.sheet-open .fab {
  opacity: 0;
  pointer-events: none;
}


.fab:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 11px 28px rgba(0, 0, 0, 0.2), 0 3px 7px rgba(0, 0, 0, 0.14);
}

.fab:active { transform: scale(0.95); }
.fab .ic { width: 26px; height: 26px; }

@media (prefers-reduced-motion: reduce) {
  .fab, .fab:hover, .fab:active { transition: none; transform: none; }
}

/* ---------- Sheets ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  touch-action: none;
}

/* With any sheet open the page behind is fully locked: fixed body (the
   iOS-proof part — overflow:hidden alone doesn't stop touch scrolling),
   hidden background scrollers, and no scroll chaining out of the sheet. */
body.sheet-open {
  position: fixed;
  inset: 0;
  width: 100%;
  overscroll-behavior: none;
}

body.sheet-open .content,
body.sheet-open .sidebar {
  overflow: hidden;
}

.sheet-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(88dvh, 780px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  animation: pop 0.16s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.98) translateY(4px); }
  to { opacity: 1; transform: none; }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 16px;
  background: var(--elev);
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.875rem;
  font-weight: 600;
}

.sheet-head .text-btn { padding: 4px 2px; color: var(--text-2); font-size: 0.8125rem; }
.sheet-head .text-btn:hover { background: transparent; color: var(--text); }
.sheet-head .strong { color: var(--accent); font-weight: 600; }
/* The editor and Settings primary action swaps to "Adding..."/"Saving...";
   reserving the width keeps the centred title from shifting. */
.sheet-head #editor-submit,
.sheet-head #settings-save,
.sheet-head #list-save { min-width: 64px; justify-content: flex-end; }

.sheet-body {
  padding: 16px 18px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.e-title {
  border: 1px solid var(--line);
  background: var(--elev);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9375rem;
  font-weight: 500;
}

.e-title:focus, .e-notes:focus { outline: none; border-color: var(--accent); }

#l-name { height: var(--control-height); min-height: var(--control-height); }
#l-name:disabled { opacity: 0.65; cursor: default; }

.list-retention-row {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.list-retention-hint { margin: 8px 0 0; }

.list-retention-warn {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--red) 8%, transparent);
}

.list-retention-warn-text {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--red);
}

.list-retention-warn-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.e-notes {
  border: 1px solid var(--line);
  background: var(--elev);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.875rem;
  resize: vertical;
  min-height: 64px;
  /* Long notes scroll inside the editor instead of making the sheet grow
     by thousands of pixels. */
  max-height: 45dvh;
}

/* ---------- Reminder editor ---------- */

.editor-card { max-height: min(92dvh, 820px); }

#editor .editor-head {
  background: var(--elev);
  border-bottom: 0;
  padding: 12px 16px 4px;
}

.editor-head > span {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#editor .editor-body {
  gap: 18px;
  padding: 10px 18px calc(26px + env(safe-area-inset-bottom));
}

.editor-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#editor .e-title,
#editor .e-notes {
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border: 0;
  border-radius: 12px;
  padding: 13px 15px;
}

#editor .e-title {
  font-size: 1.0625rem;
  font-weight: 550;
  line-height: 1.35;
  min-height: 64px;
  max-height: 40dvh;
  resize: none;
  overflow-y: auto;
}

#editor .e-title::placeholder,
#editor .e-notes::placeholder {
  color: var(--text-3);
  font-weight: 400;
}

#editor .e-notes {
  min-height: 48px;
  max-height: 30dvh;
  font-size: 0.9375rem;
  resize: none;
  overflow-y: auto;
}

#editor .e-title:focus,
#editor .e-notes:focus {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent);
}

.ed-note-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px;
}

.ed-note-links a {
  color: var(--accent);
  font-size: 0.8125rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

.ed-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ed-section-label {
  padding: 0 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
}

.ed-group {
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border-radius: 14px;
  overflow: hidden;
}

.ed-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 0.9375rem;
  color: var(--text);
}

.ed-row + .ed-row,
.ed-subrow + .ed-row {
  border-top: 1px solid color-mix(in srgb, var(--text) 7%, transparent);
}

.ed-ic {
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--text-3);
}

.ed-ic .ic { width: 19px; height: 19px; }
.ed-label { flex: 1; min-width: 0; }

.ed-value {
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-3);
  font-size: 0.875rem;
}

.ed-chevron {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--text-3);
}

.ed-switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  cursor: pointer;
}

.ed-switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.ed-switch span {
  display: block;
  pointer-events: none;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 26%, transparent);
  transition: background 0.18s;
}

.ed-switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--elev);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 0.18s;
}

.ed-switch input:checked + span { background: var(--accent); }
.ed-switch input:checked + span::after { transform: translateX(18px); }
.ed-switch input:focus-visible + span { box-shadow: 0 0 0 2px var(--accent); }

.ed-group,
.ed-row,
.ed-subrow,
.editor-body {
  min-width: 0;
}

.ed-subrow {
  display: flex;
  align-items: center;
  padding: 0 14px 10px 48px;
}

/* The row is the field; the native date/time control sits inside it so its
   value is vertically centred on every platform (iOS anchors the value to
   the top of a fixed-height input otherwise). */
#e-date-row,
#e-time-row {
  display: flex;
  align-items: center;
  height: var(--control-height);
  margin: 0 14px 10px 48px;
  padding: 0 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
}

#e-date-row input,
#e-time-row input {
  flex: 1 1 auto;
  width: auto;
  max-width: 100%;
  min-width: 0;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
}

#e-date-row:focus-within,
#e-time-row:focus-within {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent);
}

#e-date-row input:focus,
#e-time-row input:focus { box-shadow: none; }

/* The row carries the focus ring (:focus-within); the native control's own
   outline would draw a second box inside it. */
#e-date-row input:focus-visible,
#e-time-row input:focus-visible { outline: none; }

.ed-subrow input[type="date"],
.ed-subrow input[type="time"] { font-size: 0.9375rem; }

.ed-subrow input[type="date"]::-webkit-calendar-picker-indicator,
.ed-subrow input[type="time"]::-webkit-calendar-picker-indicator {
  width: 18px;
  height: 18px;
}

.ed-subrow input:focus {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent);
}

.ed-hint {
  margin: -2px 4px 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-3);
}
.ed-hint.ed-warning { color: var(--red); }

.ed-list-row { cursor: pointer; }

.ed-list-row select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  opacity: 0;
  cursor: pointer;
}

.ed-list-ic {
  width: 28px;
  height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--c, var(--blue));
  color: var(--accent-contrast);
}

.ed-list-ic .ic { width: 17px; height: 17px; }

.editor-delete { width: 100%; margin: 0; }

.parse-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 12px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.8125rem;
  padding: 9px 12px;
  text-align: left;
}

.parse-chip span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.parse-chip .ic { width: 14px; height: 14px; flex: none; }

.ed-select-row { cursor: pointer; }

.ed-select-row select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  opacity: 0;
  cursor: pointer;
  font-size: 16px;
}

.ed-repeat-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 0.875rem;
}

.ed-repeat-custom input[type="number"],
.ed-repeat-custom select {
  height: var(--control-height);
  border: 0;
  border-radius: 9px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  padding: 0 11px;
  color: var(--text);
  font-size: 0.9375rem;
}

.ed-repeat-custom input[type="number"] { width: 72px; flex: none; }
.ed-repeat-custom select { flex: 1; }

.segmented {
  display: flex;
  gap: 2px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  border-radius: 8px;
  padding: 2px;
}

.segmented-btn {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 550;
  padding: 6px 10px;
  min-height: 36px;
}

.segmented-btn.active { background: var(--elev); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }

.ed-history { display: flex; flex-direction: column; gap: 4px; padding: 0 4px; }

.history-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 0.8125rem;
  color: var(--text-2);
  transition: opacity 0.15s ease, background 0.15s ease;
}

.history-status { font-weight: 600; min-width: 74px; }

.history-undo {
  margin-left: auto;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 550;
  padding: 2px 8px;
  cursor: pointer;
}

.history-undo:hover { color: var(--text); background: var(--hover); }
.history-undo.staged { color: var(--accent); font-weight: 700; }
.history-row.history-staged .history-date { text-decoration: line-through; }
.history-empty { margin: 0; font-size: 0.8125rem; color: var(--text-3); }
.history-title {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
}

.danger-btn {
  margin-top: 6px;
  border: 1px solid color-mix(in srgb, var(--red) 35%, var(--line));
  border-radius: var(--radius-sm);
  padding: 10px;
  background: transparent;
  color: var(--red);
  font-size: 0.8125rem;
  font-weight: 550;
}

.danger-btn:hover { background: color-mix(in srgb, var(--red) 8%, transparent); }

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 10px 4px;
}

.swatch {
  position: relative;
  width: 34px;
  height: 34px;
  justify-self: center;
  border: 0;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 2px transparent;
}

.swatch.selected { box-shadow: 0 0 0 2px var(--elev), 0 0 0 4px var(--text); }

.section-empty {
  margin: 0;
  padding: 8px 10px;
  font-size: 0.8125rem;
  color: var(--text-3);
}

.notify-status { margin: 2px 0 6px; font-size: 0.875rem; }
.notify-hint { margin: 0 0 6px; font-size: 0.8125rem; color: var(--text-2); line-height: 1.45; }
.sheet-body .secondary-btn { margin-top: 4px; }

/* ---------- Settings ---------- */

.settings-subhead {
  margin: 18px 0 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
}

.settings-subhead:first-of-type { margin-top: 2px; }

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.settings-group:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.settings-group h3 {
  margin: 0 0 2px;
  font-family: 'Fraunces', serif;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.settings-group input {
  height: var(--control-height);
  min-height: var(--control-height);
  border: 1px solid var(--line);
  background: var(--elev);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.875rem;
  color: var(--text);
}

.settings-group input::placeholder { color: var(--text-3); }
.settings-group input:focus { outline: none; border-color: var(--accent); }
.settings-group .primary-btn { margin-top: 2px; }

#username-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-input-row {
  display: flex;
  gap: 10px;
}

.settings-input-row input {
  flex: 1;
  min-width: 0;
  width: 100%;
}

.theme-toggle-row {
  display: flex;
  gap: 2px;
  background: var(--fill);
  border-radius: 6px;
  padding: 2px;
  width: fit-content;
}

.theme-option-btn {
  padding: 5px 14px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.theme-option-btn:hover { color: var(--text); }
.theme-option-btn.active { background: var(--accent); color: var(--accent-contrast); }

.settings-note {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-2);
}

.settings-note strong { color: var(--text); }

.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--control-height);
  font-size: 0.875rem;
  color: var(--text);
}

.settings-row > span { flex: 1; min-width: 0; }

.settings-row select,
.settings-row input[type="time"],
.settings-row input[type="number"],
.settings-row input[type="text"] {
  flex: 0 0 var(--settings-control-width);
  width: var(--settings-control-width);
  height: var(--control-height);
  border: 1px solid var(--line);
  background: var(--elev);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: 0.875rem;
  color: var(--text);
  text-align: left;
}

.settings-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex: none;
  margin: 0;
  accent-color: var(--accent);
}

.settings-row input:focus, .settings-row select:focus { outline: none; border-color: var(--accent); }

.token-once {
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.token-value {
  margin: 0;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  overflow-wrap: anywhere;
  user-select: all;
}

.token-list { display: flex; flex-direction: column; gap: 6px; }

.token-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  font-size: 0.8125rem;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.token-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.token-meta { color: var(--text-3); font-size: 0.75rem; }

.small-btn { padding: 6px 12px; min-height: 36px; font-size: 0.75rem; }

/* Native selects ignore button min-height sizing, so the token-row select
   gets an explicit shared height, box-model reset, and a custom chevron to
   match the neighbouring buttons exactly. */
.token-row select,
.token-row .small-btn {
  height: var(--control-height);
  min-height: var(--control-height);
  box-sizing: border-box;
}

.token-row select {
  padding: 0 28px 0 12px;
  font-size: 0.8125rem;
  font-weight: 550;
  line-height: normal;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%23888888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

.token-examples { font-size: 0.8125rem; color: var(--text-2); }

.token-examples summary { cursor: pointer; font-weight: 550; }

.token-examples pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--text) 6%, transparent);
  font-size: 0.7rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}

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

.form-msg {
  margin: 0;
  font-size: 0.78rem;
  color: var(--red);
}

.form-msg.ok { color: var(--green); }
.field-error { margin-top: -4px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(420px, calc(100% - 32px));
  padding: 10px 15px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.8125rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
  animation: toast-in 0.18s ease-out;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.toast-action {
  pointer-events: auto;
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  flex: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Mobile ---------- */

#menu-btn { display: grid; }

.account-menu {
  position: fixed;
  top: calc(62px + env(safe-area-inset-top));
  transform-origin: top right;
  right: 12px;
  z-index: 70;
  min-width: 210px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
}

.account-menu .text-btn { width: 100%; }

.account-menu .storage-total {
  margin-left: auto;
  color: var(--text-3);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Desktop: mirror the mobile Home ---------- */
@media (min-width: 900px) {
  html, body { height: 100%; }
  body { overflow: hidden; overscroll-behavior-y: contain; }

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

  .sidebar {
    position: static;
    width: min(54vw, 990px);
    height: 100%;
    margin: 0 auto;
    border-right: 0;
    padding: 18px 24px calc(96px + env(safe-area-inset-bottom));
    z-index: auto;
    transform: none;
    transition: none;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .sidebar::-webkit-scrollbar { display: none; width: 0; height: 0; }

  body[data-screen="home"] .sidebar { display: flex; }
  body[data-screen="home"] .main { display: none; }
  body[data-screen="detail"] .sidebar { display: none; }
  body[data-screen="detail"] .main { display: flex; }

  .sidebar .sidebar-foot { display: none; }

  .main {
    width: min(54vw, 990px);
    min-height: 0;
    margin: 0 auto;
    display: flex;
    flex: none;
  }

  .main-head {
    position: static;
    max-width: none;
    padding: 18px 24px 10px;
    align-items: center;
  }

  .back-btn { display: flex; }
  body[data-screen="home"] .back-btn { display: none; }
  .back-btn span { display: inline; }

  #menu-btn { display: grid; }
  #sidebar-menu-btn { display: grid; }

  .main-search {
    display: flex;
    align-items: center;
    position: relative;
    margin: 0 24px 0;
  }

  .main-search .search-ic { left: 10px; width: 16px; height: 16px; }

  .main-search input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 9px 10px 9px 32px;
    background: var(--elev);
    color: var(--text);
    font-size: 0.8125rem;
    -webkit-appearance: none;
    appearance: none;
  }

  .main-search input::placeholder { color: var(--text-3); }
  .main-search input:focus { outline: none; border-color: var(--accent); }
  .main-search input::-webkit-search-cancel-button { -webkit-appearance: none; }

  .sort-bar { margin: 12px 24px 0; }

  .account-menu {
    right: max(12px, calc((100vw - min(54vw, 990px)) / 2 + 12px));
  }

  .fab {
    right: max(28px, calc((100vw - min(54vw, 990px)) / 2 + 28px));
  }

  .content {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 12px 24px calc(132px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }
}

/* ---------- Compact density (opt-in) ---------- */

[data-density="compact"] .list-row { min-height: 0; padding: 6px 8px; }
[data-density="compact"] .swipe-content { min-height: 0; padding: 8px 12px; gap: 10px; }
[data-density="compact"] .reminder-due { font-size: 0.7rem; }
[data-density="compact"] .reminder-title { font-size: 0.875rem; }
[data-density="compact"] .reminder-meta { font-size: 0.7rem; gap: 8px; }
[data-density="compact"] .reminder-notes { font-size: 0.75rem; }
[data-density="compact"] .check { width: 20px; height: 20px; }
[data-density="compact"] .content { padding-top: 10px; }
[data-density="compact"] .group-title { margin-top: 14px; }

@media (max-width: 899px) {
  .sidebar {
    position: static;
    width: 100%;
    height: 100%;
    border-right: 0;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-left: 18px;
    padding-right: 18px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
    z-index: auto;
    transform: none;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .sidebar::-webkit-scrollbar { display: none; width: 0; height: 0; }

  /* Mobile home is the full-screen list panel: search, smart views, My Lists,
     then the lists. The footer actions live in the hamburger menu. */
  body[data-screen="home"] .sidebar { display: flex; padding-top: 0; }
  body[data-screen="home"] .main { display: none; }
  body[data-screen="detail"] .sidebar { display: none; }
  body[data-screen="detail"] .main { display: flex; }

  /* The header + search stay pinned; everything below scrolls (as one page
     on touch phones). The top padding lives on the sticky wrapper so stuck
     and unstuck geometry match exactly. */
  .sidebar-top,
  .main-top {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--surface);
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  /* The main header already owns that top padding, so the wrapper only
     supplies the pinned surface. */
  .main-top { padding-top: 0; }

  .sidebar .sidebar-foot { display: none; }

  .back-btn { display: flex; }
  body[data-screen="home"] .back-btn { display: none; }

  #menu-btn { display: grid; }
  #sidebar-menu-btn { display: grid; }

  .list-row { -webkit-touch-callout: none; user-select: none; }

  /* Home and detail headers share the same height so the menu button never
     shifts vertically when opening a list. */
  .sidebar-head, .main-head { min-height: 33px; }
  .sidebar-head { align-items: center; }

  .main-head {
    flex-wrap: wrap;
    align-items: center;
    row-gap: 0;
    padding: calc(14px + env(safe-area-inset-top)) 18px 10px;
  }

  .back-btn { order: 1; flex: none; padding: 6px 6px 6px 0; margin-right: 2px; }
  .back-btn span { display: none; }
  .title-wrap { order: 2; flex-direction: row; align-items: baseline; gap: 8px; }
  .title-wrap h2 { font-size: 1.375rem; }
  .view-count { font-size: 0.8125rem; }
  .head-actions { order: 3; align-self: flex-start; }

  .search-bar-overlay input, .main-search input,
  .auth-card input, .gate-card input, .settings-group input, .e-title, .e-notes,
  #editor .e-title, #editor .e-notes,
  .ed-subrow input[type="date"], .ed-subrow input[type="time"],
  .ed-list-row select { font-size: 16px; }

  .ed-subrow {
    padding: 0 14px 12px;
    overflow: hidden;
  }

  #e-date-row,
  #e-time-row {
    margin: 0 14px 12px;
    padding: 0 12px;
  }

  .ed-subrow input[type="date"],
  .ed-subrow input[type="time"] {
    display: block;
    flex: 1 1 auto;
    width: auto;
    max-width: 100%;
    min-width: 0;
    margin: 0 3px;
  }

  /* The cross is a desktop affordance; on mobile just the centered label. */
  .swipe-act.del { gap: 0; padding: 0; justify-content: center; }
  .swipe-act.del .ic { display: none; }

  .main-search {
    display: flex;
    align-items: center;
    position: relative;
    margin: 0 18px 0;
  }

  .sort-bar {
    margin: 12px 18px 0;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .sort-control {
    gap: 2px;
    min-width: 0;
  }

  .sort-control select {
    max-width: 130px;
    min-width: 0;
    font-size: 0.71875rem;
  }

  .main-search .search-ic { left: 10px; width: 16px; height: 16px; }

  .main-search input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 9px 10px 9px 32px;
    background: var(--elev);
    color: var(--text);
    -webkit-appearance: none;
    appearance: none;
  }

  .main-search input::placeholder { color: var(--text-3); }
  .main-search input:focus { outline: none; border-color: var(--accent); }
  .main-search input::-webkit-search-cancel-button { -webkit-appearance: none; }

  .content { padding: 12px 18px calc(132px + env(safe-area-inset-bottom)); }

  .fab {
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
  }


  #editor .editor-card {
    height: 94dvh;
    max-height: 94dvh;
  }

  /* New item: compact content-height card docked at the bottom instead of
     a mostly empty full-height sheet. Expanding grows within the viewport
     and scrolls as needed. Editing keeps the full-height sheet above. */
  #editor.is-new .editor-card {
    height: auto;
    max-height: 94dvh;
  }
  .swipe-content { padding: 12px 14px; }
  .reminder-title { font-size: 0.9375rem; }
  .reminder-meta { font-size: 0.75rem; }

  .sheet { align-items: flex-end; padding: 0; }
  .sheet-card {
    width: 100%;
    max-height: 92dvh;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 0;
    transform: translateY(100%);
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
    animation: none;
    will-change: transform;
  }

  .sheet.is-visible .sheet-card { transform: translateY(0); }

  .sheet-backdrop {
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .sheet.is-visible .sheet-backdrop { opacity: 1; }

  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* Phone control heights: same visual system as web, one step taller, with
     tap areas padded out to 44px via the coarse-pointer rule above. */
  .icon-btn { width: var(--icon-size-touch); height: var(--icon-size-touch); }
  .icon-btn .ic { width: 18px; height: 18px; }
  .icon-btn::after { inset: -2px; }
  .icon-btn.small { width: 36px; height: 36px; }
  .icon-btn.small::after { inset: -4px; }
  .check { width: 28px; height: 28px; }
  .check::after { inset: -8px; }
  .back-btn { min-height: var(--control-height-touch); padding: 10px 8px 10px 0; }
  .back-btn::after { inset: 0 -6px; }
  .text-btn { min-height: var(--control-height-touch); padding: 10px 12px; }
  .primary-btn, .secondary-btn { min-height: var(--control-height-touch); }
  .small-btn { min-height: var(--control-height-touch); }
  .mini-btn { min-height: var(--control-height-touch); }
  .sort-control select { min-height: var(--control-height-touch); }
  .token-row select,
  .token-row .small-btn { height: var(--control-height-touch); min-height: var(--control-height-touch); }
  .settings-row { min-height: var(--control-height-touch); }
  .segmented-btn { min-height: var(--control-height-touch); }
  .nav-row { min-height: var(--control-height-touch); padding: 10px 8px; }
  [data-density="compact"] .check::after { inset: -12px; }
  .settings-row select,
  .settings-row input[type="time"],
  .settings-row input[type="number"],
  .settings-row input[type="text"],
  .settings-group input { height: var(--control-height-touch); }
  #token-generate, #token-copy { min-height: var(--control-height-touch); }
  .sidebar-head, .main-head { min-height: var(--icon-size-touch); }
}

/* Touch phones scroll the document itself. iOS only applies the status-bar
   tap-to-top gesture to the root scroller, so neither screen may live in a
   nested overflow container there. A narrow desktop window keeps the nested
   scrollers (and its scrollbars) exactly as before. */
@media (max-width: 899px) and (pointer: coarse) {
  html, body { height: auto; }
  /* The rubber-band gap around the whole document shows the body canvas, so
     keep it the same surface colour as both screens. */
  body { background: var(--surface); overflow: visible; overscroll-behavior-y: contain; }

  .shell { height: auto; min-height: 100dvh; }
  .sidebar { height: auto; overflow: visible; }
  .main { height: auto; }

  .content {
    flex: 0 0 auto;
    overflow: visible;
  }

  /* The screen-transition clone is a fixed overlay, so it must scroll like
     the real document does or the snapshot would be pinned at the top. */
  .nav-snapshot.nav-snapshot-page { height: 100%; overflow-y: auto; }
}

@media (max-width: 899px) and (prefers-reduced-motion: reduce) {
  .sheet-card, .toast { animation: none; transition: none; }
  .sheet-backdrop { transition: none; }
}

@media (hover: none) {
  .nav-row:hover,
  .list-row:hover,
  .icon-btn:hover,
  .text-btn:hover { background: transparent; }
  .text-btn:hover { color: var(--text-2); }
  /* Keep the swipe content opaque on touch: the Delete layer sits beneath. */
  .reminder:hover .swipe-content { background: var(--surface); }
}

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

.list-grip:focus-visible { opacity: 0.9; }

::selection { background: rgba(44, 36, 27, 0.18); }
[data-theme="dark"] ::selection { background: rgba(245, 245, 245, 0.2); }

/* ---------- Quick add: name-only default, options on demand ---------- */

.e-quick-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin-top: -8px;
}

.e-more-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: -8px;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.e-more-toggle:hover { color: var(--text); }

.e-more-toggle .ic {
  width: 14px;
  height: 14px;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.e-more-toggle[aria-expanded="true"] .ic { transform: rotate(90deg); }

/* The optional fields collapse to zero height; the grid-rows trick animates
   the expand without measuring anything in JS. */
.e-more {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

.e-more.expanded { grid-template-rows: 1fr; }

/* A class display rule beats the [hidden] UA style, so restore it. */
.e-more[hidden] { display: none; }

.e-more-inner {
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- Skeleton loading ---------- */

.skel {
  display: block;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--text) 8%, transparent) 25%,
    color-mix(in srgb, var(--text) 15%, transparent) 50%,
    color-mix(in srgb, var(--text) 8%, transparent) 75%
  );
  background-size: 300% 100%;
  animation: skel-shimmer 1.4s ease-in-out infinite;
}

@keyframes skel-shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

.skel-group {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}

.skel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 16px 15px;
  border-bottom: 1px solid var(--line);
}

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

.skel-check { width: 24px; height: 24px; border-radius: 50%; flex: none; }

.skel-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.skel-bar { height: 10px; border-radius: 999px; }
.skel-bar-title { height: 12px; }

.skel-list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}

.skel-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

@media (max-width: 899px) {
  .skel-row { padding: 14px 15px; }
}

/* ---------- Fluid feedback ---------- */

/* New rows ease into place; completing a row fills its check immediately
   (the request fires at the same time - nothing waits on the animation). */
.reminder.completing .check {
  background: var(--c);
  border-color: var(--c);
  color: var(--accent-contrast);
}
.reminder.completing .check .ic { opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
  .reminder.entering {
    animation: row-enter 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .reminder.completing .check {
    animation: check-pop 0.18s ease-out;
  }

  .reminder.uncompleting .check {
    animation: check-unpop 0.18s ease-out;
  }

  .reminder.completing .check::before,
  .reminder.uncompleting .check::before {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: 50%;
    border: 1.5px solid var(--c);
    pointer-events: none;
    animation: check-halo 0.32s ease-out;
  }
}

@keyframes check-halo {
  from { opacity: 0.65; transform: scale(0.9); }
  to { opacity: 0; transform: scale(1.5); }
}

@keyframes row-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes check-pop {
  0% { transform: scale(0.7); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes check-unpop {
  0% { transform: scale(1); }
  45% { transform: scale(0.88); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .skel { animation: none; }
  .e-more { transition: none; }
  .e-more-toggle .ic { transition: none; }
}


/* ---------------- Tenants: Reminders / Notes / Docs ---------------- */

.tenant-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: color-mix(in srgb, var(--text) 5%, var(--surface));
}

.tenant-btn {
  min-height: 34px;
  padding: 0 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.tenant-btn:hover { background: var(--hover); color: var(--text); }

.tenant-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.note-row .swipe-content { align-items: flex-start; }
.doc-row .swipe-content { align-items: center; }

.note-row .reminder-title { font-weight: 600; }



.note-row .row-edit { opacity: 0.6; }


.doc-icon {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: color-mix(in srgb, var(--text) 7%, var(--surface));
  color: var(--text-2);
}

.doc-icon .ic { width: 18px; height: 18px; }

.doc-body {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.doc-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.doc-folder {
  font-size: 0.75rem;
  color: var(--text-3);
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--text-3);
}

.doc-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: var(--text-3);
  text-decoration: none;
}

.doc-download:hover { background: var(--fill); color: var(--text); }
.doc-download .ic { width: 15px; height: 15px; }

.doc-row .reminder-title {
  font-size: 0.9375rem;
  font-weight: 400;
  line-height: 1.35;
}

.doc-sheet-file {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.doc-sheet-file .doc-icon { width: 42px; height: 42px; }
.doc-sheet-file .doc-icon .ic { width: 22px; height: 22px; }
.doc-sheet-info { min-width: 0; }
.doc-sheet-info h3 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 400;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.doc-sheet-info p {
  margin: 3px 0 0;
  font-size: 0.75rem;
  color: var(--text-3);
}

#doc-sheet-download { margin-top: 4px; }

.attach-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attach-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.8125rem;
}

.attach-item .attach-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-item .attach-size {
  flex: none;
  color: var(--text-3);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}

.attach-remove {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.attach-remove:hover { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }

.attach-remove.confirming {
  width: auto;
  padding: 0 7px;
  background: color-mix(in srgb, var(--red) 12%, transparent);
  color: var(--red);
  font-family: inherit;
  font-size: 0.6875rem;
  font-weight: 600;
}
.attach-remove .ic { width: 13px; height: 13px; }

.attach-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--text-2);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.attach-add:hover { border-color: var(--accent); color: var(--text); }
.attach-add .ic { width: 14px; height: 14px; }

.note-body {
  min-height: 140px;
  resize: vertical;
  white-space: pre-wrap;
}


.storage-breakdown {
  display: grid;
  gap: 6px;
  margin: 8px 0;
}

.storage-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  font-size: 0.8125rem;
  color: var(--text-2);
}

.storage-row strong { color: var(--text); font-weight: 600; }

.storage-largest { display: grid; gap: 4px; margin-top: 6px; }

.storage-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.75rem;
  color: var(--text-2);
}

.storage-file:last-child { border-bottom: 0; }
.storage-file .storage-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.storage-file .storage-file-meta { flex: none; color: var(--text-3); }

@media (max-width: 899px) {
  .tenant-btn { min-height: 40px; }
  .doc-body { flex-direction: column; align-items: flex-start; gap: 6px; }
  .doc-meta { justify-content: flex-start; }
  .swipe-content { padding: 13px 12px; }
}
