:root {
  --bg: #eef2f0;
  --surface: #ffffff;
  --ink: #14262b;
  --muted: #5d727a;
  --line: #d3dcd9;
  --accent: #0b7a6e;
  --accent-ink: #ffffff;
  --buoy: #e0561f;
  --amber: #a86b0a;
  --danger: #b3261e;
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10191c;
    --surface: #182428;
    --ink: #e6efed;
    --muted: #8fa5aa;
    --line: #27373c;
    --accent: #5fd0bd;
    --accent-ink: #0b1a18;
    --buoy: #ff7a45;
    --amber: #e6b450;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 var(--font);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 4px;
}
.top h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }
.icon { background: none; border: 0; font-size: 1.8rem; line-height: 1; padding: 4px 10px; border-radius: 10px; }

.searchbar { padding: 6px 16px 10px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.searchbar input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface);
}
.searchbar input:focus { border-color: var(--accent); outline: none; }

main { padding: 0 16px 24px; max-width: 640px; margin: 0 auto; }

/* Lists */
.group h2 {
  font-size: 0.95rem; margin: 18px 0 2px; color: var(--muted);
  display: flex; align-items: center; gap: 10px;
}
.group h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  cursor: pointer;
}
.row:active { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.name { font-weight: 700; overflow-wrap: anywhere; }
.note { color: var(--muted); font-size: 0.92rem; overflow-wrap: anywhere; }

/* The buoy: marks anything that needs replacing */
.buoy {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid transparent;
}
.buoy.on {
  border-color: var(--buoy);
  background: radial-gradient(circle, var(--buoy) 0 38%, transparent 42%);
}

.pill {
  font-size: 0.8rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; flex: none;
  border: 1.5px solid currentColor;
}
.pill.low { color: var(--amber); }
.pill.out { color: var(--accent-ink); background: var(--buoy); border-color: var(--buoy); }
@media (prefers-color-scheme: light) { .pill.out { color: #fff; } }

.empty { color: var(--muted); padding: 28px 4px; }

/* Add / duplicate-check area */
.composer {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin: 4px 0 8px;
}
.composer p { margin: 0 0 8px; }
.composer .line { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.composer select { flex: 1 1 140px; min-width: 0; }
.hint { color: var(--muted); font-size: 0.9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  border: 1.5px solid var(--line); background: var(--bg); border-radius: 99px;
  padding: 4px 12px; font-size: 0.92rem;
}
.chip.arch { border-style: dashed; color: var(--muted); }

/* Controls */
select, input:not([type=search]), textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface);
}
.btn {
  border: 1.5px solid var(--line); background: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-weight: 700;
}
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; padding: 10px 16px; border-radius: 10px; border-width: 1.5px; border-style: solid; }
.danger { color: var(--danger); }
.linkbtn { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 4px 8px; text-decoration: underline; }

/* To replace tab */
.got {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  border: 2px solid var(--buoy); background: none; color: var(--buoy); font-size: 1rem; line-height: 1;
}
.shop { color: var(--accent); font-weight: 700; font-size: 0.9rem; flex: none; padding: 6px 4px; }
.bar { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; gap: 8px; }

/* Activity */
.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 12px 2px; border-bottom: 1px solid var(--line); }
.log .who { font-weight: 700; }
.log .when { color: var(--muted); font-size: 0.85rem; }
.log .what { margin-top: 2px; overflow-wrap: anywhere; }
.log .undone { color: var(--muted); font-size: 0.85rem; font-style: italic; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; padding: 14px 4px; font-size: 0.95rem; color: var(--muted);
  border-top: 3px solid transparent; margin-top: -1px;
}
.tabs button[aria-current=page] { color: var(--ink); font-weight: 700; border-top-color: var(--accent); }
.count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--buoy); color: #fff; font-size: 0.78rem; font-weight: 700; text-align: center;
}

