:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --surface-2: #efebe6;
  --text: #1f2933;
  --muted: #66707a;
  --line: #e1dbd3;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fdeee4;
  --ok: #2f7d4f;
  --ok-soft: #e4f3ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1d8;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181c;
    --surface: #1c2227;
    --surface-2: #252c33;
    --text: #e9ecef;
    --muted: #9aa5b0;
    --line: #2f373f;
    --accent: #f07a3a;
    --accent-ink: #1a0d05;
    --accent-soft: #3a2316;
    --ok: #6cc48f;
    --ok-soft: #1d3326;
    --warn: #f0b85a;
    --warn-soft: #3a2f17;
    --danger: #f2877d;
    --danger-soft: #3d1f1c;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }

/* --- układ --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { font-size: 22px; padding: 4px 10px; margin-left: -10px; background: none; border: 0; color: var(--text); }
.topbar .who { font-size: 13px; color: var(--muted); text-align: right; line-height: 1.2; }

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

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; max-width: 140px; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px;
}
.nav a .ico { font-size: 22px; line-height: 1; }
.nav a.on { color: var(--accent); font-weight: 600; }
.nav a.scan .ico {
  background: var(--accent); color: var(--accent-ink);
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; margin-top: -18px;
  box-shadow: 0 4px 12px rgb(0 0 0 / .18);
}

/* --- elementy --- */
h2 { font-size: 17px; margin: 24px 0 10px; }
h2:first-child { margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 6px; font-size: 16px; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  color: inherit; text-decoration: none; background: none; width: 100%; text-align: left; font: inherit;
}
.row:last-child { border-bottom: 0; }
a.row:active, button.row:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: 13px; color: var(--muted); }
.row .end { text-align: right; font-size: 14px; white-space: nowrap; }
.row.off { opacity: .5; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 14px; min-height: 104px;
  display: flex; flex-direction: column; justify-content: space-between;
  color: inherit; text-decoration: none;
}
.tile .ico { font-size: 28px; }
.tile b { font-size: 16px; }
.tile.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.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.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* --- formularze --- */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 12px 12px; min-height: 48px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 11px 16px; min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--danger); border-color: var(--danger-soft); }
button.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
button:disabled { opacity: .5; cursor: default; }
.block { width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.actions > * { flex: 1; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  min-height: 42px; min-width: 46px; padding: 6px 10px; border-radius: 99px; font-weight: 600;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--muted);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.search { position: sticky; top: 58px; z-index: 4; background: var(--bg); padding: 4px 0 10px; display: flex; gap: 8px; }
.search input { flex: 1; }

/* --- skaner --- */
.scanner {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 4 / 3; margin-bottom: 14px;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame {
  position: absolute; left: 12%; right: 12%; top: 30%; bottom: 30%;
  border: 3px solid rgb(255 255 255 / .85); border-radius: 12px;
}
.scanner .hint { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; color: #fff; font-size: 14px; }
.scanner.small { aspect-ratio: 16 / 9; }

.sugg { display: flex; flex-direction: column; gap: 8px; margin: -4px 0 14px; }
.sugg button { justify-content: space-between; text-align: left; font-weight: 500; }
.sugg button.on { border-color: var(--accent); background: var(--accent-soft); }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.note { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  max-width: calc(100% - 32px); font-weight: 600; box-shadow: 0 6px 20px rgb(0 0 0 / .25);
}
.toast.err { background: var(--danger); color: #fff; }

.login { max-width: 380px; margin: 0 auto; padding: 12vh 16px 32px; }
.login .logo { width: 72px; height: 72px; margin-bottom: 12px; }
.login h1 { margin: 0 0 4px; }

@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
}

.row .end input { width: 110px; text-align: right; }
.picker { margin-bottom: 14px; }
.picker .list { margin-top: 6px; }
