@font-face {
  font-family: 'Source Sans 3';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/source-sans-3.woff2') format('woff2');
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/source-serif-4.woff2') format('woff2');
}

/* Bestandsbuch: a calm stock ledger. Warm paper, ink, one green accent for
   actions and healthy stock, rust for alarms, amber for "soon". Serif for
   figures and titles, sans for everything you read or tap. */
:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --sunk: #efede6;
  --ink: #1d1f1e;
  --soft: #5f6461;
  --rule: #e2dfd6;
  --field: #c9c6bc;
  --track: #e9e6dd;
  --accent: #2e5e4e;
  --accent-bg: #2e5e4e;
  --accent-bg-hover: #244b3e;
  --on-accent: #ffffff;
  --accent-wash: #e4ece7;
  --warn: #a8452a;
  --warn-wash: #f7e3da;
  --amber: #7d5a0c;
  --amber-wash: #f6ead0;
  --focus: #2e5e4e;
  --scrim: rgba(29, 31, 30, 0.45);
  --seg-on: #ffffff;

  --serif: 'Source Serif 4', Georgia, serif;
  --sans: 'Source Sans 3', system-ui, sans-serif;
  --gutter: 20px;
  --radius: 8px;
  --bar: 56px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #111a16;
    --surface: #18221d;
    --sunk: #1d2923;
    --ink: #e9e7e1;
    --soft: #a4a8a4;
    --rule: #283530;
    --field: #3a4842;
    --track: #25312b;
    --accent: #8cc3ad;
    --accent-bg: #3c7a64;
    --accent-bg-hover: #458b72;
    --on-accent: #ffffff;
    --accent-wash: #1c2c25;
    --warn: #ea8c6f;
    --warn-wash: #33231c;
    --amber: #ddb35c;
    --amber-wash: #2e2a16;
    --focus: #8cc3ad;
    --scrim: rgba(0, 0, 0, 0.6);
    --seg-on: #34433c;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #111a16;
  --surface: #18221d;
  --sunk: #1d2923;
  --ink: #e9e7e1;
  --soft: #a4a8a4;
  --rule: #283530;
  --field: #3a4842;
  --track: #25312b;
  --accent: #8cc3ad;
  --accent-bg: #3c7a64;
  --accent-bg-hover: #458b72;
  --on-accent: #ffffff;
  --accent-wash: #1c2c25;
  --warn: #ea8c6f;
  --warn-wash: #33231c;
  --amber: #ddb35c;
  --amber-wash: #2e2a16;
  --focus: #8cc3ad;
  --scrim: rgba(0, 0, 0, 0.6);
  --seg-on: #34433c;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html:has(dialog[open]) { overflow: hidden; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

::selection { background: var(--accent-wash); color: var(--ink); }

