/* One stylesheet, no build step. Sized for a phone first: nothing here is
   narrower than a thumb, and nothing overflows a 320px viewport. */

:root {
  --bg: #fbfaf7;
  --fg: #1c1b19;
  --muted: #6b6862;
  --line: #ddd9d0;
  --card: #ffffff;
  --accent: #2f6f4f;
  --ok: #2f7d4f;
  --warn: #b07d1a;
  --fail: #b23b34;
  --tap: 2.75rem; /* 44px: the smallest target a thumb hits reliably */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --fg: #ece9e3;
    --muted: #9a968e;
    --line: #2e3035;
    --card: #1e2024;
    --accent: #6fbf8f;
    --ok: #6fbf8f;
    --warn: #e0b455;
    --fail: #e8776e;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: break-word;
}

main, .topbar, footer {
  max-width: 42rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--line);
  padding-top: calc(0.75rem + env(safe-area-inset-top));
}

.topbar h1 { font-size: 1.1rem; margin: 0; margin-right: auto; }
.topbar h1 a {
  color: inherit;
  text-decoration: none;
  display: inline-block;
  /* Padding rather than height: the link stays visually the size of its text
     while giving a thumb something to hit. */
  padding: 0.6rem 0.2rem;
}
.who { color: var(--muted); font-size: 0.85rem; }

/* Backup health. The default failure mode of a nightly job is silence, so the
   state is on a page people see every day rather than in a log nobody reads. */
.backup {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}
.backup .dot {
  width: 0.6rem; height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.backup-ok .dot { background: var(--ok); }
.backup-warn { color: var(--warn); font-weight: 600; }
.backup-warn .dot { background: var(--warn); }
.backup-fail, .backup-never {
  color: var(--fail);
  font-weight: 700;
}
.backup-fail .dot, .backup-never .dot { background: var(--fail); }

form.add {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
/* min-width: 0 on every flex item that is an input. A flex item's automatic
   minimum size is its intrinsic width, and an input's intrinsic width comes
   from its default `size` — around 196px. Left at auto, a field refuses to
   shrink below that and takes the whole row from its neighbours. */
form.add input[name="name"] { flex: 1 1 10rem; min-width: 0; }
form.add .quantity { flex: 1 1 5.5rem; min-width: 0; max-width: 8rem; }

input, button {
  font: inherit;
  min-height: var(--tap);
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  padding: 0.4rem 0.6rem;
  background: var(--card);
  color: var(--fg);
  max-width: 100%;
}

button {
  cursor: pointer;
  min-width: var(--tap);
}

form.add button, .bulk button {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  padding-inline: 1rem;
}

ul.items { list-style: none; margin: 0; padding: 0; }

li.item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--line);
}

li.empty {
  color: var(--muted);
  padding: 1.5rem 0;
  text-align: center;
}

.check {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border-radius: 0.6rem;
  background: var(--card);
  position: relative;
}
.check[aria-pressed="true"]::after {
  content: "✓";
  color: var(--ok);
  font-size: 1.3rem;
  line-height: 1;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

form.fields {
  display: flex;
  gap: 0.4rem;
  flex: 1 1 auto;
  min-width: 0;
}
form.fields .name { flex: 1 1 auto; min-width: 0; }
form.fields .quantity {
  flex: 0 0 4.5rem;
  width: 4.5rem;
  min-width: 0; /* see the note above: auto would let it take the whole row */
  text-align: center;
}

li.checked form.fields .name {
  text-decoration: line-through;
  color: var(--muted);
}

.remove {
  flex: none;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  font-size: 1.4rem;
  line-height: 1;
}

.bulk { margin: 1rem 0; }

.error {
  background: color-mix(in srgb, var(--fail) 12%, transparent);
  border: 1px solid var(--fail);
  color: var(--fail);
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
}

.enrol { max-width: 30rem; }
.enrol-form { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.enrol-form input { flex: 1 1 14rem; }
.hint { color: var(--muted); font-size: 0.85rem; }
.hint code { overflow-wrap: anywhere; }

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--line);
  margin-top: 2rem;
}

button.link {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  min-height: var(--tap);
  padding: 0.6rem 0.2rem;
}

footer form { margin: 0; }
