:root {
  --bg: #f4f6f4; --card: #ffffff; --ink: #17211b; --muted: #66736b;
  --line: #dfe5e0; --accent: #1f9d55; --accent-ink: #ffffff; --accent-soft: #e4f5ea;
  --car: #2563eb; --car-soft: #e3ecff;
  --warn: #c2410c; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111614; --card: #1a201d; --ink: #eef2ef; --muted: #98a59c;
    --line: #2a332e; --accent: #34c26f; --accent-ink: #062a15; --accent-soft: #163a25;
    --car: #6ea0ff; --car-soft: #1b2a4a;
    --shadow: 0 1px 2px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
button, input { font: inherit; color: inherit; }
button, .btn { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; text-decoration: none; color: inherit; display: inline-block; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.ghost, .btn.ghost { background: transparent; }
button.small { padding: 6px 10px; font-size: 13px; }
button.danger { color: var(--warn); }
button.icon { padding: 8px 12px; font-size: 16px; }
button:hover { filter: brightness(.97); }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

/* ---- top: three big tabs ---- */
.top { position: sticky; top: 0; z-index: 10; display: flex; gap: 10px; align-items: center;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.tabs { flex: 1; display: flex; gap: 8px; }
.tabs button { flex: 1; padding: 12px 10px; font-size: 16px; font-weight: 600; border-radius: 12px; color: var(--muted); background: var(--card); }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
body[data-mode="auto"] .tabs button.on { background: var(--car); color: #fff; }
.intro { margin: 10px 16px 0; font-size: 13px; color: var(--muted); }

.chips { display: flex; gap: 8px; padding: 10px 16px 0; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; border-radius: 999px; padding: 6px 12px; font-size: 13px; border: 1px solid var(--line); background: var(--card); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip .n { opacity: .7; margin-left: 4px; }
.search-wrap { padding: 10px 16px 0; max-width: 1100px; margin: 0 auto; }
.search-wrap input { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }

/* ---- list ---- */
.list { max-width: 1100px; margin: 0 auto; padding: 12px 16px 120px; display: flex; flex-direction: column; gap: 6px; }
.group-h { margin: 14px 4px 2px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; }
.row { display: grid; grid-template-columns: 72px 1fr auto auto; gap: 14px; align-items: center;
  background: var(--card); border: 2px solid transparent; border-radius: 14px; padding: 8px 10px 8px 8px; box-shadow: var(--shadow); transition: border-color .15s; }
.row.counted { border-color: var(--accent); }
body[data-mode="auto"] .row.counted { border-color: var(--car); }
.row.inactive { opacity: .55; }
.row.dragover { border-color: var(--warn); }
.row.locked { opacity: .5; }
.row.locked .qty button, .row.locked .qty input { cursor: not-allowed; }
.thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; background: var(--accent-soft); display: grid; place-items: center; cursor: pointer; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; background: #fff; }
.thumb .ph { font-size: 28px; opacity: .35; }
.thumb .hint { position: absolute; bottom: 3px; right: 3px; font-size: 10px; background: rgba(0,0,0,.55); color: #fff; padding: 1px 5px; border-radius: 5px; opacity: 0; transition: opacity .15s; }
.thumb:hover .hint { opacity: 1; }
.info { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.name { font-weight: 600; line-height: 1.25; }
.meta { font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.price { font-weight: 600; color: var(--ink); }
/* car badge */
.car { display: none; text-align: center; min-width: 74px; padding: 6px 8px; border-radius: 10px; background: var(--car-soft); color: var(--car); cursor: pointer; line-height: 1.1; }
.car b { display: block; font-size: 20px; }
.car small { font-size: 11px; opacity: .8; }
.car.zero { opacity: .45; }
body[data-mode="auto"] .car, body[data-mode="prijem"] .car { display: block; }
.qty { display: grid; grid-template-columns: 44px 84px 44px; gap: 6px; }
.qty button { padding: 0; height: 44px; font-size: 22px; border-radius: 10px; }
.qty input { height: 44px; text-align: center; font-size: 20px; font-weight: 700; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); width: 100%; min-width: 0; }
.qty input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.qty input::placeholder { color: var(--muted); font-weight: 400; font-size: 13px; }
.row.counted .qty input { background: var(--accent-soft); }
body[data-mode="auto"] .row.counted .qty input { background: var(--car-soft); }

.bottom { position: fixed; bottom: 0; left: 0; right: 0; display: flex; gap: 14px; align-items: center; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); flex-wrap: wrap; }
.progress { flex: 1 1 220px; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bar { flex: 1; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
body:not([data-mode="inventura"]) .bar { display: none; }
#btnReset { order: 1; }
.foot-actions { order: 2; display: none; gap: 8px; align-items: center; flex-wrap: wrap; }
body[data-mode="auto"] .foot-actions[data-for="auto"], body[data-mode="prijem"] .foot-actions[data-for="prijem"], body[data-mode="inventura"] .foot-actions[data-for="inventura"] { display: flex; }
body[data-mode="auto"] button.primary { background: var(--car); color: #fff; }
.toggle { font-size: 13px; display: flex; align-items: center; gap: 6px; }

.drop-overlay { position: fixed; inset: 0; display: none; place-items: center; background: rgba(31,157,85,.18); border: 4px dashed var(--accent); z-index: 50; pointer-events: none; text-align: center; font-size: 22px; font-weight: 700; }
.drop-overlay small { font-weight: 400; font-size: 14px; }
.drop-overlay.on { display: grid; }

dialog { border: none; border-radius: 16px; padding: 0; background: var(--card); color: var(--ink); max-width: 560px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 18px; }
dialog .hint { margin: 0; font-size: 13px; color: var(--muted); }
dialog .row { display: block; position: relative; padding-left: 28px; font-size: 14px; background: none; border: none; box-shadow: none; }
dialog .row input { position: absolute; left: 2px; top: 3px; margin: 0; }
dialog .row small { display: block; color: var(--muted); margin-top: 2px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 6px 0 0; padding: 0; }
.img-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.url-row { display: flex; gap: 8px; }
.url-row input { flex: 1; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--warn); color: #fff; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

@media (max-width: 640px) {
  .top { padding: 8px 10px; }
  .tabs button { padding: 10px 4px; font-size: 14px; }
  .chips, .search-wrap, .intro { padding-left: 10px; padding-right: 10px; margin-left: 0; margin-right: 0; }
  .list { padding: 10px 10px 130px; gap: 6px; }
  .row { grid-template-columns: 56px 1fr auto; gap: 8px 10px; padding: 8px; }
  .thumb { width: 56px; height: 56px; }
  .name { font-size: 14px; }
  .car { min-width: 60px; padding: 4px 6px; }
  .car b { font-size: 17px; }
  .qty { grid-column: 1 / -1; grid-template-columns: 44px 1fr 44px; }
  .foot-actions { width: 100%; }
  .foot-actions .primary { flex: 1; }
}

/* ---- login ---- */
.login { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--bg); }
.login[hidden] { display: none; }
.login form { width: min(360px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 10px; background: var(--card); padding: 24px; border-radius: 18px; box-shadow: var(--shadow); text-align: center; }
.login .logo { margin: 0 auto 4px; width: 48px; height: 48px; font-size: 26px; border-radius: 14px; }
.login h2 { margin: 0; font-size: 20px; }
.login .hint { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.login input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.login button { padding: 12px; font-size: 16px; }
.login .err { color: var(--warn); font-size: 13px; min-height: 1.2em; }
