/* Huskelapp. A notepad on the kitchen table: ruled paper with a red margin
   line, graphite ink, one pencil-yellow accent for the things you press most.
   Phone first; on a wide screen the pad simply sits in the middle. */

:root {
  --desk: #E9EDE8;
  --paper: #FDFDFA;
  --ink: #22303E;
  --ink-soft: #4A5868;
  --muted: #7A8693;
  --rule: #D9E4EC;
  --margin: #EDB1AD;
  --pencil: #F2C14E;
  --pencil-ink: #22303E;
  --pencil-deep: #D9A22A;
  --done: #9AA4AE;
  --mine: #4F7CAC;
  --danger: #B5524E;
  --ok: #3F8A5F;
  --focus: #2E6FB0;
  --shadow: 0 1px 2px rgba(34, 48, 62, .08), 0 6px 18px rgba(34, 48, 62, .08);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --row: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
/* Dark: the device's dark mode unless this device chose Light (Settings →
   Appearance sets data-theme on <html>), or chosen Dark. The two blocks must
   stay identical (tests/test_static.py checks). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #11161C;
    --paper: #19212A;
    --ink: #E4E9EE;
    --ink-soft: #C2CBD4;
    --muted: #8D98A4;
    --rule: #26313C;
    --margin: #5E3A3A;
    --pencil: #E8B93F;
    --pencil-ink: #1A2028;
    --pencil-deep: #F2C14E;
    --done: #6F7A86;
    --mine: #7BA4CF;
    --danger: #E07B76;
    --ok: #6CC08F;
    --focus: #79B6E2;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --desk: #11161C;
  --paper: #19212A;
  --ink: #E4E9EE;
  --ink-soft: #C2CBD4;
  --muted: #8D98A4;
  --rule: #26313C;
  --margin: #5E3A3A;
  --pencil: #E8B93F;
  --pencil-ink: #1A2028;
  --pencil-deep: #F2C14E;
  --done: #6F7A86;
  --mine: #7BA4CF;
  --danger: #E07B76;
  --ok: #6CC08F;
  --focus: #79B6E2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; min-height: 100dvh; background: var(--desk); color: var(--ink);
  font: 17px/1.4 var(--font); overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.2; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------- the pad -- */

#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; background: var(--paper); position: relative;
  padding-bottom: calc(96px + var(--safe-b)); }
@media (min-width: 700px) { #app { margin: 24px auto; min-height: calc(100dvh - 48px); border-radius: 14px; box-shadow: var(--shadow); } }

.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-t) + 10px) 10px 10px 16px; background: var(--paper);
}
.bar h1 { font-size: 1.45rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .title-btn { all: unset; flex: 1; min-width: 0; cursor: pointer; border-radius: 6px; }
.bar .title-btn h1 { display: block; }
.bar .sub { font-size: .85rem; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-top: 2px; flex-wrap: wrap; }
.bar .grow { flex: 1; min-width: 0; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: none; color: var(--ink-soft); flex: none;
}
.icon-btn:active { background: var(--rule); }
.icon-btn svg, .ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round; }
.text-btn { border: 0; background: none; color: var(--ink-soft); font-weight: 600; padding: 10px 10px; border-radius: 10px; }
.text-btn:active { background: var(--rule); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; background: var(--c, var(--mine)); }

