:root {
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  --bg: #f2f4f8;
  --surface: #fff;
  --soft: #edf1f7;
  --text: #161c29;
  --muted: #526178;
  --line: #e0e6ef;
  --blue: #0756c7;
  --blue-fill: #155cd1;
  --blue-soft: #e9f2ff;
  --orange: #a6420a;
  --orange-soft: #fff0e4;
  --red: #a52235;
  --red-fill: #a52235;
  --bar: rgba(250, 252, 255, .96);
  --shadow: 0 10px 28px rgba(32, 54, 97, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121419;
    --surface: #1b202a;
    --soft: #272e3c;
    --text: #eff3fa;
    --muted: #aebbd0;
    --line: #333d4e;
    --blue: #a4caff;
    --blue-fill: #245fcc;
    --blue-soft: #203658;
    --orange: #ffc29c;
    --orange-soft: #482d21;
    --red: #ffa8b6;
    --red-fill: #a32640;
    --bar: rgba(22, 26, 35, .96);
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; border: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:active:not(:disabled) { filter: brightness(.88); }
button:disabled { opacity: .46; cursor: default; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; overflow-wrap: anywhere; }
h1 { font-size: clamp(1.18rem, 4.7vw, 1.7rem); letter-spacing: -.035em; line-height: 1.25; }
h2 { font-size: 1.16rem; letter-spacing: -.025em; }
h3 { font-size: 1.1rem; line-height: 1.35; }
.shell { max-width: 600px; margin-inline: auto; padding: calc(19px + env(safe-area-inset-top)) max(15px, env(safe-area-inset-right)) calc(94px + env(safe-area-inset-bottom)) max(15px, env(safe-area-inset-left)); }
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 18px; }
.heading { display: flex; align-items: center; gap: 10px; }
.heading img { border-radius: 12px; flex: none; }
.save-status { color: var(--muted); font-size: .8125rem; }
.summary { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 21px; box-shadow: var(--shadow); }
.total { color: #fff; padding: 17px 19px 18px; background: linear-gradient(112deg, #164caf, #1c60d4 66%, #266bdf); }
.total > span { color: #eaf3ff; font-size: .875rem; font-weight: 600; }
.total > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin-top: 3px; }
.total strong { font-size: clamp(1.9rem, 7vw, 2.75rem); letter-spacing: -.045em; line-height: 1.1; }
strong, .quantity { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.total small { color: #eaf3ff; font-size: .875rem; }
.subtotals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.subtotals > div { padding: 12px 16px; display: grid; gap: 1px; }
.subtotals > div + div { border-inline-start: 1px solid var(--line); }
.subtotals span { font-size: .875rem; font-weight: 600; }
.subtotals strong { font-size: 1.34rem; }
.current { --accent: var(--blue); --tint: var(--blue-soft); color: var(--accent); }
.returned { --accent: var(--orange); --tint: var(--orange-soft); color: var(--accent); }
.section-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 7px 10px; margin-top: 19px; }
.section-header small { font-size: .8125rem; color: var(--muted); font-weight: 500; margin-inline-start: 4px; }
.primary, .secondary { min-height: 44px; padding: 6px 13px; border-radius: 11px; font-size: .875rem; font-weight: 650; }
.primary { color: #fff; background: var(--blue-fill); }
.secondary { background: var(--soft); color: var(--text); }
.toolbar { margin-block: 9px 11px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.search { display: flex; align-items: center; gap: 10px; padding-inline: 12px; border-radius: 11px; background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.search input { min-width: 0; width: 100%; height: 44px; padding: 0; background: transparent; color: var(--text); border: 0; }
.search input::placeholder { color: var(--muted); }
.search:focus-within { outline: 2px solid var(--blue); }
.search input:focus-visible { outline: none; }
.cards { display: grid; gap: 10px; }
.card, .empty, .settings-group, .history-list { background: var(--surface); border: 1px solid var(--line); border-radius: 17px; }
.card { padding: 10px 12px 12px; box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 1px 9px; }
.card-heading { min-width: 0; }
.card-heading p { margin-top: 3px; font-size: .8125rem; color: var(--muted); }
.edit { flex: none; color: var(--muted); }
.stock-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(142px, 60%); gap: 5px; align-items: center; min-width: 0; padding: 3px 4px 3px 8px; border-radius: 11px; background: var(--tint); }
.stock-row + .stock-row { margin-top: 6px; }
.stock-label { font-size: .875rem; font-weight: 650; overflow-wrap: anywhere; }
.stepper { display: grid; grid-template-columns: 44px minmax(50px,1fr) 44px; gap: 2px; }
.stepper button { border-radius: 9px; min-width: 0; min-height: 44px; padding: 2px; color: var(--accent); background: var(--surface); font-size: 1.3rem; line-height: 1.05; font-weight: 650; }
.stepper .quantity { font-size: 1rem; background: transparent; }
.empty { display: grid; justify-items: center; text-align: center; gap: 7px; padding: 23px 14px; color: var(--muted); }
.empty strong { color: var(--text); }
.empty p, #empty-history { font-size: .875rem; }
.empty .glyph { color: var(--blue); margin-bottom: 2px; }
#history h2, #settings h2 { margin: 16px 0 10px; }
.history-list { margin: 0 0 10px; padding: 0; list-style: none; overflow: hidden; }
.history-list:empty { display: none; }
.history-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(65px, 32%); align-items: center; gap: 6px 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.history-list li:last-child { border-bottom: 0; }
.history-list time, .history-list p, .history-list small { display: block; color: var(--muted); font-size: .8125rem; margin-top: 3px; }
.history-list .change { text-align: end; }
.history-list strong { display: block; }
.wide { width: 100%; }
.settings-group { overflow: hidden; }
.settings-group button, .setting-status { width: 100%; min-height: 51px; background: transparent; text-align: start; padding: 11px 14px; }
.settings-group button { display: flex; flex-wrap: wrap; gap: 4px 8px; justify-content: space-between; align-items: center; }
.settings-group button + button { border-top: 1px solid var(--line); }
.settings-group button span, .note { color: var(--muted); font-size: .875rem; }
.note { line-height: 1.55; padding: 7px 2px; }
.danger-text { color: var(--red); }
.danger-button { background: var(--red-fill); }
.bottom-bar { position: fixed; inset: auto 0 0; z-index: 2; border-top: 1px solid var(--line); background: var(--bar); padding: 4px max(8px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
.nav-inner { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; max-width: 570px; margin: auto; }
.nav-inner button { display: grid; justify-items: center; align-content: center; gap: 4px; min-height: 51px; padding: 4px; border-radius: 10px; font-size: .8125rem; color: var(--muted); background: transparent; }
.nav-inner button[aria-current] { background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.glyph { display: inline-block; flex: none; width: 17px; height: 17px; position: relative; color: inherit; }
.box { border: 1.7px solid currentColor; border-radius: 3px; }
.box::after { content: ""; position: absolute; inset: 4px 4px auto; border-block-start: 1.7px solid currentColor; }
.clock { border: 1.7px solid currentColor; border-radius: 50%; }
.clock::after { content: ""; position: absolute; left: 6px; top: 3px; width: 4px; height: 5px; border-left: 1.7px solid; border-bottom: 1.7px solid; }
.settings-icon { background: linear-gradient(currentColor,currentColor) center 2px/16px 1.7px, linear-gradient(currentColor,currentColor) center/16px 1.7px, linear-gradient(currentColor,currentColor) center 13px/16px 1.7px; background-repeat: no-repeat; }
.settings-icon::after { content: ""; position: absolute; top: 0; left: 4px; width: 2px; height: 6px; background: currentColor; box-shadow: 7px 5px currentColor, 1px 11px currentColor; border-radius: 2px; }
.magnify { height: 14px; width: 14px; border: 1.7px solid; border-radius: 50%; margin-right: 2px; }
.magnify::after { content: ""; position: absolute; width: 6px; height: 1.7px; background: currentColor; transform: rotate(45deg); right: -4px; bottom: -1px; border-radius: 2px; }
dialog { width: min(420px, calc(100% - 26px)); max-height: calc(100% - 26px); overflow: auto; border: 1px solid var(--line); border-radius: 20px; padding: 17px; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(12, 22, 40, .58); }
dialog form { display: grid; gap: 12px; }
dialog p, dialog label span { font-size: .9375rem; line-height: 1.45; }
dialog label { display: grid; gap: 6px; }
dialog input { width: 100%; height: 46px; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 7px 10px; }
.dialog-actions, .sort-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.toast { position: fixed; z-index: 3; bottom: calc(71px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); padding: 9px 14px; border-radius: 11px; background: var(--text); color: var(--surface); font-size: .875rem; text-align: center; pointer-events: none; box-shadow: var(--shadow); }
@media (max-width: 345px) {
  .shell { padding-inline: max(10px, env(safe-area-inset-left)); }
  .heading { gap: 7px; }
  .heading img { width: 36px; height: 36px; }
  .stock-row { grid-template-columns: minmax(0, 1fr) minmax(142px, 62%); }
}
.stepper button.at-limit { opacity: .48; }
