:root {
  --bg: #f6f4f3;
  --surface: #ffffff;
  --ink: #221e1f;
  --muted: #6b6466;
  --line: #e3dcd9;
  --accent: #a3282f;
  --accent-hover: #861f25;
  --accent-soft: #f8e7e8;
  --ok: #1d7a4a;
  --danger: #b42318;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }

input, select {
  font: inherit; color: var(--ink); width: 100%;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  min-height: 44px; /* wygodny cel dotykowy */
}
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid1 { display: grid; gap: 14px; }
.grid2 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn {
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  min-height: 44px; padding: 10px 20px; border-radius: 999px;
  border: 1.5px solid var(--accent); background: var(--accent); color: #fff;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--ghost { background: transparent; color: var(--accent); }
.btn--ghost:hover { background: var(--accent-soft); }
.btn--sm { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.btn--block { width: 100%; }
.btn--ok { background: var(--ok); border-color: var(--ok); }
.btn--ok:hover { background: #166238; border-color: #166238; }

/* LOGOWANIE */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login__card { width: min(380px, 100%); }
.login__card h1 { margin: 0; font-size: 1.6rem; }

/* PASEK GÓRNY */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--ink); color: #fff;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.top .btn--ghost { color: #fff; border-color: rgba(255,255,255,.5); }

/* STATYSTYKI */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 12px 16px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat strong { display: block; font-size: 1.35rem; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat--warn strong { color: var(--danger); }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, 1fr); } }

/* ZAKŁADKI */
.tabs { display: flex; gap: 4px; padding: 12px 16px 0; border-bottom: 1px solid var(--line); background: var(--surface); }
.tab {
  font: inherit; background: none; border: 0; padding: 12px 14px; cursor: pointer;
  color: var(--muted); border-bottom: 3px solid transparent; min-height: 44px;
}
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.pane { padding: 14px 16px 120px; max-width: 900px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input { flex: 1; }

.chips { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 14px; min-height: 36px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
.chip.is-on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* LISTA PRODUKTÓW */
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; cursor: pointer; text-align: left; font: inherit; color: inherit; width: 100%;
}
.item:hover { border-color: var(--accent); }
.item__img { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--accent-soft); }
.item__name { font-weight: 600; }
.item__meta { font-size: 13px; color: var(--muted); }
.item__qty { font-weight: 700; font-size: 1.15rem; text-align: right; white-space: nowrap; }
.item__qty.is-low { color: var(--danger); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #fde8e6; color: var(--danger); margin-left: 6px; vertical-align: middle; }

.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 8; font: inherit; font-weight: 600; min-height: 48px; padding: 12px 20px;
  border-radius: 999px; border: 0; background: var(--accent); color: #fff; box-shadow: 0 10px 24px -8px rgba(0,0,0,.4); cursor: pointer;
}

/* SPRZEDAŻ */
#sellBox { margin-bottom: 14px; display: grid; gap: 12px; }
.sell-head { display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: center; }
.sell-head img { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; background: var(--accent-soft); }
.big { font-size: 1.4rem; font-weight: 700; }
.price { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.qtyBox { display: flex; align-items: center; gap: 10px; }
.qtyBox button { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: #fff; font-size: 1.6rem; cursor: pointer; }
.qtyBox input { text-align: center; font-size: 1.4rem; font-weight: 700; max-width: 110px; }

/* SKANER */
.scanner {
  position: fixed; inset: 0; z-index: 40; background: #000; color: #fff;
  display: grid; grid-template-rows: 1fr auto auto auto; gap: 12px; padding: 16px;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; background: #111; }
.scanner__hint { text-align: center; margin: 0; color: rgba(255,255,255,.85); }
.scanner__row { display: flex; gap: 8px; }
.scanner__row input { background: #fff; }
.scanner__close { color: #fff; border-color: rgba(255,255,255,.6); justify-self: center; }

/* OKNA (karta produktu, formularz) */
dialog.sheet {
  border: 0; padding: 0; border-radius: 18px; width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px); background: var(--surface); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(20,14,12,.55); }
dialog.sheet > div, dialog.sheet > form { padding: 20px; }
dialog.sheet h2 { margin: 0; font-size: 1.3rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
.toast--bad { background: var(--danger); }

/* WSPÓLNA KOLUMNA TREŚCI (statystyki, zakładki, listy wyrównane do jednej linii) */
.shell { max-width: 900px; margin: 0 auto; padding: 0 16px; }
.shell .stats { padding: 12px 0 0; }
.shell .tabs { padding: 12px 0 0; background: transparent; }
.shell .pane { max-width: none; padding: 14px 0 120px; }

.hist { display: grid; gap: 6px; padding: 12px 14px; }
.hist__meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--line); color: var(--ink); }
.pill--sale { background: var(--accent-soft); color: var(--accent); }
.pill--receipt { background: #e4f3ea; color: var(--ok); }
.pill--issue { background: #fdf0dc; color: #8a5a00; }
.pill--adjustment { background: #ece8ff; color: #4b3d9a; }
.hist__qty { font-weight: 700; }
.hist__qty.plus { color: var(--ok); }
.hist__qty.minus { color: var(--danger); }

/* NAWIGACJA MODUŁÓW */
.modules { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.modules a { white-space: nowrap; min-height: 40px; display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 600; }
.modules a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* DYSTRYBUTOR (wiersz select + przycisk) */
.supplier-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.supplier-row select { min-width: 0; }

/* POWIĘKSZENIE ZDJĘCIA */
.thumb-zoom { cursor: zoom-in; }
dialog.lightbox { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100vh; width: 100%; height: 100%; }
dialog.lightbox::backdrop { background: rgba(10,8,8,.9); }
dialog.lightbox img { display: block; margin: auto; max-width: 96vw; max-height: 90vh; object-fit: contain; border-radius: 12px; }
dialog.lightbox form, dialog.lightbox > div { height: 100%; display: grid; place-items: center; }
.lightbox__close { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; }

/* WYNIKI WYSZUKIWANIA W SPRZEDAŻY */
.matches-hint { margin: 0 0 4px; }
.item__supplier { font-size: 12px; color: var(--muted); }
