:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --ink: #14110f;
  --muted: #6f6861;
  --line: #e2dcd3;
  --accent: #e8492f;
  --accent-ink: #ffffff;
  --pos: #1f7a4a;
  --neg: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,17,15,.06), 0 4px 16px rgba(20,17,15,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1e1b18;
    --surface-2: #2a2622;
    --ink: #f3eee8;
    --muted: #a39b92;
    --line: #36312c;
    --pos: #4cc38a;
    --neg: #ff7a6b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
h2, h3 { margin: 0; line-height: 1.2; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.error { color: var(--neg); margin: 8px 0 0; font-weight: 500; }

/* ---- przyciski ---- */
button { cursor: pointer; border: 0; background: none; }
button:disabled { cursor: not-allowed; opacity: .45; }
.primary {
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 18px; border-radius: 10px; font-weight: 600;
}
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.primary.wide { width: 100%; padding: 12px; }
.ghost { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.ghost:hover { background: var(--surface-2); }
.ghost.small { padding: 5px 10px; font-size: 13px; }
.x { width: 32px; height: 32px; border-radius: 8px; font-size: 22px; line-height: 1; color: var(--muted); }
.x:hover { background: var(--surface-2); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- inputy ---- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
label > input, .stepper {
  display: block; width: 100%; margin-top: 5px;
}
input[type=text], input:not([type]), input[type=password], input[type=search], input[type=number] {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-size: 16px; color: var(--ink); width: 100%;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---- nagłówek ---- */
.brand { font-weight: 900; letter-spacing: .02em; font-size: 20px; }
.brand span { color: var(--accent); font-weight: 600; margin-left: 4px; font-style: italic; }
.brand.big { font-size: 34px; text-align: center; margin-bottom: 20px; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: #14110f; color: #f3eee8;
}
.top .user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #c9c1b8; }
.top .ghost { background: transparent; border-color: #3a3430; color: #f3eee8; }
.top .ghost:hover { background: #2a2622; }

main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 100px; }

/* ---- podsumowanie ---- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  display: flex; flex-direction: column; min-width: 0;
}
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat strong { font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.pos strong { color: var(--pos); }
.stat.neg strong { color: var(--neg); }
.stat.strong { border-width: 2px; }
.stat small { color: var(--muted); font-size: 12px; }

/* ---- zakładki / toolbar ---- */
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tabs button { padding: 8px 18px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1 1 200px; width: auto; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { padding: 8px 12px; font-size: 14px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--ink); color: var(--bg); }
.chk { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; color: var(--ink); font-size: 14px; }
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---- karty magazynu ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
.card.empty { opacity: .6; }
.card-head { display: flex; gap: 12px; align-items: center; }
.card-head h3 { font-size: 17px; overflow-wrap: anywhere; }
.card-head p { margin: 2px 0 0; }
.swatch-icon { background: var(--surface-2); border-radius: 12px; padding: 6px; display: grid; place-items: center; flex: none; }
.count { text-align: center; flex: none; }
.count strong { display: block; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.count span { font-size: 12px; color: var(--muted); }
.size-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: flex; align-items: baseline; gap: 6px; padding: 7px 12px; min-height: 40px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.chip b { font-size: 14px; }
.chip span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip:not(:disabled):hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.card-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px dashed var(--line); padding-top: 10px; }
.empty-msg { color: var(--muted); text-align: center; padding: 40px 0; grid-column: 1 / -1; }
.garment { display: block; flex: none; }

/* ---- historia ---- */
.history { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.hrow { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.hrow:last-child { border-bottom: 0; }
.hrow > strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hrow.przyjecie { border-left: 3px solid var(--neg); }
.hrow.wydanie { border-left: 3px solid var(--pos); }
.history .empty-msg { padding: 30px; }

/* ---- dialogi ---- */
dialog {
  border: 0; padding: 0; border-radius: 18px; width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(20,17,15,.55); }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 18px; }
.dlg-body { padding: 16px 18px; overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface); }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.total { margin: 6px 0 0; font-size: 16px; }

.intake-top { display: flex; gap: 14px; align-items: flex-start; }
.preview { background: var(--surface-2); border-radius: 14px; padding: 8px; flex: none; }
.type-pick { display: flex; gap: 8px; margin-bottom: 12px; }
.type-pick label {
  flex: 1; margin: 0; display: flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; color: var(--ink); font-size: 14px;
}
.type-pick input { position: absolute; opacity: 0; pointer-events: none; }
.type-pick label:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.type-pick label:has(input:focus-visible) { outline: 2px solid var(--accent); }

.palette { display: grid; grid-template-columns: repeat(auto-fill, 38px); gap: 8px; }
.sw {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2);
  position: relative; padding: 0;
}
.sw.sel { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.sw.custom {
  display: grid; place-items: center; margin: 0; cursor: pointer; font-size: 20px; color: var(--ink);
  background: conic-gradient(#f43f5e, #f59e0b, #84cc16, #06b6d4, #6366f1, #d946ef, #f43f5e);
}
.sw.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.size-cell { margin: 0; text-align: center; color: var(--ink); }
.size-cell span { display: block; font-size: 14px; margin-bottom: 4px; }
.size-cell input { text-align: center; padding: 8px 4px; }

.issue-product { display: flex; gap: 14px; align-items: center; background: var(--surface-2); padding: 10px 12px; border-radius: 12px; margin-bottom: 14px; }
.stepper { display: flex; gap: 0; }
.stepper input { text-align: center; border-radius: 0; width: 100%; min-width: 0; }
.stepper button { width: 44px; flex: none; border: 1px solid var(--line); background: var(--surface-2); font-size: 20px; }
.stepper button:first-child { border-radius: 10px 0 0 10px; border-right: 0; }
.stepper button:last-child { border-radius: 0 10px 10px 0; border-left: 0; }

/* ---- toast, FAB ---- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 500;
  transition: .2s; pointer-events: none; z-index: 20; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--neg); color: #fff; }
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 10;
  width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 32px; line-height: 1; box-shadow: 0 6px 20px rgba(232,73,47,.45);
}

/* ---- logowanie ---- */
.login-page { display: grid; place-items: center; padding: 16px; background: #14110f; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border-radius: 18px; padding: 28px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

/* ---- responsywność ---- */
.mobile-only { display: none; }
@media (max-width: 720px) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat strong { font-size: 17px; }
  .cards { grid-template-columns: 1fr; }
  .tabs { flex: 1; }
  .tabs button { flex: 1; }
  .toolbar .seg { flex: 1; }
  .toolbar .seg button { flex: 1; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  dialog form { max-height: 92dvh; }
  .dlg-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .dlg-foot button { flex: 1; }
  .preview svg { width: 72px; height: 72px; }
  .hrow { padding: 10px; gap: 10px; }
}
