:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #5f6672;
  --border: #dcdfe5;
  --primary: #1d4ed8;
  --primary-text: #ffffff;
  --primary-soft: #e3eafc;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #a35a00;
  --warn-soft: #fff3df;
  --ok: #1b7f3b;
  --ok-soft: #e4f5e9;
  --tile-border: #f2b705;  /* żółte ramki kafelków — wymóg użytkownika (w nocy szare były niewidoczne) */
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --surface-2: #252932;
    --text: #eceef2;
    --muted: #9aa2b1;
    --border: #323743;
    --primary: #5b8cff;
    --primary-text: #0b1020;
    --primary-soft: #1e2a4a;
    --danger: #ff6b6b;
    --danger-soft: #3a1d1f;
    --warn: #ffb547;
    --warn-soft: #3a2c14;
    --ok: #4cd07d;
    --ok-soft: #173323;
    --tile-border: #ffd23f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* Atrybut hidden zawsze chowa element — także taki z display: grid/flex (np. kafle na czas szukania). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- Układ ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 8px 0;
  background: var(--primary); color: var(--primary-text);
}
.topbar h1 { flex: 1; font-size: 19px; font-weight: 650; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { color: inherit; }
/* Ścieżka w pasku: wcześniejsze człony mniejsze i przygaszone, ostatni (bieżący ekran) — pełny tytuł. */
.topbar h1 .crumb { color: inherit; text-decoration: none; font-size: 15px; font-weight: 500; opacity: .85; }
.topbar h1 .crumb:active { opacity: 1; text-decoration: underline; }
.topbar h1 .crumb-sep { margin: 0 6px; font-size: 15px; font-weight: 400; opacity: .6; }
/* Przyciski w pasku z białą ramką: ⚙ Moje konto i ⏻ Wyloguj (ikony SVG, na każdym ekranie). */
.topbar .text-btn { min-height: 40px; padding: 0 12px; border: 1px solid rgb(255 255 255 / .45); border-radius: 10px; background: transparent; color: inherit; font-size: 15px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.topbar .text-btn.icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; padding: 0; flex: none; }
.topbar .text-btn:active, .topbar .text-btn.on { background: rgb(255 255 255 / .18); }
/* Wąski telefon: trochę ciaśniej, żeby ścieżka („Magazyn / Spis / ATLAS”) się mieściła. */
@media (max-width: 420px) {
  .topbar:has(.text-btn) { gap: 6px; }
  .topbar:has(.text-btn) h1 { padding: 0 4px; }
}
.page { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(110px + env(safe-area-inset-bottom)); }
.section-title { margin: 22px 0 8px; font-size: 14px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

/* ---------- Przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); }
/* „Jeżeli nie ma na liście — zamów …” pod wynikami wyszukiwania — wyraźnie widoczny (uwaga użytkownika). */
.btn.missing { background: var(--warn-soft); border: 2px solid var(--warn); color: var(--text); }
.btn.block { width: 100%; }
.btn.big { min-height: 58px; font-size: 18px; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; font-size: 22px; cursor: pointer;
}
.icon-btn:active { background: rgb(127 127 127 / .2); }

/* ---------- Kafle na ekranie głównym ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile {
  position: relative;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 4px;
  min-height: 96px; padding: 14px;
  border: 1.5px solid var(--tile-border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  text-align: left; cursor: pointer;
}
.tile:active { transform: scale(.98); }
.tile .ico { font-size: 26px; line-height: 1; }
.tile b { font-size: 17px; }
.tile span.sub { font-size: 13px; color: var(--muted); }
.tile.hero { grid-column: span 2; min-height: 110px; background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.tile.hero span.sub { color: inherit; opacity: .85; }
/* Administrator: wszystkie kafle jednakowe; pierwszy rząd po 3 (Pobranie, Zwrot, Przesunięcie), dalej po 2. */
.tiles.admin { grid-template-columns: repeat(6, 1fr); }
/* Wspólne wiersze (subgrid) w każdym rzędzie kafli: ikona, tytuł i opis zaczynają się na tej samej wysokości,
   nawet gdy w jednym kaflu tytuł lub opis ma dwie linie. */
.tiles.admin .tile {
  grid-column: span 3; grid-row: span 3;
  display: grid; grid-template-rows: subgrid; row-gap: 4px; align-content: start;
  grid-template-columns: minmax(0, 1fr); justify-content: stretch; justify-items: start; align-items: start;
}
@supports not (grid-template-rows: subgrid) {
  .tiles.admin .tile { display: flex; justify-content: flex-start; }
}
.tiles.admin .tile.third { grid-column: span 2; padding: 12px 10px; }
.tiles.admin .tile.third b { font-size: 15px; hyphens: manual; -webkit-hyphens: manual; }
.tiles.admin .tile.third span.sub { font-size: 12px; hyphens: manual; -webkit-hyphens: manual; }
.badge {
  position: absolute; top: 10px; right: 10px;
  min-width: 26px; padding: 2px 8px; border-radius: 13px;
  background: var(--danger); color: #fff; font-size: 14px; font-weight: 700; text-align: center;
}

/* ---------- Pola formularzy ---------- */
.field { display: block; }
.field > span { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); font-size: 16px;
}
textarea.input { min-height: 120px; resize: vertical; }
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; }

