:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #e9edf4;
  --text: #0e1a2b;
  --muted: #5a6577;
  --line: #d3d9e3;
  --brand: #00205b;
  --brand-2: #0077c8;
  --accent: #00a3e0;
  --ok: #157f3d;
  --ok-bg: #e2f4e8;
  --warn: #9a5b00;
  --warn-bg: #fff1d6;
  --err: #b42318;
  --err-bg: #fde7e5;
  --info-bg: #e4f1fb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 20, 40, .08), 0 4px 14px rgba(10, 20, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b111b;
    --surface: #141c29;
    --surface-2: #1d2737;
    --text: #e8edf5;
    --muted: #9aa6b8;
    --line: #2a3546;
    --brand: #7fb3ff;
    --brand-2: #4aa8ff;
    --accent: #38c3f5;
    --ok: #4ccf7c;
    --ok-bg: #12301f;
    --warn: #f3b443;
    --warn-bg: #36280c;
    --err: #ff7b6e;
    --err-bg: #3b1714;
    --info-bg: #102538;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--brand); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #0d1830; } }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 650; letter-spacing: .2px; }
.topbar a { color: #fff; text-decoration: none; }
.topbar .back { font-size: 22px; padding: 2px 8px 2px 0; }
.net { display: flex; gap: 6px; align-items: center; font-size: 13px; opacity: .95; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #9aa6b8; display: inline-block; }
.dot.ok { background: #3ddc84; } .dot.down { background: #ff6b5e; } .dot.checking { background: #ffc94d; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 90px); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card h2 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 10px; text-decoration: none; color: inherit; display: block; }
.stat b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat.attn b { color: var(--brand-2); }

.bigbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.big {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 112px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 17px; font-weight: 650; text-align: center; padding: 12px; text-decoration: none;
}
.big svg { width: 34px; height: 34px; }
.big.primary { background: var(--brand-2); color: #fff; border-color: transparent; }
.big:active { transform: scale(.98); }
.big[disabled] { opacity: .5; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--brand-2); border-color: transparent; color: #fff; }
.btn.ok { background: var(--ok); border-color: transparent; color: #fff; }
.btn.danger { color: var(--err); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }

.progress { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 8px 0; }
.progress > i { display: block; height: 100%; background: var(--brand-2); transition: width .3s; }

.banner { border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.err { background: var(--err-bg); color: var(--err); }
.banner.info { background: var(--info-bg); }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.pending_ocr, .badge.ocr_running { background: var(--info-bg); color: var(--brand-2); }
.badge.pending_review { background: var(--warn-bg); color: var(--warn); }
.badge.confirmed, .badge.pending_upload, .badge.uploading { background: var(--info-bg); color: var(--brand-2); }
.badge.uploaded { background: var(--ok-bg); color: var(--ok); }
.badge.upload_error { background: var(--err-bg); color: var(--err); }

/* Galerie */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 13px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--brand-2); border-color: transparent; color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; }
.tile .img { aspect-ratio: 4 / 3; background: var(--surface-2) center / cover no-repeat; }
.tile .meta { padding: 7px 9px 9px; }
.tile .num { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 14px; min-height: 20px; }
.tile .num.invalid { color: var(--err); }
.tile .sel { position: absolute; top: 6px; left: 6px; width: 30px; height: 30px; border-radius: 50%; background: rgba(0, 0, 0, .45); border: 2px solid #fff; display: none; }
.selecting .tile .sel { display: block; }
.tile.selected { outline: 3px solid var(--brand-2); outline-offset: -3px; }
.tile.selected .sel { background: var(--brand-2); }
.tile.selected .sel::after { content: "✓"; color: #fff; position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  display: flex; gap: 8px; overflow-x: auto;
}
.actionbar .btn { flex: none; }

/* Detail */
.photo-wrap { position: relative; border-radius: 12px; overflow: hidden; background: #000; touch-action: none; user-select: none; }
.photo-wrap img { display: block; width: 100%; max-height: 62vh; object-fit: contain; }
.photo-wrap .cropbox { position: absolute; border: 2px solid var(--accent); background: rgba(0, 163, 224, .15); pointer-events: none; }
.photo-wrap.cropping { cursor: crosshair; outline: 3px dashed var(--accent); }
.numinput {
  width: 100%; font-size: 28px; font-weight: 700; letter-spacing: 1px; text-align: center;
  font-variant-numeric: tabular-nums; padding: 10px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--surface);
}
.numinput.valid { border-color: var(--ok); }
.numinput.invalid { border-color: var(--err); }
.check { font-size: 14px; margin: 6px 0 2px; text-align: center; }
.check.valid { color: var(--ok); } .check.invalid { color: var(--err); }
.cands { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cand { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-variant-numeric: tabular-nums; }
.cand.valid { border-color: var(--ok); }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
pre { white-space: pre-wrap; font-size: 13px; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 200px; overflow: auto; }
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=url], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); min-height: 46px;
}
.switch { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch:last-child { border-bottom: 0; }
.switch input { width: 22px; height: 22px; margin-top: 2px; flex: none; accent-color: var(--brand-2); }
.switch small { display: block; color: var(--muted); }

/* Hromadné focení */
.camera { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; }
.camera video { flex: 1; width: 100%; min-height: 0; object-fit: cover; background: #000; }
.camera .hud { position: absolute; top: 0; left: 0; right: 0; padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; display: flex; gap: 10px; align-items: center; background: linear-gradient(rgba(0,0,0,.65), transparent); }
.camera .hud .grow { font-size: 14px; }
.camera .hud b { font-size: 20px; }
.camera .controls { display: flex; align-items: center; justify-content: space-around; padding: 18px 16px calc(env(safe-area-inset-bottom) + 22px); background: #000; }
.shutter { width: 84px; height: 84px; border-radius: 50%; border: 5px solid #fff; background: #fff; box-shadow: inset 0 0 0 4px #000; cursor: pointer; }
.shutter:active { transform: scale(.92); background: #ddd; }
.camera .last { width: 60px; height: 60px; border-radius: 10px; background: #222 center / cover; border: 2px solid #fff; }
.camera .cbtn { min-width: 70px; min-height: 48px; color: #fff; background: rgba(255,255,255,.15); border: 0; border-radius: 12px; font-weight: 600; padding: 8px 12px; }
.camera .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.camera .flash.go { animation: flash .25s ease-out; }
@keyframes flash { from { opacity: .7; } to { opacity: 0; } }
.camera .guide { position: absolute; left: 8%; right: 8%; top: 42%; height: 16%; border: 2px dashed rgba(255,255,255,.55); border-radius: 10px; pointer-events: none; }
.camera .err { padding: 24px; text-align: center; margin: auto; }

/* Toast + dialog */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 80px); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: #1c2533; color: #fff; padding: 10px 16px; border-radius: 12px; max-width: 92vw; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.3); pointer-events: auto; display: flex; gap: 12px; align-items: center; }
.toast.err { background: #8f1d14; }
.toast button { background: none; border: 0; color: #7fd0ff; font-weight: 700; cursor: pointer; }
dialog { border: 0; border-radius: 16px; padding: 0; max-width: 560px; width: calc(100% - 24px); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog .dbody { padding: 18px; max-height: 70vh; overflow: auto; }
dialog .dfoot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px 18px; flex-wrap: wrap; }
.confirm-list { display: grid; gap: 8px; margin: 10px 0; }
.confirm-list .it { display: flex; gap: 10px; align-items: center; }
.confirm-list img { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.confirm-list b { font-variant-numeric: tabular-nums; font-size: 17px; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
