:root {
  --bg: #f6f1e7;
  --card: #fffdf8;
  --line: #e4dccb;
  --ink: #22302a;
  --muted: #5d6a62;
  --green: #2f4a3a;
  --green-soft: #dbe8d8;
  --yellow-soft: #f7e6b5;
  --pink-soft: #ecd9dc;
  --warn: #9a4a12;
  --warn-soft: #fbead8;
  --bad: #a3271f;
  --r: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 84px;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #7aa58a; outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.muted { color: var(--muted); font-size: 14px; }
.sp { flex: 1; }
.plus { color: #2c6b3f; }
.minus { color: var(--bad); }

/* nagłówek i nawigacja */
.top { background: var(--green); color: #fff; }
.top-in { max-width: 920px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 700; font-size: 19px; letter-spacing: -0.01em; }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.caps { flex: none; transform-origin: 50% 55%; animation: caps 3.6s ease-in-out infinite; }
.auth-card .caps { width: 30px; height: 30px; }
@keyframes caps {
  0%, 62%, 100% { transform: rotate(0) translateY(0); }
  70% { transform: rotate(-20deg) translateY(-3px); }
  78% { transform: rotate(16deg) translateY(0); }
  86% { transform: rotate(-9deg) translateY(-1px); }
  93% { transform: rotate(4deg); }
}
#nav { display: flex; gap: 4px; }
#nav button {
  background: none; border: 0; color: #d7e3da; padding: 8px 12px; border-radius: 999px; font-size: 15px; font-weight: 500;
}
#nav button:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
#nav button[aria-current] { background: #fff; color: var(--green); font-weight: 650; }

main#view { max-width: 920px; margin: 0 auto; padding: 20px 16px 8px; outline: none; }
.vhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.vhead h1 { font-size: 26px; letter-spacing: -0.02em; text-wrap: balance; }
.sub { color: var(--muted); margin-bottom: 14px; max-width: 60ch; }

.pill {
  display: inline-block; background: var(--green); color: #fff; font-size: 15px; font-weight: 600;
  padding: 6px 16px; border-radius: 12px 12px 12px 0; margin: 22px 0 8px;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
ul.list, ul.steps, ul.alerts { list-style: none; margin: 0; padding: 0; }
ul.list > li + li { border-top: 1px solid var(--line); }
.empty { padding: 16px; color: var(--muted); }

/* kafle */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tile {
  border: 0; border-radius: var(--r); padding: 14px 16px; text-align: left; display: flex; flex-direction: column; gap: 2px;
}
.tile span { font-weight: 600; font-size: 14px; }
.tile b { font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tile small { font-size: 16px; font-weight: 600; }
.t-green { background: var(--green-soft); }
.t-yellow { background: var(--yellow-soft); }
.t-pink { background: var(--pink-soft); }
.tile:hover { filter: brightness(0.97); }

.mini { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 16px; }
.mini b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini.col { flex-direction: column; align-items: stretch; gap: 6px; }
.mini.col .mini { padding: 0; }
.alerts { padding: 6px 16px !important; background: var(--warn-soft); border-color: #efd3b5; }
.alerts li { padding: 6px 0; font-size: 15px; }

.bar { height: 8px; background: #e9e2d2; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: #4f8a63; border-radius: 99px; }

/* wiersze magazynu */
.search {
  width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); margin-top: 6px;
}
.row { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 6px; }
.row.low { background: var(--warn-soft); }
.row-main {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 6px 10px; border-radius: 10px;
  display: flex; flex-direction: column; gap: 1px;
}
.row-main:hover { background: rgba(47, 74, 58, 0.06); }
.nm { font-weight: 600; overflow-wrap: anywhere; }
.nt { color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; }
.nt.warn { color: var(--warn); font-weight: 600; }
.qty { text-align: right; white-space: nowrap; min-width: 64px; }
.qty b { font-size: 20px; font-variant-numeric: tabular-nums; display: block; line-height: 1.1; }
.qty span { color: var(--muted); font-size: 13px; }
.pm { display: flex; gap: 6px; }
.ib {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 24px; line-height: 1;
  display: grid; place-items: center; color: var(--green);
}
.ib:hover { background: var(--green-soft); border-color: #b9cfb9; }

.thumb {
  flex: none; width: 52px; height: 52px; padding: 0; border-radius: 10px; border: 1px solid var(--line); background: #fff; overflow: hidden;
  display: grid; place-items: center; margin-left: 6px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.none { border-style: dashed; border-color: #cfc6b2; color: #8a948d; background: none; }
.thumb.none:hover { color: var(--green); border-color: var(--green); }
.row-main { padding-left: 6px; }
.photo-row { display: flex; gap: 12px; align-items: center; }
.photo-prev { width: 84px; height: 84px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); flex: none; }
.photo-btns { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; flex: 1; }
.photo-btns input { border: 0; padding: 0; min-height: 0; background: none; font-size: 14px; max-width: 100%; }
.viewer img { width: 100%; max-height: 70dvh; object-fit: contain; border-radius: 12px; background: #fff; }

/* historia */
.log { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; font-size: 15px; }
.log time { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }

/* produkcja */
.batch { padding: 16px; margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.batch.done { opacity: 0.8; }
.bhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.bhead h3 { font-size: 20px; }
.bqty { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.bqty b { font-size: 20px; font-variant-numeric: tabular-nums; }
.steps li label { font-weight: 400; font-size: 16px; display: flex; align-items: center; gap: 12px; padding: 9px 4px; cursor: pointer; }
.steps input { width: 22px; height: 22px; accent-color: var(--green); flex: none; }
.steps input:checked + span { color: var(--muted); text-decoration: line-through; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.ship { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.ship .mini { padding: 8px 0; }

/* spis */
.row.count { padding: 8px 16px; }
.row.count label { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row.count input { width: 92px; padding: 9px 10px; border: 1px solid #cfc6b2; border-radius: 10px; text-align: right; background: #fff; font-variant-numeric: tabular-nums; }
.row.count input.changed { border-color: #c98a2b; background: #fff6e1; font-weight: 700; }
.unit { width: 56px; color: var(--muted); font-size: 13px; }
.savebar {
  position: sticky; bottom: 76px; margin-top: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 10px 12px 10px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  box-shadow: 0 6px 20px rgba(34, 48, 42, 0.12);
}

/* przyciski */
.btn {
  border: 1px solid #cfc6b2; background: #fff; border-radius: 12px; padding: 10px 16px; font-weight: 600; min-height: 44px; white-space: nowrap;
}
.btn:hover { background: #f4efe3; }
.btn.small { padding: 6px 12px; min-height: 38px; font-size: 15px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: #26402f; }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: rgba(47, 74, 58, 0.08); }
.btn.link-danger { border-color: transparent; background: none; color: var(--bad); padding-left: 4px; padding-right: 4px; }
.btn.wide { width: 100%; margin-top: 18px; }

/* okno */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(20, 30, 25, 0.35);
}
dialog::backdrop { background: rgba(28, 40, 33, 0.45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { font-size: 20px; overflow-wrap: anywhere; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.half { grid-column: auto; }
label, legend { font-weight: 600; font-size: 14px; }
.field input, .field select, .field textarea, .auth-card input {
  width: 100%; padding: 10px 12px; border: 1px solid #cfc6b2; border-radius: 10px; background: #fff; min-height: 44px;
}
textarea { resize: vertical; }
.hint { color: var(--muted); font-size: 13px; }
.seg { grid-column: 1 / -1; border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg legend { margin-bottom: 4px; padding: 0; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span {
  display: block; text-align: center; padding: 10px 4px; border: 1px solid #cfc6b2; border-radius: 10px; background: #fff; font-size: 14px; cursor: pointer;
}
.seg input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid #7aa58a; outline-offset: 2px; }
.err { color: var(--bad); font-weight: 600; font-size: 14px; }

/* stopka, toast */
.foot { max-width: 920px; margin: 28px auto 0; padding: 0 16px; display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; }
.foot a, .foot button { color: var(--muted); background: none; border: 0; padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; }
#toast {
  position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s; max-width: calc(100vw - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); }

/* logowanie */
body.auth { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px 24px; width: min(380px, 100%); }
.auth-card h1 { font-size: 28px; color: var(--green); letter-spacing: -0.02em; margin-bottom: 4px; }
.auth-card label { display: block; margin: 16px 0 4px; }
.auth-card .err { margin-top: 12px; }

/* telefon: nawigacja na dole */
@media (max-width: 720px) {
  .top-in { padding: 10px 16px; }
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--green); display: flex; justify-content: space-between; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); overflow-x: auto;
  }
  #nav button { padding: 12px 4px; font-size: 11.5px; border-radius: 10px; flex: 1 0 auto; }
  .tiles { grid-template-columns: 1fr; gap: 8px; }
  .tile { flex-direction: row; justify-content: space-between; align-items: center; }
  .tile b { font-size: 24px; }
  .vhead h1 { font-size: 22px; }
  .row { gap: 6px; padding-right: 8px; }
  .qty { min-width: 52px; }
  .log { flex-direction: column; gap: 2px; }
  .log time { text-align: left; }
  .log time br { display: none; }
}
@media (min-width: 721px) {
  body { padding-bottom: 32px; }
  .savebar { bottom: 16px; }
  #toast { bottom: 28px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } .caps { animation: none; } }
@media print {
  .top, .foot, .pm, .btn, .search, .savebar { display: none !important; }
  body { background: #fff; padding: 0; }
}