/* Bottom sheets */
.sheet {
  width: min(560px, 100%); max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--bg); color: var(--ink);
  overflow-y: auto;
}
.sheet::backdrop { background: rgba(0, 10, 12, 0.55); }
.sheet .in { padding: 16px 18px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet h3 { margin: 8px 0 0; font-size: 1rem; color: var(--muted); }
.sheet .head { display: flex; justify-content: space-between; align-items: center; }
.sheet label { display: grid; gap: 4px; font-weight: 700; font-size: 0.92rem; }
.sheet label input, .sheet label textarea, .sheet label select { font-weight: 400; font-size: 1rem; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; margin: 0; padding: 0; }
.seg legend { font-weight: 700; font-size: 0.92rem; padding: 0; margin-bottom: 4px; float: left; width: 100%; }
.seg button { background: var(--surface); border: 0; padding: 11px 4px; border-left: 1px solid var(--line); }
.seg button:first-of-type { border-left: 0; }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg button[aria-pressed=true][data-v=out] { background: var(--buoy); color: #fff; }
.toggle {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 14px; font-weight: 700;
}
.toggle[aria-pressed=true] { border-color: var(--buoy); }
.toggle[aria-pressed=true] .buoy { border-color: var(--buoy); background: radial-gradient(circle, var(--buoy) 0 38%, transparent 42%); }
.toggle .buoy { border-color: var(--muted); }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.row-actions .primary { flex: 1; }
.meta { margin: 0; color: var(--muted); font-size: 0.88rem; }
.err { color: var(--danger); margin: 0; min-height: 1.3em; }
.sheet .log li { padding: 10px 0; }
.sheet .log .btn, .log .btn { padding: 4px 12px; font-size: 0.9rem; margin-top: 6px; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; z-index: 50;
  max-width: 90vw; text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

/* Login */
.login { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 20px; }
.login form { width: min(360px, 100%); display: grid; gap: 14px; }
.login h1 { margin: 0 0 6px; }
.login label { display: grid; gap: 4px; font-weight: 700; font-size: 0.92rem; }
.login input { font-weight: 400; }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: pop 0.18s ease-out; }
  @keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }
}

/* Freezer, exclusions, import */
.searchbar { display: flex; gap: 8px; align-items: stretch; }
.searchbar input { flex: 1; min-width: 0; width: auto; }
.chipbtn { border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 0 12px; font-weight: 700; white-space: nowrap; }
.chipbtn[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tag { font-size: 0.8rem; color: var(--accent); font-weight: 700; flex: none; }
.shop.off { color: var(--muted); font-weight: 400; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 0.95rem; }
.check input { width: 20px; height: 20px; padding: 0; flex: none; accent-color: var(--accent); }
.composer .check { margin-top: 10px; }
.tick { width: 16px; height: 16px; border-radius: 4px; border: 2px solid var(--muted); flex: none; }
.toggle[aria-pressed=true] .tick { background: var(--accent); border-color: var(--accent); }
.catrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--line); }
.catrow .cn { flex: 1 1 160px; min-width: 0; }
.catrow .cn2 { font-weight: 700; }
.skiplist { margin: 6px 0 0; padding-left: 18px; font-size: 0.9rem; color: var(--muted); }
#imp-text { font-size: 0.9rem; }

/* Out of stock, collapsible groups, reorder */
.row.is-out .txt { opacity: 0.5; }
.row.is-out .name { text-decoration: line-through; text-decoration-thickness: 2px; }
.gtoggle {
  background: none; border: 0; padding: 8px 0; font: inherit; color: inherit;
  display: flex; align-items: center; gap: 8px; text-align: left; flex: none; max-width: 100%;
}
.chev { display: inline-block; transition: transform 0.15s; width: 1em; }
.group.shut .chev { transform: rotate(-90deg); }
.gcount { font-size: 0.8rem; font-weight: 400; opacity: 0.8; }
.group.shut h2 { margin-bottom: 0; }
.mv { display: flex; gap: 4px; }
.btn.mini { padding: 4px 10px; min-width: 38px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.35; }
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }

/* Roles / people */
.tabs { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 1fr; }
.sheet label.check { display: flex; font-weight: 400; font-size: 0.95rem; }
.person { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.person .pa { display: flex; gap: 6px; flex-wrap: wrap; }
.pform { display: grid; gap: 8px; }
.btn.danger { color: var(--danger); }
