:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1a2230;
  --muted: #6b7686;
  --line: #e3e8ef;
  --brand: #2563eb;
  --brand-ink: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --warn-bg: #fff7ed;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; }
.num { text-align: right; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; }
.userbox { display: flex; align-items: center; gap: 12px; }

/* Cards / layout */
main { max-width: 1080px; margin: 0 auto; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.authwrap { display: flex; justify-content: center; padding-top: 8vh; }
.auth-card { width: 380px; max-width: 92vw; padding: 24px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; }
.row .field { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; color: var(--muted); font-weight: 600; }
input, select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--ink); width: 100%;
}
input:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.check input { width: auto; }

/* Buttons */
.btn {
  padding: 9px 14px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; background: #eef1f6; color: var(--ink);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-in { background: #dcfce7; color: #166534; }
.btn-out { background: #fee2e2; color: #991b1b; }
.btn-adj { background: #e0e7ff; color: #3730a3; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.auth-card .tabs { margin-bottom: 20px; }
.tab {
  padding: 9px 14px; background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px;
}
.tab.active { color: var(--brand-ink); border-bottom-color: var(--brand); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-num { display: block; font-size: 26px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-warn .stat-num { color: var(--warn); }

/* Toolbar */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }

/* Table */
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.grid th.num { text-align: right; }
.grid td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: none; }
.grid tr.archived { opacity: 0.5; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }

/* Stock badge */
.qty { font-weight: 700; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-low { background: var(--warn-bg); color: var(--warn); }
.badge-zero { background: #fee2e2; color: #991b1b; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.tag-in { background: #dcfce7; color: #166534; }
.tag-out { background: #fee2e2; color: #991b1b; }
.tag-adjust { background: #e0e7ff; color: #3730a3; }
.delta-pos { color: var(--ok); font-weight: 700; }
.delta-neg { color: var(--danger); font-weight: 700; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty { padding: 28px; text-align: center; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.error { color: var(--danger); font-size: 13px; margin: 0; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal { width: 460px; max-width: 96vw; padding: 22px; }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* Toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; z-index: 40; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }

@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .grid th:nth-child(3), .grid td:nth-child(3) { display: none; }
}

/* ====================================================================== */
/* Police, sken a akční panel                                              */
/* ====================================================================== */

/* Plovoucí tlačítko skenu. Dole vpravo = dosah palce jednou rukou; skladník
   drží zboží v druhé ruce a k hornímu okraji obrazovky nedosáhne. */
.scan-fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 40;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 0 22px;
  font: inherit; font-weight: 700; font-size: 1rem;
  color: #fff; background: #0d6a88; border: 0; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28); cursor: pointer;
}
.scan-fab:active { transform: translateY(1px); }
.scan-fab-ico { font-size: 1.3rem; line-height: 1; }

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: #0f1213; color: #e9ebe7;
  display: flex; flex-direction: column;
}
.overlay.hidden { display: none; }

/* ---- sken ---- */
.scan-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 14px; font-size: .95rem;
}
.scan-stage { position: relative; flex: 1 1 auto; overflow: hidden; background: #000; }
.scan-stage video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(68vw, 300px); aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, .9); border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}
/* Bliknutí po načtení kódu — na iOS není vibrace, takže vizuál je povinný. */
.scan-flash { position: absolute; inset: 0; background: #fff; opacity: .85; }
.scan-manual { padding: 14px; display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.scan-manual .field { flex: 1 1 180px; margin: 0; }
.scan-manual .field span { color: #a2aaac; }
.scan-manual input { text-transform: uppercase; }

/* ---- police ---- */
.bin-overlay { background: #f3f4f0; color: #14171a; }
.bin-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 16px 16px 12px; border-bottom: 1px solid #d6d9d2;
  background: #fff;
}
.bin-title { font-size: 2rem; font-weight: 800; line-height: 1.05; letter-spacing: -.02em; }
.bin-sub { font-size: .85rem; }
.bin-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 14px 96px; }

.bin-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bin-item { background: #fff; border: 1px solid #d6d9d2; border-radius: 12px; padding: 14px; }
.bin-item-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.bin-item-name { font-weight: 700; font-size: 1.05rem; }
.bin-item-sku { font-size: .8rem; }
.bin-item-qty { text-align: right; white-space: nowrap; }
.bin-item-qty b { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bin-item-qty span { font-size: .9rem; margin-left: 4px; color: #545c60; }

/* Tlačítka 56 px vysoká — menší se v rukavici netrefí. */
.bin-actions { display: flex; gap: 8px; margin-top: 12px; }
.bin-actions .btn { flex: 1 1 0; min-height: 56px; font-size: 1rem; font-weight: 700; }
.btn-out { background: #a32e1a; color: #fff; border-color: #a32e1a; }
.btn-in { background: #1f6b4f; color: #fff; border-color: #1f6b4f; }
.btn-xl { min-height: 56px; font-size: 1.05rem; }
.btn-wide { width: 100%; margin-top: 14px; }

.bin-empty { text-align: center; padding: 32px 12px; }
.bin-empty .big { font-size: 1.1rem; margin-bottom: 18px; }
.bin-err { color: #a32e1a; font-weight: 600; }

/* ---- akční panel ---- */
.sheet-overlay { background: rgba(15, 18, 19, .55); justify-content: flex-end; }
.sheet {
  background: #fff; color: #14171a;
  border-radius: 16px 16px 0 0; padding: 16px 16px 28px;
  max-height: 88vh; overflow-y: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 1.15rem; }
.sheet-item { margin: 0 0 12px; font-weight: 600; }
.sheet input { min-height: 52px; font-size: 1.15rem; }

.add-results { display: grid; gap: 8px; margin-top: 8px; }
.add-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  width: 100%; text-align: left; font: inherit; cursor: pointer;
  background: #f3f4f0; border: 1px solid #d6d9d2; border-radius: 10px;
  padding: 12px 14px; min-height: 56px;
}
.add-plus { font-size: 1.5rem; font-weight: 700; color: #0d6a88; }

/* ---- správa polic ---- */
.genrow { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.genrow .field { flex: 1 1 160px; margin: 0; }
.genrow .btn { min-height: 44px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bins-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.bin-card {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px; border: 1px solid #d6d9d2; border-radius: 10px;
  background: #fff; text-decoration: none; color: inherit; min-height: 64px;
}
.bin-card-code { font-weight: 800; font-size: 1.15rem; letter-spacing: -.01em; }
.bin-card-meta { font-size: .75rem; }

@media (max-width: 560px) {
  .bin-actions { flex-wrap: wrap; }
  .bin-actions .btn { flex: 1 1 45%; }
}

/* ====================================================================== */
/* Média                                                                   */
/* ====================================================================== */

.media-overlay { background: #f3f4f0; color: #14171a; }
.bin-title.sm { font-size: 1.3rem; }
.media-actions { display: flex; gap: 10px; padding: 12px 14px; }
.media-actions .btn { flex: 1 1 0; }
.media-grid {
  flex: 1 1 auto; overflow-y: auto; padding: 0 14px 32px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
  align-content: start;
}
.media-tile { position: relative; margin: 0; background: #000; border-radius: 10px; overflow: hidden; }
.media-tile img, .media-tile video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.media-tile video { object-fit: contain; background: #000; }
.media-badge {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(0, 0, 0, .68); color: #fff; font-size: 11px;
  padding: 2px 7px; border-radius: 999px;
}
.media-del {
  position: absolute; right: 6px; top: 6px; width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff;
  font-size: 20px; line-height: 1; cursor: pointer;
}

.cap-overlay { background: #000; }
.cap-bar { padding: 18px 14px calc(18px + env(safe-area-inset-bottom)); display: flex; justify-content: center; }
.cap-shoot {
  min-width: 190px; min-height: 62px; border-radius: 999px;
  font: inherit; font-size: 1.05rem; font-weight: 700;
  background: #fff; color: #14171a; border: 0; cursor: pointer;
}
.cap-shoot.recording { background: #a32e1a; color: #fff; }

/* Nabídka doložit pohyb — sedí nad obsahem, ne v toku, aby neposkakoval layout. */
.move-media-bar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: #14171a; color: #fff; font-size: .92rem;
}
.move-media-bar .btn { background: #fff; border-color: #fff; color: #14171a; }

/* ====================================================================== */
/* Mobile first — appka se používá na telefonu u regálu, ne u stolu        */
/* ====================================================================== */

/* iOS zoomne stránku u každého inputu pod 16 px. Zoom pak zůstane a rozbije
   layout, takže 16 px je minimum, ne estetická volba. */
input, select, textarea, button { font-size: 16px; }

body { padding-bottom: env(safe-area-inset-bottom); }

.topbar { position: sticky; top: 0; z-index: 20; padding: 10px 14px; gap: 10px; }
.userbox { gap: 8px; }
.userbox .muted { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Záložky se na úzkém displeji nevejdou → vodorovný scroll místo zalomení,
   které by rozhodilo výšku hlavičky. */
.main-tabs {
  display: flex; overflow-x: auto; gap: 2px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.main-tabs::-webkit-scrollbar { display: none; }
.main-tabs .tab { flex: 0 0 auto; min-height: 44px; padding: 10px 14px; }

.btn { min-height: 44px; }
.btn-sm { min-height: 36px; }

@media (max-width: 720px) {
  main { padding: 12px !important; }
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
  .stat { padding: 10px; }
  .stat-num { font-size: 20px; }
  .stat-label { font-size: 10px; }

  .toolbar { gap: 8px; }
  .toolbar .field, .toolbar input[type="search"], .toolbar input[type="text"] { flex: 1 1 100%; }

  /* Tabulka se na telefonu překlopí do karet. Vodorovný scroll u tabulky
     s pěti sloupci je na mobilu nepoužitelný — data zmizí za okrajem. */
  .tablewrap { border: 0; background: transparent; box-shadow: none; }
  .grid, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid thead { display: none; }
  .grid tr {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); margin-bottom: 10px; padding: 12px;
  }
  .grid td { border: 0; padding: 3px 0; text-align: left; }
  .grid td.num { text-align: left; }
  /* Popisek sloupce se bere z data-label, které dopisuje app.js. */
  .grid td[data-label]::before {
    content: attr(data-label) " ";
    display: inline-block; min-width: 92px;
    color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  }
  .grid td .btn { min-height: 40px; }

  .modal { width: 100%; max-width: 100%; border-radius: 14px 14px 0 0; }
  .genrow { flex-direction: column; align-items: stretch; }
  .genrow .btn { width: 100%; }
  .card-head { flex-direction: column; align-items: stretch; gap: 8px; }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

  /* Plovoucí sken nesmí zakrýt poslední řádek seznamu. */
  #view-stock, #view-movements, #view-audit, #view-bins { padding-bottom: 84px; }
}

@media (max-width: 380px) {
  .bin-title { font-size: 1.7rem; }
  .scan-fab { padding: 0 16px; }
  .scan-fab span:not(.scan-fab-ico) { display: none; }
}

/* Tisk štítků: akce musí být vidět na první pohled, ne schovaná v rohu karty. */
.print-bar { margin: 12px 0 16px; }
.print-bar .hint { margin-top: 8px; }
.bin-card { align-items: center; text-align: center; }
.bin-card-qr {
  width: 100%; max-width: 74px; aspect-ratio: 1; margin: 0 auto 6px;
  image-rendering: pixelated; /* QR nesmí prohlížeč rozmazat interpolací */
}

/* Otevřeno ze štítku: uživatel není přihlášený, takže pod overlayem svítí
   přihlašovací formulář. Schováme ho, ať neprobleskuje při zavření. */
body.label-mode #authView,
body.label-mode .topbar,
body.label-mode .scan-fab { display: none !important; }
.media-badge.warn { background: rgba(163, 46, 26, .88); }
