:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1d2321;
  --muted: #66706c;
  --line: #dfe3df;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --accent-soft: #e2f0eb;
  --warn: #b5541c;
  --warn-soft: #fbeadf;
  --danger: #b3261e;
  --ok: #2e7d32;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --card: #1c2120;
    --text: #e8ecea;
    --muted: #9aa5a0;
    --line: #2d3432;
    --accent: #4fb69a;
    --accent-text: #0b1f19;
    --accent-soft: #1d3330;
    --warn: #f0a070;
    --warn-soft: #3a2a1f;
    --danger: #ff8a80;
    --ok: #81c784;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px 96px; }

header.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
}
header.top .row { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
header.top h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { border: 0; background: none; font-size: 26px; line-height: 1; padding: 4px 8px 4px 0; color: var(--accent); cursor: pointer; }

.loc-pick { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; }
.loc-pick label { color: var(--muted); font-size: 14px; }
select {
  min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); flex: 1;
}

h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 8px; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 16px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 96px; padding: 14px; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between;
}
.tile .ico { font-size: 26px; }
.tile .lbl { font-weight: 600; font-size: 17px; }
.tile.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.banner {
  background: var(--warn-soft); color: var(--warn); border-radius: var(--radius);
  padding: 12px 14px; margin-top: 14px; cursor: pointer;
}
.banner b { display: block; margin-bottom: 4px; }
.banner ul { margin: 0; padding-left: 18px; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 8px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); font-weight: 500;
  display: inline-flex; align-items: center; gap: 8px;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); }

.qty { display: flex; align-items: center; gap: 10px; }
.qty button {
  width: 52px; height: 52px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 24px; cursor: pointer;
}
.qty input { width: 110px; height: 52px; text-align: center; font-size: 24px; font-weight: 600; }
input[type=number], input[type=text], input[type=email], input[type=password], textarea {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 10px; min-height: 44px;
  width: 100%;
}
.qty input { width: 110px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px; }
.list .li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list .li:last-child { border-bottom: 0; }
.li .name { flex: 1; min-width: 0; }
.li .name small { display: block; color: var(--muted); font-size: 13px; }
.li input { width: 96px; flex: none; text-align: right; }
.li .num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.in { color: var(--danger); }
.out { color: var(--ok); }
.low { color: var(--warn); font-weight: 600; }
.short { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.filters select { flex: 1 1 140px; }
.search { margin-top: 12px; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.savebar .inner { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.btn {
  min-height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  padding: 0 18px; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); flex: 1; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }

.msg { border-radius: 12px; padding: 12px 14px; margin-top: 14px; }
.msg.err { background: var(--warn-soft); color: var(--danger); }
.msg.ok { background: var(--accent-soft); color: var(--accent); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; white-space: normal; position: sticky; left: 0; background: var(--card); min-width: 150px; }
td:first-child small { color: var(--muted); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }

.hist .li { align-items: flex-start; }
.hist .reversed .name > span { text-decoration: line-through; color: var(--muted); }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 720px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.modal h3 { margin: 0 0 8px; }
.modal .actions { display: flex; gap: 10px; margin-top: 16px; }

.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.login h1 { font-size: 26px; }
.login .field { margin-bottom: 12px; }
.login .btn { width: 100%; }

.main-actions { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 16px; }
.tile.big { min-height: 72px; flex-direction: row; align-items: center; justify-content: flex-start; gap: 14px; }
.tile.big .lbl { font-size: 20px; }
.unit-hint { text-transform: none; letter-spacing: 0; }
a { color: var(--accent); }

select.full { width: 100%; }
select:disabled { opacity: .45; }
.qty-input { width: 100%; max-width: 220px; height: 52px; font-size: 24px; font-weight: 600; text-align: center; }
.qty-input.over { color: var(--danger); border-color: var(--danger); }
.avail { margin: 16px 0 0; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