/* Sync state: quiet when all is well. */
.sync { font-size: .78rem; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.sync.off i { background: var(--pencil-deep); }
.sync.wait i { background: var(--pencil-deep); animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* Space chips (All, Mine, Us, Family). */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; flex: none;
  border: 1.5px solid var(--rule); background: none; border-radius: 999px; padding: 6px 13px; font-size: .92rem;
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.chip .dot { width: 8px; height: 8px; }

/* Ruled rows with the margin line: the notepad itself. */
.ruled { list-style: none; margin: 0; padding: 0; position: relative; }
.ruled::before { content: ""; position: absolute; top: 0; bottom: 0; left: 46px; width: 1.5px; background: var(--margin); opacity: .7; pointer-events: none; }
.ruled > li { position: relative; display: flex; align-items: center; min-height: var(--row); border-bottom: 1px solid var(--rule); }
.ruled > li:first-child { border-top: 1px solid var(--rule); }

/* Home: one row per list. */
.lists .row { all: unset; box-sizing: border-box; display: grid; grid-template-columns: 46px 1fr auto; align-items: center;
  width: 100%; min-height: 60px; padding: 8px 14px 8px 0; cursor: pointer; }
.lists .row:active { background: var(--rule); }
.lists .kind { display: grid; place-items: center; color: var(--c, var(--mine)); }
.lists .kind .ic { width: 22px; height: 22px; }
.lists .what { padding-left: 12px; min-width: 0; }
.lists .what b { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lists .what span { display: block; color: var(--muted); font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lists .count { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: .95rem; padding-left: 10px; }
.section-title { padding: 22px 16px 8px 60px; font-size: .9rem; color: var(--muted); font-weight: 600; }
.more-link { display: flex; align-items: center; gap: 8px; padding: 16px 16px 16px 60px; color: var(--ink-soft); text-decoration: none; }

.fab {
  position: fixed; right: max(18px, calc(50% - 320px + 18px)); bottom: calc(22px + var(--safe-b)); z-index: 8;
  width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--pencil); color: var(--pencil-ink);
  box-shadow: var(--shadow); display: grid; place-items: center;
}
.fab svg { width: 30px; height: 30px; stroke-width: 2.4; }
.fab:active { transform: scale(.95); background: var(--pencil-deep); }

/* A checklist's things. */
.items li { gap: 0; }
.tick {
  flex: none; width: 46px; align-self: stretch; display: grid; place-items: center; border: 0; background: none; padding: 0;
}
.tick span { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--ink-soft); display: grid; place-items: center; background: var(--paper); }
.tick span svg { width: 16px; height: 16px; stroke: var(--paper); stroke-width: 3; opacity: 0; }
.done .tick span { background: var(--ink-soft); border-color: var(--ink-soft); }
.done .tick span svg { opacity: 1; }
.tick:disabled { cursor: default; }
.thing { all: unset; box-sizing: border-box; flex: 1; min-width: 0; padding: 12px 14px 12px 12px; cursor: pointer; }
.thing b { font-weight: 450; display: block; overflow-wrap: anywhere; }
.thing b .pending-mark { display: inline; }
.thing > span { display: block; color: var(--muted); font-size: .84rem; margin-top: 1px; overflow-wrap: anywhere; }
.done .thing b { color: var(--done); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.sub-items { list-style: none; margin: 0; padding: 0; width: 100%; }
.items li.section { flex-wrap: wrap; }
.items li.section > .thing b { font-weight: 700; }
.sub-items li { display: flex; align-items: center; min-height: 46px; border-top: 1px dashed var(--rule); padding-left: 28px; }
.sub-items .tick span { width: 20px; height: 20px; }
.pending-mark { color: var(--muted); font-size: .75rem; margin-left: 6px; }
.empty { padding: 40px 24px 40px 60px; color: var(--muted); }
.empty b { color: var(--ink); display: block; margin-bottom: 4px; }

.toggle-done { all: unset; box-sizing: border-box; display: flex; gap: 8px; align-items: center; width: 100%;
  padding: 18px 16px 10px 60px; color: var(--muted); font-weight: 600; font-size: .9rem; cursor: pointer; }
.toggle-done svg { width: 18px; height: 18px; transition: transform .15s; }
.toggle-done[aria-expanded="true"] svg { transform: rotate(90deg); }

.banner { margin: 10px 14px; padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--pencil) 22%, var(--paper));
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner p { flex: 1; min-width: 12em; }
.banner .btn { padding: 8px 14px; }

/* The add field sits at the bottom, above the keyboard, always ready. */
.add-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; max-width: 640px; margin: 0 auto;
  padding: 10px 12px calc(10px + var(--safe-b)); background: var(--paper); border-top: 1px solid var(--rule);
  display: flex; gap: 8px;
}
.add-bar input { flex: 1; min-width: 0; border: 1.5px solid var(--rule); border-radius: 12px; padding: 12px 14px; background: var(--paper);
  font-size: 1.02rem; }
.add-bar input:focus { border-color: var(--ink-soft); outline: none; }
.add-bar button { border: 0; border-radius: 12px; background: var(--pencil); color: var(--pencil-ink); width: 52px; display: grid; place-items: center; }
.add-bar button svg { width: 24px; height: 24px; stroke-width: 2.4; }
@media (min-width: 700px) { .add-bar { bottom: 24px; border-radius: 0 0 14px 14px; } }

/* Collections: read first. */
.search { padding: 0 14px 12px; }
.search input { width: 100%; border: 1.5px solid var(--rule); border-radius: 12px; padding: 10px 14px; background: var(--paper); }
.tools { display: flex; gap: 8px; padding: 0 14px 12px; flex-wrap: wrap; }
.tools .btn { flex: 1 1 auto; padding: 9px 12px; font-size: .92rem; }
.tools .btn svg { width: 18px; height: 18px; }
.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 650; background: var(--ink); color: var(--paper);
  display: inline-flex; align-items: center; gap: 8px; justify-content: center; text-decoration: none;
}
.btn.pencil { background: var(--pencil); color: var(--pencil-ink); }
.btn.ghost { background: none; color: var(--ink); border: 1.5px solid var(--rule); }
.btn.danger { background: none; color: var(--danger); border: 1.5px solid var(--rule); }
.btn.wide { width: 100%; }
.btn svg { width: 20px; height: 20px; }
.btn:disabled { opacity: .5; }
.badge { display: inline-block; font-size: .75rem; border-radius: 6px; padding: 1px 7px; background: var(--rule); color: var(--ink-soft); }
.lock { display: inline-flex; align-items: center; gap: 4px; }