/* Nagłówek nad wyszukiwarką na ekranie głównym („Czego szukasz?”). */
.search-title { margin: 4px 0 0; font-size: 24px; font-weight: 700; letter-spacing: -.01em; color: var(--text); }
.search-bar { position: sticky; top: 56px; z-index: 5; margin: -16px -16px 0; padding: 12px 16px 8px; background: var(--bg); }
/* Ujemny margines tylko na samej górze strony — pod przyciskiem (np. „Export do Excel”) nie może zachodzić na jego ramkę. */
.search-bar:not(:first-child) { margin-top: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

.seg { display: flex; padding: 3px; border-radius: 12px; background: var(--surface-2); }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); }

/* ---------- Listy ---------- */
.list { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 60px; padding: 10px 14px;
  border: 0; border-bottom: 1px solid var(--border);
  background: transparent; text-align: left;
}
.item:last-child { border-bottom: 0; }
button.item { cursor: pointer; }
button.item:active { background: var(--surface-2); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { font-size: 13px; color: var(--muted); }
.item .qty { flex: none; text-align: right; font-weight: 700; white-space: nowrap; }
.item .qty small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.item.cancelled .title, .item.cancelled .qty { text-decoration: line-through; opacity: .55; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; }
.pill.low { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.info { background: var(--primary-soft); color: var(--primary); }

.card { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.card + .card { margin-top: 12px; }

/* Tabela (ustawienia minimów) */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.table td.num { width: 84px; }
.table td.num .input { min-height: 42px; padding: 6px 8px; text-align: right; }
/* ---------- Arkusz (okno od dołu) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgb(0 0 0 / .45);
  animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0; background: var(--surface);
  animation: up .18s ease-out;
}
.sheet h2 { font-size: 20px; margin-bottom: 4px; padding-right: 40px; }
.sheet .close { position: absolute; }
.sheet-head { position: relative; margin-bottom: 14px; }
.sheet-head .icon-btn { position: absolute; top: -8px; right: -6px; }
@media (min-width: 640px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 20px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }

/* Licznik ilości */
.stepper { display: flex; align-items: stretch; gap: 10px; margin: 8px 0 12px; }
.stepper button {
  width: 68px; min-height: 64px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface-2); font-size: 30px; font-weight: 600; cursor: pointer;
}
.stepper button:active { transform: scale(.96); }
.stepper input {
  flex: 1; min-width: 0; min-height: 64px;
  border: 2px solid var(--primary); border-radius: 14px;
  background: var(--surface); text-align: center; font-size: 30px; font-weight: 700;
}
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.quick button { min-height: 44px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-weight: 600; cursor: pointer; }

/* Ekran logowania */
.login { max-width: 420px; margin: 0 auto; padding: calc(32px + env(safe-area-inset-top)) 16px 32px; }
.login .logo { width: 72px; height: 72px; margin: 0 auto 12px; display: block; }
.login h1 { text-align: center; margin-bottom: 24px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0; min-height: 18px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--text); border-color: var(--text); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button {
  min-height: 64px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); font-size: 26px; font-weight: 600; cursor: pointer;
}
.keypad button:active { background: var(--surface-2); }
.keypad button.fn { font-size: 16px; color: var(--muted); }
.error { margin: 10px 0; padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-weight: 600; }

/* Komunikat */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 100;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: #16181d; color: #fff; font-weight: 600; box-shadow: 0 6px 20px rgb(0 0 0 / .25);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast { width: max-content; }
#toast.has-action { display: flex; align-items: center; gap: 14px; pointer-events: auto; }
#toast button {
  min-height: 40px; padding: 6px 14px; border: 0; border-radius: 9px;
  background: rgb(255 255 255 / .18); color: #fff; font-weight: 700; cursor: pointer;
}

/* Wybór lokalizacji w okienku pobrania */
.loc-pick { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.loc-pick button {
  flex: 1 1 auto; min-height: 52px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); text-align: center; cursor: pointer; line-height: 1.2;
}
.loc-pick button b { display: block; font-size: 15px; }
.loc-pick button small { color: var(--muted); font-size: 12px; }
.loc-pick button.on { border: 2px solid var(--primary); background: var(--primary-soft); }
.loc-pick button.empty { opacity: .6; }
.loc-pick.big button { min-height: 76px; flex-basis: 100%; }
.loc-pick.big button b { font-size: 18px; }
.stock-line { font-size: 13px; color: var(--muted); }
.stock-line b { color: var(--text); font-weight: 600; }
/* Brak towaru / poniżej minimum — na czerwono, łącznie z pogrubioną liczbą. */
.stock-line.neg, .stock-line.neg b, .stock-line .neg, .stock-line .neg b { color: var(--danger); }
#toast.err { background: var(--danger); }

/* Kolejka w telefonie — zapisy czekające na zasięg (pasek na dole, pod okienkami) */
#outbox {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--warn-soft); color: var(--warn); font-weight: 650; border-top: 1px solid var(--border);
}
#outbox[hidden] { display: none; }
#outbox span { flex: 1; }
#outbox button {
  min-height: 40px; padding: 6px 14px; border: 1px solid currentColor; border-radius: 9px;
  background: transparent; color: inherit; font-weight: 700; cursor: pointer;
}

/* Raporty */
.report-head { display: flex; align-items: baseline; gap: 8px; margin: 22px 0 8px; }
.report-head b { flex: 1; font-size: 16px; }
