:root {
  --fir: #1f4d3a;
  --fir-deep: #163a2b;
  --fir-tint: #e3eee8;
  --snow: #f3f6f5;
  --paper: #ffffff;
  --ink: #17211d;
  --ink-soft: #52605a;
  --line: #d3dcd8;
  --berry: #b3261e;
  --berry-tint: #f8e3e1;
  --gold: #c8962e;
  --gold-tint: #faf0d9;
  --focus: #2f6fd6;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Bahnschrift", "DIN Alternate", "Roboto Condensed", "Segoe UI", system-ui, sans-serif;
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: 2.4rem;
  --step-4: 3.6rem;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--snow);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
h1, h2 { line-height: 1.15; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: var(--step-2); }
h2 { font-size: var(--step-1); }
p { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-soft); }
.block { display: block; }
.strong { font-weight: 600; }
.code, td.code { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.error { color: var(--berry); }
.error:empty { display: none; }
.warn { color: #7a5a12; background: var(--gold-tint); padding: 0.5rem 0.75rem; border-radius: var(--radius-s); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- ovládací prvky ---------- */
button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 44px; padding: 0.5rem 1rem; border-radius: var(--radius-s);
  border: 1px solid transparent; cursor: pointer; text-decoration: none; font-weight: 600;
}
button:disabled { opacity: 0.55; cursor: progress; }
.primary { background: var(--fir); color: #fff; }
.primary:hover { background: var(--fir-deep); }
.secondary { background: var(--paper); border-color: var(--line); color: var(--fir); }
.secondary:hover { border-color: var(--fir); }
.danger { background: var(--berry); color: #fff; }
.link { background: none; border: 0; padding: 0.25rem 0.4rem; min-height: auto; color: var(--fir); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.danger-link { color: var(--berry); }
.wide { width: 100%; }
.icon { background: none; border: 0; font-size: 1.6rem; min-height: 40px; min-width: 40px; padding: 0; color: var(--ink-soft); }
input, select, textarea {
  min-height: 44px; padding: 0.5rem 0.65rem; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius-s); width: 100%;
}
input:focus, select:focus { border-color: var(--fir); }
input[type="checkbox"], input[type="radio"] { width: 1.15rem; height: 1.15rem; min-height: 0; accent-color: var(--fir); }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field .label { font-size: var(--step--1); color: var(--ink-soft); }
.field .hint { font-size: var(--step--1); color: var(--ink-soft); }
.checkbox, .radio { display: flex; align-items: center; gap: 0.5rem; }
.inline { display: flex; align-items: center; gap: 0.5rem; color: var(--ink-soft); }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: flex-end; align-items: center; }
.inline-form { display: flex; gap: 0.5rem; align-items: flex-end; }
.inline-form.wrap { flex-wrap: wrap; }
.inline-form > input, .inline-form > select, .inline-form > .field { flex: 1 1 10rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: var(--paper); }
.segmented button { border-radius: 0; min-height: 40px; background: none; color: var(--ink-soft); font-weight: 500; }
.segmented button[aria-pressed="true"] { background: var(--fir); color: #fff; }
.tag { display: inline-block; margin-left: 0.5rem; padding: 0 0.4rem; border-radius: var(--radius-s); background: var(--gold-tint); color: #7a5a12; font-size: var(--step--1); }
.tag-ok { background: var(--fir-tint); color: var(--fir); }

/* ---------- rozvržení ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  padding: 0.5rem 1rem; padding-top: max(0.5rem, env(safe-area-inset-top));
  background: var(--fir); color: #fff;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: var(--step-1); letter-spacing: 0.01em; }
.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.tabs a { color: #d6e6dd; text-decoration: none; padding: 0.55rem 0.75rem; border-radius: var(--radius-s); font-weight: 500; }
.tabs a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.tabs a.active { color: var(--fir); background: #fff; }
.session { margin-left: auto; display: flex; gap: 0.75rem; align-items: center; font-size: var(--step--1); }
.session .link { color: #d6e6dd; }
.collection-name { color: #fff; font-weight: 600; }
main { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 4rem; outline: none; }
.page-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; }
.filters { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.filters input[type="search"] { flex: 2 1 16rem; }
.filters select { flex: 1 1 12rem; width: auto; }
.section-title { margin-top: 0.5rem; font-size: var(--step-0); color: var(--ink-soft); font-weight: 600; }
.empty, .empty-note { color: var(--ink-soft); padding: 1.5rem 0; }

/* ---------- přihlášení ---------- */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login { width: min(100%, 22rem); }
.login-title { font-size: var(--step-4); color: var(--fir); font-weight: 700; letter-spacing: -0.02em; }

/* ---------- příjem (PC) ---------- */
.scan-page { display: flex; flex-direction: column; gap: 1rem; }
.scan-controls { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: center; }
.mode-switch { display: inline-flex; border-radius: var(--radius-m); overflow: hidden; border: 2px solid var(--line); }
.mode { border-radius: 0; min-height: 52px; padding: 0 1.6rem; font-size: var(--step-1); background: var(--paper); color: var(--ink-soft); }
.mode-add[aria-pressed="true"] { background: var(--fir); color: #fff; }
.mode-remove[aria-pressed="true"] { background: var(--berry); color: #fff; }
.qty { width: 5.5rem; text-align: center; font-size: var(--step-1); }
.station { width: 9rem; }
.scan-input {
  min-height: 72px; font-size: var(--step-2); padding: 0.5rem 1rem; letter-spacing: 0.04em;
  border: 3px solid var(--fir); border-radius: var(--radius-m);
}
.scan-page[data-mode="remove"] .scan-input { border-color: var(--berry); }

/* výsledková tabule – jediný výrazný prvek aplikace */
.board {
  display: grid; grid-template-columns: auto 1fr; gap: 1.5rem; align-items: center;
  min-height: 11rem; padding: 1.5rem 2rem; border-radius: var(--radius-m);
  background: var(--paper); border: 1px solid var(--line);
}
.board-count { font-size: clamp(3.5rem, 9vw, 7rem); font-weight: 700; line-height: 1; min-width: 2ch; text-align: center; }
.board-title { font-size: clamp(1.5rem, 3.2vw, 2.6rem); font-weight: 600; line-height: 1.15; }
.board-detail { margin-top: 0.4rem; font-size: var(--step-1); color: var(--ink-soft); }
.board.idle { grid-template-columns: 1fr; border-style: dashed; }
.board.idle .board-title { color: var(--ink-soft); font-size: var(--step-2); }
.board.added { background: var(--fir); border-color: var(--fir); color: #fff; }
.board.added .board-detail { color: #cfe3d8; }
.board.removed, .board.error { background: var(--berry); border-color: var(--berry); color: #fff; }
.board.removed .board-detail, .board.error .board-detail { color: #f6d3cf; }
.board.error, .board.unknown { grid-template-columns: 1fr; }
.board.unknown { background: var(--gold-tint); border-color: var(--gold); }
.board.flash { animation: flash 420ms ease-out; }
@keyframes flash { from { transform: scale(1.015); filter: brightness(1.25); } to { transform: none; filter: none; } }
.scan-totals { font-size: var(--step-1); color: var(--ink-soft); }
.recent { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-m); }
.recent li { display: grid; grid-template-columns: 4.5rem 1fr auto; gap: 0.75rem; align-items: center; padding: 0.5rem 1rem; border-top: 1px solid var(--line); }
.recent li:first-child { border-top: 0; }
.recent li.undone { opacity: 0.5; text-decoration: line-through; }
.recent small { color: var(--ink-soft); }
.delta { font-weight: 700; font-size: var(--step-1); }
.pos, .delta.pos { color: var(--fir); }
.neg, .delta.neg { color: var(--berry); }

/* ---------- tabulky ---------- */
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-m); }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 0.55rem 0.75rem; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
table.data thead th { border-top: 0; font-size: var(--step--1); color: var(--ink-soft); font-weight: 600; background: var(--snow); position: sticky; top: 0; }
table.data.compact td { padding: 0.35rem 0.6rem; font-size: var(--step--1); }
table.data .num { text-align: right; white-space: nowrap; }
table.data tr.group th { background: var(--fir-tint); color: var(--fir); font-weight: 600; }
table.data tr.retired { color: var(--ink-soft); }
table.data tr.undone { opacity: 0.5; }
table.data tr.more .diff { color: var(--fir); font-weight: 700; }
table.data tr.less .diff { color: var(--berry); font-weight: 700; }
table.data tr.less { background: var(--berry-tint); }
table.data tr.pending td:nth-child(3) { color: var(--gold); }
.row-actions { white-space: nowrap; text-align: right; }
.row-link { padding: 0; text-align: left; }

/* ---------- přehled ---------- */
.totals { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 1px; margin: 0; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.total { background: var(--paper); padding: 1rem 1.25rem; }
.total dt { font-size: var(--step--1); color: var(--ink-soft); }
.total dd { margin: 0.2rem 0 0; font-size: var(--step-2); font-weight: 600; }
.total-main { background: var(--fir); color: #fff; }
.total-main dt { color: #cfe3d8; }
.total-main dd { font-size: var(--step-3); }
.totals .warn { grid-column: 1 / -1; border-radius: 0; }
details summary { cursor: pointer; font-weight: 600; color: var(--fir); padding: 0.5rem 0; }

/* ---------- inventura (mobil) ---------- */
.inv-start { max-width: 34rem; }
.inv-page { max-width: 46rem; }
.camera-box { position: relative; border-radius: var(--radius-m); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.camera { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-frame { position: absolute; inset: 30% 12%; border: 3px solid rgba(255, 255, 255, 0.85); border-radius: var(--radius-m); box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.25); }
.camera-frame-square { inset: 15% 20%; }
.small { font-size: var(--step--1); }
.count-card { background: var(--paper); border: 2px solid var(--fir); border-radius: var(--radius-m); padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.count-name { font-size: var(--step-1); font-weight: 600; }
.count-row { display: grid; grid-template-columns: 4.5rem 1fr 4.5rem; align-items: center; gap: 0.75rem; }
.step { min-height: 4.5rem; font-size: 2.2rem; background: var(--fir-tint); color: var(--fir); border-radius: var(--radius-m); }
.count-value { text-align: center; display: flex; flex-direction: column; }
.count-value .big { font-size: var(--step-4); font-weight: 700; line-height: 1; }
.count-set { display: flex; gap: 0.5rem; }
.count-input { font-size: var(--step-1); text-align: center; }
.inv-progress { font-weight: 600; }
.past ul { margin: 0.5rem 0 0; padding-left: 1.25rem; }

/* ---------- katalog ---------- */
.pick-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.pick { width: 100%; display: grid; grid-template-columns: 5.5rem 1fr auto; gap: 0.75rem; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); border-radius: 0; font-weight: 400; }
.pick:hover, .pick:focus-visible { background: var(--fir-tint); }
.pick .price { color: var(--ink-soft); }
.preview-list { max-height: 40vh; overflow-y: auto; margin: 0; padding-left: 1.25rem; font-size: var(--step--1); }
.warn-box { background: var(--gold-tint); padding: 0 0.75rem; border-radius: var(--radius-s); }
.warn-box ul { margin: 0 0 0.75rem; padding-left: 1.25rem; font-size: var(--step--1); }
.admin section { padding-top: 1rem; border-top: 1px solid var(--line); }
.admin ul { margin: 0; padding-left: 1.25rem; }

/* ---------- dialogy a hlášky ---------- */
.modal { border: 0; border-radius: var(--radius-m); padding: 0; width: min(40rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); color: var(--ink); }
.modal::backdrop { background: rgba(23, 33, 29, 0.45); }
.modal > header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem 0.75rem 1.25rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--paper); }
.modal > header + * { padding: 1.25rem; }
.toasts { position: fixed; right: 1rem; bottom: max(1rem, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 0.5rem; z-index: 100; max-width: min(28rem, calc(100vw - 2rem)); }
.toast { padding: 0.75rem 1rem; border-radius: var(--radius-s); background: var(--ink); color: #fff; }
.toast-ok { background: var(--fir); }
.toast-error { background: var(--berry); }

/* ---------- přihlášení kartičkou a QR ---------- */
.badge-input { min-height: 56px; font-size: var(--step-1); letter-spacing: 0.2em; border: 2px solid var(--fir); }
.pass-login summary { color: var(--ink-soft); font-weight: 500; }
.pass-login form { margin-top: 0.75rem; }
.hint-box { background: var(--fir-tint); color: var(--fir); padding: 0.75rem 1rem; border-radius: var(--radius-s); }
.center { align-items: center; text-align: center; }
.qr-holder { width: min(18rem, 70vw); aspect-ratio: 1; display: grid; place-items: center; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-m); padding: 0.75rem; }
.qr-holder .qr { width: 100%; height: 100%; image-rendering: pixelated; }
.qr-holder.expired .qr { opacity: 0.15; }

/* kartička obsluhy – rozměr platební karty */
.badge-card {
  width: 85.6mm; height: 54mm; padding: 4mm 5mm; box-sizing: border-box;
  display: flex; flex-direction: column; justify-content: space-between;
  background: #fff; color: #000; border: 1px solid var(--line); border-radius: 3mm;
  font-family: var(--font);
}
.badge-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1.2mm solid var(--fir); padding-bottom: 1mm; }
.badge-brand { font-weight: 700; color: var(--fir); font-size: 11pt; }
.badge-user { font-weight: 700; font-size: 14pt; }
.badge-barcode { width: 100%; height: 19mm; object-fit: fill; image-rendering: pixelated; }
.badge-foot { display: flex; justify-content: space-between; font-size: 8pt; }
.badge-note { font-size: 6.5pt; color: #444; margin: 0; }
.badge-card-admin .badge-head { border-bottom-color: var(--berry); }
.badge-card-admin .badge-brand { color: var(--berry); }
.tag-admin { background: var(--berry-tint); color: var(--berry); }
.dev-state { font-size: var(--step-1); font-weight: 700; }
.dev-state.on { color: var(--berry); }
.dev-state.off { color: var(--fir); }
.dev-banner { margin: 0; padding: 0.4rem 1rem; background: var(--berry); color: #fff; font-weight: 600; text-align: center; }

/* ---------- mobil ---------- */
@media (max-width: 720px) {
  .topbar { gap: 0.5rem; padding: 0.4rem 0.75rem; }
  .brand { font-size: var(--step-0); }
  .tabs { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .tabs a { white-space: nowrap; padding: 0.5rem 0.6rem; }
  .collection-name { display: none; }
  main { padding: 1rem 1rem 5rem; }
  .totals { grid-template-columns: 1fr 1fr; }
  .total-main { grid-column: 1 / -1; }
  .board { grid-template-columns: 1fr; padding: 1rem; text-align: left; }
  .grid-2 { grid-template-columns: 1fr; }
  .inline-form { flex-wrap: wrap; }
  .recent li { grid-template-columns: 3.5rem 1fr auto; padding: 0.5rem 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .board.flash { animation: none; }
}

@media print {
  body.printing-node > *:not(#print-area) { display: none !important; }
  body.printing-node #print-area { display: block; }
  body.printing-node .badge-card { border-color: #999; break-inside: avoid; }
  .topbar, .no-print, .toasts, .history { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .table-wrap { border: 0; overflow: visible; }
  table.data thead th { position: static; }
  .total-main { background: #fff; color: var(--ink); border: 2px solid var(--ink); }
  .total-main dt { color: var(--ink-soft); }
}