/* Meal plan days. */
.days li { align-items: stretch; }
.pager { display: flex; align-items: center; gap: 4px; padding: 0 8px 6px; }
.pager .grow { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pager b { font-size: .95rem; }
.pager .fwd svg { transform: scaleX(-1); }
.link { all: unset; cursor: pointer; color: var(--muted); font-size: .82rem; text-decoration: underline; text-underline-offset: 2px; }
.link:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.days .past .day { opacity: .5; }
.weekday-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 0 12px; }
.period-preview { margin: -4px 0 14px; }
.chip.taken { border-style: dashed; }
.days .day { flex: none; width: 46px; display: grid; place-items: center; align-content: center; line-height: 1.1; text-align: center; padding: 8px 0; }
.days .day b { font-size: .8rem; color: var(--muted); font-weight: 600; }
.days .day span { font-size: 1.1rem; font-weight: 700; }
.days .today .day b, .days .today .day span { color: var(--pencil-ink); }
.days .today .day { background: var(--pencil); }
.days .meals { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.days .meal { all: unset; box-sizing: border-box; display: block; padding: 12px 14px; cursor: pointer; }
.days .meal + .meal { border-top: 1px dashed var(--rule); }
.days .meal span { display: block; color: var(--muted); font-size: .82rem; }
.days .free { color: var(--muted); font-style: italic; }
.days .add-meal { all: unset; box-sizing: border-box; padding: 12px 14px; color: var(--muted); cursor: pointer; display: flex; gap: 6px; align-items: center; }
.days .add-meal svg { width: 18px; height: 18px; }

/* Sheets: everything that is not the list itself slides up from the bottom. */
dialog.sheet {
  margin: auto 0 0; width: 100%; max-width: 100%; max-height: 92dvh; border: 0; padding: 0;
  border-radius: 18px 18px 0 0; background: var(--paper); color: var(--ink); overflow: auto;
}
dialog.sheet::backdrop { background: rgba(17, 22, 28, .5); }
@media (min-width: 700px) { dialog.sheet { max-width: 600px; margin: auto auto 0; } }
@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: up .2s ease-out; }
  @keyframes up { from { transform: translateY(30%); } }
}
.sheet-in { padding: 6px 18px calc(18px + var(--safe-b)); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 6px 6px 18px; position: sticky; top: 0; background: var(--paper); z-index: 1; }
.sheet-head h2 { flex: 1; font-size: 1.2rem; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--rule); margin: 8px auto 0; }
.field { display: grid; gap: 5px; margin: 0 0 14px; }
.field > span { font-size: .85rem; color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%; border: 1.5px solid var(--rule); border-radius: 12px; padding: 11px 13px; background: var(--paper); font-size: 1rem;
}
.field textarea { min-height: 80px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: grid; gap: 10px; }
.menu { list-style: none; margin: 0 -18px; padding: 0; }
.menu li + li { border-top: 1px solid var(--rule); }
.menu button, .menu a { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 14px; width: 100%; padding: 15px 22px; cursor: pointer; }
.menu button:active, .menu a:active { background: var(--rule); }
.menu .ic { color: var(--ink-soft); }
.menu .danger { color: var(--danger); }
.menu .danger .ic { color: var(--danger); }
.menu span small { display: block; color: var(--muted); font-size: .82rem; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 14px; }
.preset {
  border: 1.5px solid var(--rule); background: var(--paper); border-radius: 14px; padding: 16px 6px 12px;
  display: grid; justify-items: center; gap: 8px; font-weight: 600; font-size: .92rem;
}
.preset .ic { width: 28px; height: 28px; color: var(--c, var(--ink-soft)); }
.preset:active { background: var(--rule); }
.picks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pick { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border: 1.5px solid var(--rule); border-radius: 12px; cursor: pointer; }
.pick:active { background: var(--rule); }
.pick b { flex: 1; font-weight: 600; }
.pick span { color: var(--muted); font-size: .84rem; }
.day-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 14px; }
.day-chips .chip { padding: 8px 12px; }
.kids { list-style: none; margin: 0 0 12px; padding: 0; }
.kids li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--rule); min-height: 44px; }
.kids li input { flex: 1; min-width: 0; border: 0; background: none; padding: 8px 0; font-size: 1rem; }
.kids li input:focus { outline: none; }
.kids .icon-btn { width: 36px; height: 36px; }
.kids .icon-btn svg { width: 18px; height: 18px; }
.readout { white-space: pre-wrap; color: var(--ink-soft); margin: 0 0 14px; }
.people { list-style: none; margin: 0 0 14px; padding: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.people li b { flex: 1; font-weight: 550; }
.members li { padding: 4px 0; min-height: 44px; }
.tag { font-size: .75rem; color: var(--muted); border: 1px solid var(--rule); border-radius: 999px; padding: 1px 8px; }
.people .grow { flex: 1; }
.people select { border: 1.5px solid var(--rule); border-radius: 10px; padding: 6px 8px; background: var(--paper); }
.token { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; word-break: break-all; background: var(--rule);
  padding: 10px 12px; border-radius: 10px; }
h3.sheet-sub { font-size: 1rem; margin: 18px 0 8px; }
.error { color: var(--danger); font-size: .92rem; margin: 0 0 10px; }

/* Inputs outside .field (settings rows, share pickers) look the same. */
.page input:not([type=checkbox]), .page select, .row2 > input, .row2 > select, .card select, .people select {
  border: 1.5px solid var(--rule); border-radius: 12px; padding: 10px 12px; background: var(--paper); font-size: 1rem; min-width: 0;
}
.page form.row2 { align-items: stretch; }

/* Settings and admin pages. */
.page { padding: 0 16px 24px; }
.page section { margin-top: 22px; }
.page h2 { font-size: 1.05rem; margin-bottom: 10px; }
.card { border: 1.5px solid var(--rule); border-radius: 14px; padding: 14px; }
.card + .card { margin-top: 10px; }
.card h3 { font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.card p { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.users { list-style: none; margin: 0; padding: 0; }
.users li { display: flex; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.users li div { flex: 1; min-width: 0; }
.users li span { color: var(--muted); font-size: .85rem; display: block; }

/* Toasts sit above the add field. */
#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(86px + var(--safe-b)); z-index: 30; display: grid; gap: 8px;
  justify-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 560px;
  background: var(--ink); color: var(--paper); border-radius: 12px; padding: 11px 15px; font-size: .95rem; box-shadow: var(--shadow);
  transition: opacity .3s, transform .3s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
.toast button { background: none; border: 0; color: var(--pencil); font-weight: 700; padding: 0; }

/* Login and invite pages. */
.auth { max-width: 380px; margin: 0 auto; padding: calc(var(--safe-t) + 12vh) 22px 40px; }
.auth h1 { font-size: 2rem; margin-bottom: 4px; display: flex; align-items: center; gap: 12px; }
.auth h1 img { width: 44px; height: 44px; }
.auth .lead { color: var(--muted); margin-bottom: 26px; }
.loading { padding: 60px 24px; text-align: center; color: var(--muted); }

/* Drag and drop: a grip per row; the row follows the finger as a ghost. */
.grip { flex: none; width: 44px; align-self: stretch; display: grid; place-items: center; border: 0; background: none;
  color: var(--muted); opacity: .55; touch-action: none; cursor: grab; padding: 0; }
.grip svg { width: 22px; height: 22px; stroke-width: 3.2; }
.grip:active, .grip:focus-visible { opacity: 1; }
.drag-ghost { position: fixed; z-index: 60; margin: 0; list-style: none; display: flex; align-items: center;
  background: var(--paper); box-shadow: var(--shadow); border-radius: 10px; pointer-events: none; opacity: .97; }
.drag-src { opacity: .3; }
.drop-line { position: fixed; z-index: 59; height: 3px; border-radius: 2px; background: var(--pencil-deep); pointer-events: none; }
.drop-on { background: color-mix(in srgb, var(--pencil) 28%, var(--paper)); }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
.meal-row { display: flex; align-items: stretch; }
.meal-row .meal { flex: 1; min-width: 0; }
.days .meal-row + .meal-row { border-top: 1px dashed var(--rule); }
