:root {
  --bg: #f6f7f4; --fg: #1d2420; --muted: #66726a; --card: #fff; --line: #dfe4dd;
  --accent: #2f6f4f; --accent-fg: #fff; --danger: #b3261e; --flash: #fff3b0;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #131715; --fg: #e8ede9; --muted: #98a59c; --card: #1c221f; --line: #2c3530; --accent: #4fae80; --accent-fg: #07130d; --danger: #ff8a80; --flash: #4a4413; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
input, select { min-height: 44px; width: 100%; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
label { display: block; margin: 10px 0; font-size: .9rem; color: var(--muted); }
label input { margin-top: 4px; color: var(--fg); }
.error { color: var(--danger); min-height: 1.4em; margin: 6px 0; font-size: .9rem; }

#main { max-width: 760px; margin: 0 auto; padding: 0 12px 96px; }
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; padding: calc(env(safe-area-inset-top) + 10px) 0 8px; background: var(--bg); }
.top input { flex: 1; }
.icon { width: 44px; padding: 0; font-size: 1.4rem; }
.sync { min-height: 32px; padding: 0 10px; font-size: .75rem; color: var(--muted); white-space: nowrap; border-radius: 999px; }
.sync[data-state="offline"], .sync[data-state="pending"] { color: var(--danger); }
.tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tabs button { flex: 0 0 auto; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.tabs select { margin-left: auto; width: auto; }
.hint { width: 100%; margin-bottom: 8px; background: var(--flash); }
.empty { text-align: center; color: var(--muted); margin: 40px 0; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.item.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--flash); } }
.item .main { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 4px 0; min-height: 44px; }
.item .name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item .meta { display: block; font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.zero .name { opacity: .5; text-decoration: line-through; }
.item .loc { flex: none; min-width: 58px; text-align: center; font-weight: 700; font-size: 1.1rem; padding: 6px 8px; border-radius: 10px; background: var(--accent); color: var(--accent-fg); white-space: nowrap; }
.item .qty { flex: none; display: flex; align-items: center; gap: 2px; }
.item .qty button { width: 40px; padding: 0; }
.item .qty span { min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; }

.shelf { display: grid; grid-template-columns: 28px repeat(2, 1fr); gap: 6px; align-items: stretch; }
.shelf .axis { display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 600; }
.shelf .cell { min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px; }
.shelf .cell b { font-size: .8rem; color: var(--muted); }
.shelf .cell span { font-size: 1.3rem; font-weight: 700; }
.shelf .cell.has { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.shelf .cell.has b { color: inherit; opacity: .8; }

.fab { position: fixed; right: calc(env(safe-area-inset-right) + 18px); bottom: calc(env(safe-area-inset-bottom) + 18px); width: 62px; height: 62px; padding: 0; border-radius: 50%; background: var(--accent); color: var(--accent-fg); border: 0; font-size: 2rem; box-shadow: 0 4px 14px rgba(0,0,0,.3); z-index: 6; }

.sheet { border: 0; border-radius: 18px 18px 0 0; padding: 16px; width: min(100%, 560px); max-width: 100%; margin: auto auto 0; background: var(--bg); color: var(--fg); max-height: 96dvh; overflow: auto; }
.sheet::backdrop { background: rgba(0,0,0,.45); }
.sheet h2 { margin: 0 0 4px; font-size: 1.2rem; }
.sheet.small { padding: 8px; }
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 18px; } }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.field { margin: 10px 0; }
.field label, .lbl { margin: 0 0 4px; display: block; font-size: .9rem; color: var(--muted); }
.field small { color: var(--muted); }
.stepper { display: flex; gap: 6px; }
.stepper button { width: 48px; padding: 0; font-size: 1.3rem; }
.stepper input { text-align: center; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 22px; min-height: 22px; margin: 0; }
.actions { display: flex; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }
.comp-grid { display: grid; grid-template-columns: 24px repeat(2, 1fr); gap: 4px; margin: 8px 0 4px; }
.comp-grid .axis { display: flex; align-items: center; justify-content: center; font-size: .8rem; color: var(--muted); }
.comp-grid button { min-height: 40px; padding: 0; border-radius: 8px; font-size: .85rem; }
.comp-grid .wide, .shelf .wide { grid-column: 1 / -1; }
.comp-grid button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 700; }
.menu-item { display: block; width: 100%; text-align: left; margin: 4px 0; padding: 12px 14px; line-height: 20px; text-decoration: none; color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card { width: min(100%, 360px); background: var(--card); padding: 20px; border: 1px solid var(--line); border-radius: 16px; }
.card h1 { margin: 0 0 8px; font-size: 1.4rem; }
.card button { width: 100%; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; }
