:root {
  color-scheme: dark;
  --bg: #0f1012;
  --bg2: #17191c;
  --card: #1d2024;
  --line: #2c3036;
  --fg: #f2f2f0;
  --muted: #9aa0a6;
  --accent: #f5b83d;
  --accent-fg: #1a1300;
  --ok: #4cc77a;
  --low: #f5b83d;
  --out: #ff6b62;
  --mp: #6fa8ff;
  --radius: 12px;
  --top: calc(52px + env(safe-area-inset-top));
  --tabs: calc(60px + env(safe-area-inset-bottom));
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font-size: 16px; line-height: 1.4; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a.btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
h2 { font-size: 20px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ok { color: var(--ok); } .low { color: var(--low); } .out { color: var(--out); }
.hidden { display: none !important; }

/* ---------- header ---------- */
#top {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  height: var(--top); padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
#top .brand { font-weight: 700; letter-spacing: .02em; }
#top .live { flex: 1; text-align: center; font-weight: 700; font-size: 17px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#top .live small { color: var(--muted); font-weight: 500; }
.pill {
  border: 1px solid var(--line); border-radius: 99px; padding: 4px 10px; font-size: 13px;
  background: var(--card); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  color: var(--fg); text-decoration: none;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok::before { background: var(--ok); }
.pill.wait::before { background: var(--low); }
.pill.bad::before { background: var(--out); }
.pill.ok, .pill.wait, .pill.bad { color: var(--fg); }

/* ---------- layout ---------- */
#banners { position: relative; z-index: 5; padding: calc(var(--top) + 8px) 12px 0; }
#banners:empty { padding-bottom: 0; }
main { padding: 8px 12px calc(var(--tabs) + 24px); max-width: 900px; margin: 0 auto; }
body.has-cart main { padding-bottom: calc(var(--tabs) + var(--cart-h, 96px) + 24px); }

#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20; height: var(--tabs);
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg2); border-top: 1px solid var(--line);
}
#tabs a {
  display: flex; align-items: center; justify-content: center; text-decoration: none;
  color: var(--muted); font-weight: 600; font-size: 15px;
}
#tabs a.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.banner { border-radius: var(--radius); padding: 12px; margin: 0 0 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 15px; }
.banner p { margin: 0; flex: 1 1 220px; }
.banner.warn { background: #3a2a05; border: 1px solid #7a5a12; }
.banner.info { background: #132235; border: 1px solid #284a73; }
.banner.bad { background: #3a1210; border: 1px solid #7d2a24; }

/* ---------- buttons & forms ---------- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--fg); font-weight: 600; text-decoration: none; cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.danger { color: var(--out); border-color: #5a2522; }
.big { min-height: 56px; font-size: 18px; padding: 10px 18px; }
.wide { width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }
.small { min-height: 36px; padding: 4px 10px; font-size: 14px; }

label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], input[type=date], input[type=password], input[type=number], input:not([type]), select, textarea {
  width: 100%; font-size: 17px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.check { display: flex; gap: 10px; align-items: center; color: var(--fg); font-size: 16px; }
.check input { width: 22px; height: 22px; }
.error { color: var(--out); margin: 8px 0 0; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button, .seg label.opt {
  flex: 1 1 0; min-width: 64px; min-height: 48px; margin: 0; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); font-weight: 700; font-size: 16px;
}
.seg label.opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg button.on, .seg label.opt:has(input:checked) { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.seg button.on.mp { background: var(--mp); border-color: var(--mp); color: #06142b; }

/* ---------- selling ---------- */
.showbar {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 4px;
}
.showbar .where { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.totals { display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline; margin: 2px 0 8px; }
.totals .grand { font-size: 26px; font-weight: 800; }
.totals span { font-size: 14px; color: var(--muted); }
.totals b { color: var(--fg); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.tile {
  position: relative; min-height: 88px; padding: 8px; border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; text-align: left;
  background: var(--card); border: 2px solid var(--line);
}
.tile:active { transform: scale(.97); }
.tile .v { font-size: 20px; font-weight: 800; line-height: 1.1; word-break: break-word; }
.tile .p { font-size: 15px; font-weight: 600; }
.tile .q { font-size: 13px; color: var(--muted); }
.tile.s-low { border-color: #7a5a12; } .tile.s-low .q { color: var(--low); font-weight: 700; }
.tile.s-out { border-color: #7d2a24; } .tile.s-out .q { color: var(--out); font-weight: 700; }
.tile.noprice { opacity: .5; border-style: dashed; }
.tile.has-pic { justify-content: flex-start; gap: 4px; }
.tile .pic { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; margin-bottom: 2px; background: var(--bg2); }
.tile.noprice .p { color: var(--out); font-size: 13px; }
.tile .badge {
  position: absolute; top: -8px; right: -8px; min-width: 28px; height: 28px; border-radius: 14px; padding: 0 7px;
  background: var(--accent); color: var(--accent-fg); font-weight: 800; display: flex; align-items: center; justify-content: center;
}

#cart {
  position: fixed; left: 0; right: 0; bottom: var(--tabs); z-index: 15;
  background: var(--bg2); border-top: 2px solid var(--accent); padding: 8px 12px 10px;
  max-height: 55vh; display: flex; flex-direction: column;
}
#cart .lines { overflow-y: auto; margin: 0 0 8px; padding: 0; list-style: none; max-height: 30vh; }
#cart .lines li { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
#cart .lines .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#cart .qtybtn { min-width: 44px; min-height: 40px; padding: 0; font-size: 22px; }
#cart .empty { text-align: center; color: var(--muted); padding: 14px 0; }
#cart .pay { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
#cart .confirm { grid-column: 1 / -1; min-height: 60px; font-size: 20px; font-weight: 800; }

/* ---------- tables / lists ---------- */
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
td.r, th.r { text-align: right; }
tr.void td { color: var(--muted); text-decoration: line-through; }
tr.void td.keep { text-decoration: none; }
.scroll { overflow-x: auto; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 800; }
.stat.key { grid-column: 1 / -1; border-color: var(--accent); }
.stat.key .v { font-size: 30px; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list a.rowlink { display: block; color: inherit; text-decoration: none; }

.stockrow { display: flex; gap: 10px; align-items: center; }
.stockrow .what { flex: 1; min-width: 0; }
.stockrow .thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; }
.stockrow .qty { font-size: 22px; font-weight: 800; min-width: 48px; text-align: right; }
.prices { font-size: 13px; color: var(--muted); }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; border: 1px solid currentColor; font-weight: 700; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 12px; right: 12px; z-index: 50; bottom: calc(var(--tabs) + 12px);
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
body.has-cart #toast { bottom: calc(var(--tabs) + var(--cart-h, 96px) + 12px); }
.toast {
  pointer-events: auto; background: #f2f2f0; color: #111; border-radius: 10px; padding: 8px 12px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.5); font-weight: 600; font-size: 15px;
}
.toast p { margin: 0; flex: 1; }
.toast.bad { background: var(--out); color: #fff; }
.toast button { min-height: 38px; background: #111; color: #fff; border-color: #111; }

@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

.vstock { margin: 6px 0; }
.vstock input { max-width: 130px; }
details.card > summary { font-weight: 700; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
details.card[open] > summary { margin-bottom: 4px; }

/* ---------- item picture ---------- */
.picfield { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 4px 0 8px; }
.picprev { width: 96px; height: 96px; border-radius: var(--radius); border: 1px dashed var(--line); display: flex; align-items: center; justify-content: center; overflow: hidden; font-size: 13px; text-align: center; }
.picprev img { width: 100%; height: 100%; object-fit: cover; }
.picfield label.btn { position: relative; overflow: hidden; display: inline-block; margin: 0; color: var(--fg); }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