h1, h2, h3, p, ol, ul, dl, dd, figure { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
table { border-collapse: collapse; }

button, summary, .stepper, .segmented, .file-btn {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1[tabindex='-1']:focus { outline: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon { display: block; flex: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Layout ------------------------------------------------------------------ */

.wrap {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}
.wrap.is-narrow { max-width: 720px; }

.page { padding-top: 28px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }

/* Top bar ------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--bar); }
.mark { font-family: var(--serif); font-weight: 600; font-size: 20px; letter-spacing: -0.01em; text-decoration: none; white-space: nowrap; }
.nav { display: flex; align-items: center; gap: 2px; }
.nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  color: var(--soft);
  font-weight: 500;
  font-size: 15px;
  text-decoration: none;
  white-space: nowrap;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current='page'] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.nav .badge { min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: var(--surface); font-size: 12px; font-weight: 600; line-height: 18px; text-align: center; }
@media (max-width: 560px) {
  .nav a { padding: 0 7px; font-size: 14px; }
  .mark { font-size: 18px; }
}

/* Page headers --------------------------------------------------------------- */

.page-head { margin-bottom: 28px; }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin: -12px 0 2px -6px; padding-right: 8px; color: var(--soft); text-decoration: none; font-weight: 500; font-size: 15px; }
.back:hover { color: var(--ink); }
.page-head h1 { font-family: var(--serif); font-size: 32px; font-weight: 600; line-height: 1.15; letter-spacing: -0.015em; text-wrap: balance; }
.page-head p { margin-top: 6px; color: var(--soft); max-width: 62ch; text-wrap: pretty; }

.section { margin-top: 40px; }
.section > h2 { font-family: var(--serif); font-size: 21px; font-weight: 600; margin-bottom: 6px; }
.lede { color: var(--soft); max-width: 62ch; margin-bottom: 14px; text-wrap: pretty; }

/* Home summary ----------------------------------------------------------- */

.summary { display: grid; gap: 30px; padding-bottom: 30px; border-bottom: 1px solid var(--rule); }
@media (min-width: 820px) { .summary { grid-template-columns: 0.9fr 1.1fr; gap: 56px; } }
.days { font-family: var(--serif); font-size: 26px; line-height: 1.1; }
.days-lead { display: block; color: var(--soft); margin-bottom: 4px; }
.days b { font-size: 76px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; margin-right: 8px; }
.summary-text { margin-top: 12px; color: var(--soft); max-width: 46ch; text-wrap: pretty; }
.summary-text strong { color: var(--ink); font-weight: 600; }
.summary .btn-row { margin-top: 20px; }

.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.chart-head h2 { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.chart-head span { font-size: 14px; color: var(--soft); }
.bars { display: grid; grid-template-columns: max-content 1fr 46px; column-gap: 14px; row-gap: 10px; margin-top: 14px; }
.bar { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; align-items: center; font-size: 15px; text-decoration: none; }
.bar-name { white-space: nowrap; color: var(--soft); }
.bar-track { position: relative; height: 10px; border-radius: 2px; background: var(--track); }
.bar-track i { position: absolute; inset: 0 auto 0 0; border-radius: 2px; background: var(--accent); transform-origin: left; }
.bar-track b { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); }
.bar-val { text-align: right; font-weight: 600; }
.bar.is-weak .bar-name { color: var(--warn); font-weight: 600; }
.bar.is-weak .bar-track i { background: var(--warn); }
a.bar:hover .bar-name { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
@media (prefers-reduced-motion: no-preference) {
  .bars.is-fresh .bar-track i { animation: bar-grow 700ms var(--ease-out) both; animation-delay: calc(var(--i) * 50ms); }
}
@keyframes bar-grow { from { transform: scaleX(0); } }
@media (max-width: 560px) {
  .bars { grid-template-columns: 1fr 46px; }
  .bar { row-gap: 4px; }
  .bar-name { white-space: normal; }
  .bar-val { grid-row: 1; grid-column: 2; }
  .bar-track { grid-column: 1 / -1; }
}

/* Notices ---------------------------------------------------------------- */

.notices { display: grid; gap: 8px; margin-top: 22px; }
.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--sunk);
  color: var(--ink);
  font-size: 16px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.notice span { text-wrap: pretty; }
.notice b { font-weight: 600; }
.notice .icon { margin-left: auto; color: var(--soft); }
.notice.is-amber { background: var(--amber-wash); }
.notice.is-warn { background: var(--warn-wash); }
.notice.is-warn b { color: var(--warn); }
.notice:hover span { text-decoration: underline; text-underline-offset: 3px; }
/* A notice that asks something: not a link, with its answers as buttons. */
.notice.is-ask { flex-wrap: wrap; cursor: default; }
.notice.is-ask:hover span { text-decoration: none; }
.notice.is-ask > span { flex: 1 1 260px; }
.notice.is-ask > .notice-actions { flex: 0 1 auto; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Ledger ------------------------------------------------------------------- */

.ledger { width: 100%; margin-top: 28px; font-size: 16px; }
.ledger thead th {
  position: sticky;
  top: calc(var(--bar) + env(safe-area-inset-top));
  z-index: 2;
  padding: 10px 12px 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--ink);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--soft);
}
.ledger thead th:last-child { padding-right: 0; }
.ledger thead th.num { text-align: right; }
.ledger .cat th { padding: 28px 0 8px; border-bottom: 1px solid var(--rule); text-align: left; font-weight: 400; }
.cat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.cat-name { font-family: var(--serif); font-size: 21px; font-weight: 600; text-decoration: none; }
a.cat-name:hover { text-decoration: underline; text-underline-offset: 4px; }
.cat-meta { color: var(--soft); font-size: 14px; font-weight: 500; white-space: nowrap; }
.cat-meta .is-warn { color: var(--warn); font-weight: 600; }
.ledger tbody tr:not(.cat) > * { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.ledger tbody tr:not(.cat) > :last-child { padding-right: 0; }
.ledger tbody tr:not(.cat) th { text-align: left; font-weight: 500; }
.ledger tbody th a { text-decoration: none; }
.ledger tbody th a:hover { text-decoration: underline; text-underline-offset: 3px; }
.ledger tbody th small { display: block; color: var(--soft); font-size: 14px; font-weight: 400; }
.tag-review { display: block; color: var(--warn); font-size: 14px; font-weight: 600; }
.col-mhd { font-size: 15px; white-space: nowrap; }
.num { text-align: right; white-space: nowrap; }
.num b { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.num span { color: var(--soft); }
.ledger tr.is-empty .num b { color: var(--warn); }
.ledger .col-act { width: 1%; }
.add-row { margin-top: 18px; }
@media (max-width: 600px) {
  .ledger thead { display: none; }
  .ledger, .ledger tbody, .ledger .cat, .ledger .cat th { display: block; }
  .ledger tbody tr:not(.cat) {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    column-gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--rule);
  }
  .ledger tbody tr:not(.cat) > * { padding: 0; border: 0; }
  .ledger tbody tr:not(.cat) th { grid-column: 1; grid-row: 1; }
  .col-mhd { grid-column: 1; grid-row: 2; font-size: 14px; }
  .ledger .num { grid-column: 2; grid-row: 1 / 3; }
  .ledger .col-act { grid-column: 3; grid-row: 1 / 3; width: auto; }
}

/* Best-before labels: a word, then the date, never colour alone. */

.mhd-pair { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.mhd { font-weight: 600; }
.mhd.is-expired { color: var(--warn); }
.mhd.is-soon { color: var(--amber); }
.mhd.is-later { color: var(--ink); }
.mhd.is-ok, .mhd.is-none { font-weight: 400; color: var(--soft); }
.mhd-date { color: var(--soft); }

/* Steppers ------------------------------------------------------------------- */

.steps {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.steps button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 44px;
  border: 0;
  background: none;
  cursor: pointer;
}
.steps button + button { border-left: 1px solid var(--rule); }
.steps button:hover { background: var(--sunk); }
.steps button:active { background: var(--accent-wash); }
.steps button:disabled { color: var(--field); cursor: default; background: none; }

/* Buttons --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--field);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms;
}
.btn:hover { background: var(--sunk); }
.btn.is-primary { background: var(--accent-bg); border-color: var(--accent-bg); color: var(--on-accent); }
.btn.is-primary:hover { background: var(--accent-bg-hover); }
.btn.is-danger { color: var(--warn); }
.btn.is-danger:hover { background: var(--warn-wash); }
.btn.is-quiet { border-color: transparent; background: transparent; padding: 0 10px; }
.btn.is-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  cursor: pointer;
}
.text-btn.is-danger { color: var(--warn); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--soft);
  cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover { color: var(--ink); background: var(--sunk); }

/* Tables: expiry list, log, batches ---------------------------------------- */

.table { width: 100%; font-size: 16px; }
.table th, .table td { padding: 12px 12px 12px 0; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table thead th { padding-top: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--soft); border-bottom-color: var(--ink); }
.table thead th.num { text-align: right; }
.table tbody th { font-weight: 500; }
.table small { display: block; color: var(--soft); font-size: 14px; font-weight: 400; }
.table a { text-decoration: none; }
.table a:hover { text-decoration: underline; text-underline-offset: 3px; }
.table .delta { font-weight: 600; }
.table td.num, .table th.num { text-align: right; }
@media (min-width: 601px) {
  .table.is-log { table-layout: fixed; }
  .table.is-log thead th:nth-child(2) { width: 170px; }
  .table.is-log thead th:nth-child(3) { width: 90px; }
}
.table .group-toggle { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.table .group-toggle .icon { color: var(--soft); transition: transform 200ms var(--ease-out); }
.table .group-toggle[aria-expanded='true'] .icon { transform: rotate(180deg); }
.table tr.is-nested > :first-child { padding-left: 18px; box-shadow: inset 1px 0 0 var(--rule); }
.show-sm { display: none !important; }
@media (max-width: 600px) { .show-sm { display: block !important; } }
.table .is-reversed { color: var(--soft); text-decoration: line-through; }
.table .is-spoiled { color: var(--warn); }
.table .is-minus { color: var(--soft); }
.row-btn { all: unset; cursor: pointer; }
.row-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.row-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

.kind { font-size: 14px; font-weight: 600; }
.kind.is-arrival { color: var(--accent); }
.kind.is-used { color: var(--soft); }
.kind.is-spoiled { color: var(--warn); }
.kind.is-correction { color: var(--soft); font-style: italic; }
.tag-reversed { color: var(--soft); font-size: 14px; }

@media (max-width: 600px) {
  .table.is-stacking, .table.is-stacking tbody { display: block; }
  .table.is-stacking thead { display: none; }
  .table.is-stacking tr { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; row-gap: 2px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
  .table.is-stacking tr > * { padding: 0; border: 0; }
  .table.is-stacking .num { grid-column: 2; grid-row: 1 / 3; align-self: center; }
  .table.is-stacking .full { grid-column: 1 / -1; }
  .table.is-stacking .hide-sm { display: none; }
  .table.is-stacking tr.is-nested { margin-left: 2px; padding-left: 16px; border-left: 1px solid var(--rule); }
  .table.is-stacking tr.is-nested > :first-child { padding-left: 0; box-shadow: none; }
}


.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; }
.facts dt { color: var(--soft); }
.facts dd { font-weight: 500; }

.page-head .figure { font-family: var(--serif); font-size: 22px; margin-top: 14px; color: var(--soft); }
.figure b { color: var(--ink); font-size: 52px; font-weight: 600; letter-spacing: -0.02em; margin-right: 6px; }

.empty { padding: 32px 0; }
.empty b { display: block; font-family: var(--serif); font-size: 22px; font-weight: 600; }
.empty p { margin-top: 6px; color: var(--soft); max-width: 46ch; }

/* Forms ----------------------------------------------------------------- */

.field { display: grid; gap: 8px; }
.field + .field { margin-top: 22px; }
.field-label { font-weight: 600; }
.field-hint { font-size: 15px; color: var(--soft); text-wrap: pretty; }

.input, .select {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--field);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  caret-color: var(--accent);
}
.input:focus, .select:focus { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); outline-offset: 0; }
.input::placeholder { color: var(--soft); }
.select {
  appearance: none;
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--soft) 50%), linear-gradient(135deg, var(--soft) 50%, transparent 50%);
  background-position: calc(100% - 22px) 21px, calc(100% - 16px) 21px;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

.stepper {
  display: inline-grid;
  justify-self: start;
  width: fit-content;
  grid-template-columns: 48px 68px 48px;
  align-items: center;
  border: 1px solid var(--field);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.stepper button { height: 48px; border: 0; background: none; display: grid; place-items: center; cursor: pointer; }
.stepper button:hover { background: var(--sunk); }
.stepper input {
  width: 100%;
  height: 48px;
  border: 0;
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  background: transparent;
  text-align: center;
  font-weight: 600;
  font-size: 19px;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.segmented {
  display: flex;
  width: 100%;
  max-width: 520px;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--sunk);
}
.segmented label { position: relative; flex: 1 1 0; min-width: 0; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span {
  display: block;
  min-height: 42px;
  padding: 10px 6px;
  border-radius: 7px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  color: var(--soft);
}
.segmented input:checked + span { background: var(--seg-on); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }

.check { display: grid; grid-template-columns: 26px 1fr; gap: 12px; align-items: start; cursor: pointer; }
.check input {
  appearance: none;
  width: 26px; height: 26px;
  margin: 0;
  border: 1px solid var(--field);
  border-radius: 6px;
  background: var(--surface);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.check input:checked { background: var(--accent-bg); border-color: var(--accent-bg); }
.check input:checked::after { content: ''; width: 11px; height: 6px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: translateY(-2px) rotate(-45deg); }
.check b { display: block; font-weight: 600; }
.check small { display: block; color: var(--soft); font-size: 15px; }

.inline-fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.field-optional { margin-left: 4px; font-weight: 400; font-size: 15px; color: var(--soft); }

/* Storage place: a text field with a clear button, and the most used places
   as chips. A chip fills the field; the one matching the field is pressed. */
.place-input { position: relative; }
.place-input .input { padding-right: 50px; }
.place-clear { position: absolute; top: 2px; right: 2px; }
.place-clear[hidden] { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  max-width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--field);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background-color 150ms, border-color 150ms;
}
.chip:hover { background: var(--sunk); }
.chip[aria-pressed='true'] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-wash); font-weight: 600; }
.table .is-none { color: var(--soft); font-weight: 400; }
.batch-actions { column-gap: 20px; row-gap: 0; }

/* Setup -------------------------------------------------------------------- */

.setup-form fieldset { border: 0; padding: 0; margin: 0 0 32px; }
.setup-form legend { padding: 0; margin-bottom: 12px; font-family: var(--serif); font-size: 21px; font-weight: 600; }
.people { display: grid; gap: 14px; }
.people-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.people-row b { display: block; font-weight: 600; }
.people-row small { color: var(--soft); font-size: 15px; }
.preview { padding: 14px 16px; border-radius: var(--radius); background: var(--accent-wash); margin-bottom: 16px; }
.preview b { font-weight: 600; }
.or-line { display: flex; align-items: center; gap: 14px; margin: 36px 0 16px; color: var(--soft); font-size: 15px; }
.or-line::before, .or-line::after { content: ''; flex: 1; border-top: 1px solid var(--rule); }

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

dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 24px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 14px 14px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog.sheet::backdrop { background: var(--scrim); }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 14px; } }
@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: sheet-in 300ms var(--ease-out); }
  dialog.sheet[open]::backdrop { animation: fade-in 200ms ease-out; }
}
@keyframes sheet-in { from { transform: translateY(32px); opacity: 0.5; } }
@keyframes fade-in { from { opacity: 0; } }
.sheet-head { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 12px; padding: 20px var(--gutter) 6px; }
.sheet-head h2 { font-family: var(--serif); font-size: 23px; font-weight: 600; line-height: 1.2; }
.sheet-head p { margin-top: 4px; color: var(--soft); font-size: 15px; }
.sheet-head .icon-btn { margin: -8px -12px 0 0; }
.sheet-body { padding: 16px var(--gutter) calc(22px + env(safe-area-inset-bottom)); }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.sheet-actions .btn { flex: 1 1 140px; }
.form-error { margin-top: 12px; color: var(--warn); font-weight: 600; font-size: 15px; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 30;
  width: min(560px, calc(100% - 24px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.toast .btn { min-height: 42px; background: transparent; border-color: color-mix(in srgb, var(--bg) 35%, transparent); color: var(--bg); }
.toast .btn:hover { background: color-mix(in srgb, var(--bg) 12%, transparent); }
.toast-timer { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--accent-bg); transform-origin: left; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 240ms var(--ease-out); }
  .toast-timer { animation: toast-timer linear forwards; animation-duration: var(--duration, 5000ms); }
}
@keyframes toast-in { from { transform: translate(-50%, 14px); opacity: 0; } }
@keyframes toast-timer { to { transform: scaleX(0); } }

@media (min-width: 900px) { :root { --gutter: 28px; } }

/* Sync ------------------------------------------------------------------ */

.sync-key-hint { cursor: default; margin-bottom: 14px; }
.key-code {
  margin: 14px 0 4px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--sunk);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 17px;
  font-variant-numeric: slashed-zero;
  letter-spacing: 0.04em;
  line-height: 1.6;
  word-spacing: 0.2em;
  overflow-wrap: anywhere;
  user-select: all;
}
.key-input { min-height: 0; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; resize: vertical; }
.qr-frame { display: grid; place-items: center; margin: 16px 0; }
.qr { display: block; width: min(100%, 280px); height: auto; border-radius: 4px; }

/* The printed key: only the sheet built for it shows on paper. */
.print-sheet { display: none; }
@media print {
  body > :not(.print-sheet) { display: none !important; }
  .print-sheet { display: block; max-width: 16cm; margin: 0 auto; color: #000; font-size: 12pt; }
  .print-sheet h1 { font-family: var(--serif); font-size: 22pt; margin-bottom: 10pt; }
  .print-sheet p { margin: 10pt 0; }
  .print-sheet .qr { width: 6cm; margin: 14pt 0; }
  .print-sheet .key-code { background: none; border: 1px solid #000; font-size: 14pt; }
}

/* The release at the foot of Settings. Five taps unlock sync creation. */
.app-version { display: block; margin: 32px auto 0; padding: 8px 12px; border: 0; background: none; color: var(--soft); font: inherit; font-size: 13px; -webkit-user-select: none; user-select: none; }

/* The hint to put the app on the home screen. */
.install-notice span .icon { display: inline-block; margin: 0 2px; vertical-align: -3px; color: inherit; }
.notice-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin: -8px -6px -8px auto;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--soft);
  cursor: pointer;
}
.notice-close .icon { margin: 0; }
