/* LICZNIK — panel sklepu (koncept Studio WWW)
   Spokojny, gęsty informacyjnie: neutralne tło z nutą szałwii, głęboka zieleń jako kolor marki,
   miedź jako akcent. Dwa motywy przez [data-theme] na <html>. Mobile-first od 320 px. */

:root, [data-theme="light"] {
  --bg: #F3F4EF; --surface: #FFFFFF; --surface-2: #F0F2EC; --surface-3: #E6E9E1; --line: #DADFD4; --line-2: #C7CEC0;
  --ink: #17201C; --ink-2: #44514A; --ink-3: #56635C;
  --brand: #0D6B58; --brand-2: #0A5646; --brand-soft: #DCEEE7; --on-brand: #FFFFFF; --brand-ink: #0A5646;
  --accent: #A9521C; --accent-2: #F2B87C; --accent-soft: #F8E7D8;
  --good: #146C43; --bad: #B3261E; --warn-ink: #8A4B00; --warn-soft: #FCEBD0;
  --prev: #8C968F; --c3: #4E63C9; --c4: #8A5FB8;
  --st-nowe-bg: #E3ECFB; --st-nowe: #1D4F9C;
  --st-opl-bg: #DCEEE7; --st-opl: #0A5646;
  --st-wys-bg: #EAECE6; --st-wys: #3D4943;
  --st-zw-bg: #FBE4E1; --st-zw: #9C2219;
  --heat-0: #EEF1EA; --heat-1: #0D6B58;
  --strip-bg: #17201C; --strip-ink: #E9EEE9; --strip-hi: #F2B87C;
  --shadow: 0 1px 2px rgba(23, 32, 28, .06), 0 8px 24px -12px rgba(23, 32, 28, .18);
  --shadow-lg: 0 24px 60px -20px rgba(15, 25, 20, .45);
  --backdrop: rgba(18, 26, 22, .42);
  --focus: #0B57D0;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0F1513; --surface: #161E1B; --surface-2: #1B2521; --surface-3: #222E29; --line: #2A3631; --line-2: #3A4842;
  --ink: #E5ECE8; --ink-2: #B4C1BA; --ink-3: #9DABA4;
  --brand: #4CC9A3; --brand-2: #6FD9B7; --brand-soft: #173A31; --on-brand: #06201A; --brand-ink: #7FE0C0;
  --accent: #F0A46A; --accent-2: #F2B87C; --accent-soft: #3A2A1E;
  --good: #6FD9A0; --bad: #FF8A80; --warn-ink: #F5C27A; --warn-soft: #3A2C17;
  --prev: #7D8A84; --c3: #93A4F5; --c4: #C9A2EE;
  --st-nowe-bg: #1C2B44; --st-nowe: #A9C7FF;
  --st-opl-bg: #173A31; --st-opl: #8FE3C6;
  --st-wys-bg: #263029; --st-wys: #C3CEC8;
  --st-zw-bg: #3D1F1C; --st-zw: #FFB4AB;
  --heat-0: #1C2622; --heat-1: #4CC9A3;
  --strip-bg: #22302A; --strip-ink: #DCE6E0; --strip-hi: #F5C08A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
  --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, .7);
  --backdrop: rgba(0, 0, 0, .6);
  --focus: #8AB4FF;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 14px/1.45 "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--brand-ink); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex: none; }
kbd { font: 500 11px/1 "IBM Plex Mono", ui-monospace, monospace; padding: 3px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); color: var(--ink-2); }
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-weight: 500; font-size: .94em; }
.sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--surface); color: var(--ink); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); }
.skip:focus { top: 8px; }

/* pasek informacji o danych przykładowych */
.demo-strip { background: var(--strip-bg); color: var(--strip-ink); font-size: 12.5px; line-height: 1.4; padding: 7px 16px; }
.demo-strip strong { color: var(--strip-hi); font-weight: 600; }

/* ---------- układ ---------- */
.app { min-height: 100vh; }
.side { display: none; }
.col { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 12px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; }
.search-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink-3); text-align: left;
}
.search-btn svg { width: 18px; height: 18px; }
.search-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-kbd { display: none; }
.top-acts { display: flex; gap: 2px; }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn .dot { position: absolute; top: 8px; right: 8px; min-width: 9px; height: 9px; border-radius: 9px; background: var(--accent); box-shadow: 0 0 0 2px var(--bg); }
[data-theme="light"] .t-sun, [data-theme="dark"] .t-moon { display: none; }

main { display: block; padding: 16px 12px 96px; max-width: 1480px; outline: none; }
.view { display: grid; gap: 14px; }
.vhead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.vtitle { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h1 { font-size: 22px; line-height: 1.2; font-weight: 600; letter-spacing: -.01em; outline: none; }
.chip-demo { font-size: 11.5px; font-weight: 600; letter-spacing: .02em; color: var(--warn-ink); background: var(--warn-soft); padding: 3px 8px; border-radius: 99px; border: 1px dashed currentColor; }
.vsub { color: var(--ink-2); font-size: 13px; max-width: 90ch; }
.vsub b { font-weight: 600; color: var(--ink); }

/* przełącznik segmentowy (radia) */
.seg { display: inline-flex; flex-wrap: wrap; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-3); }
.seg label { position: relative; display: block; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.seg span { display: flex; align-items: center; gap: 6px; min-height: 30px; padding: 4px 10px; border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg label:hover span { color: var(--ink); }
.seg .n { font-size: 11.5px; color: var(--ink-3); font-weight: 500; }
.seg-sm span { min-height: 26px; padding: 2px 8px; font-size: 12.5px; }

.period { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; }
.period .seg { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; }
.period .seg span { justify-content: center; padding: 4px 4px; }
.custom { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; width: 100%; }
.custom .field { flex: 1 1 130px; }

/* ---------- karty KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi { position: relative; display: grid; gap: 4px; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.kpi-l { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.kpi-v { font-size: clamp(17px, 5.4vw, 26px); font-weight: 600; letter-spacing: -.015em; line-height: 1.15; white-space: nowrap; }
.kpi-d { display: flex; flex-wrap: wrap; gap: 0 6px; font-size: 12px; color: var(--ink-3); }
.delta { font-weight: 600; white-space: nowrap; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--ink-2); }
.kpi-spark { width: 100%; height: 30px; display: block; margin-top: 2px; }

/* ---------- karty ---------- */
.card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; align-content: start; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.card-head h2 { font-size: 15px; font-weight: 600; }
.card-note { font-size: 12px; color: var(--ink-3); }
.grid-2 { display: grid; gap: 14px; }
.legend { display: flex; gap: 12px; list-style: none; padding: 0; margin: 0; font-size: 12px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.lg { width: 16px; height: 0; border-top: 2.5px solid var(--brand); }
.lg-prev { border-top: 2px dashed var(--prev); }

.chart { position: relative; min-width: 0; }
.chart-line { height: 230px; outline-offset: 4px; border-radius: 6px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart text { fill: var(--ink-3); font-size: 11px; font-family: inherit; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ln-cur { fill: none; stroke: var(--brand); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .ar-cur { fill: var(--brand); opacity: .09; }
.chart .ln-prev { fill: none; stroke: var(--prev); stroke-width: 1.6; stroke-dasharray: 4 4; }
.chart .cursor { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .pt { fill: var(--surface); stroke: var(--brand); stroke-width: 2.25; }
.chart .pt-prev { fill: var(--surface); stroke: var(--prev); stroke-width: 1.6; }
.tip {
  position: absolute; z-index: 5; top: 0; left: 0; pointer-events: none; min-width: 150px; padding: 8px 10px; border-radius: 8px;
  background: var(--ink); color: var(--bg); font-size: 12px; line-height: 1.45; box-shadow: var(--shadow); white-space: nowrap;
}
.tip b { font-weight: 600; }
.tip .tp { opacity: .78; }
.chart-hint { font-size: 12px; color: var(--ink-3); }

/* kanały: poziome paski HTML + legenda */
.ch-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-3); }
.ch-bar span { display: block; height: 100%; }
.ch-bar span + span { box-shadow: -2px 0 0 var(--surface); }
.ch-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.ch-list li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto auto; align-items: center; gap: 4px 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.ch-list li:last-child { border-bottom: 0; }
.ch-sw { width: 10px; height: 10px; border-radius: 3px; }
.ch-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-n { font-weight: 600; text-align: right; }
.ch-p { color: var(--ink-3); width: 46px; text-align: right; font-size: 12px; }
.ch-d { grid-column: 2 / -1; font-size: 11.5px; color: var(--ink-3); margin-top: -3px; }

.chart-top svg { height: auto; }
.chart-top .bar { fill: var(--brand); }
.chart-top .bar-bg { fill: var(--surface-2); }
.chart-top .lbl { fill: var(--ink); font-size: 12.5px; }
.chart-top .val { fill: var(--ink-2); font-size: 12px; font-weight: 600; }

.chart-heat svg { height: auto; }
.chart-heat .cell { stroke: var(--surface); stroke-width: 2; }
.heat-scale { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-3); justify-content: flex-end; }
.heat-scale i { width: 80px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--heat-0), var(--heat-1)); }
.heat-peak { font-size: 12.5px; color: var(--ink-2); }

.data-alt { font-size: 13px; }
.data-alt summary { cursor: pointer; color: var(--brand-ink); font-weight: 500; width: fit-content; padding: 4px 0; }
.alt-body { max-height: 320px; overflow: auto; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; }
.alt-body table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.alt-body th, .alt-body td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.alt-body th:first-child, .alt-body td:first-child { text-align: left; }
.alt-body thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--ink-2); }

.todo { display: grid; gap: 10px; }
.todo-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.todo-item svg { width: 18px; height: 18px; margin-top: 1px; color: var(--accent); }
.todo-item b { font-weight: 600; }
.todo-item p { font-size: 13px; color: var(--ink-2); }
.todo-item .link { font-size: 13px; }
.link { background: none; border: 0; padding: 0; color: var(--brand-ink); text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }

/* ---------- pasek narzędzi, pola ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.field select, .field input, .num-in {
  height: 36px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); min-width: 0;
}
.field select { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px; background-repeat: no-repeat; }
.field-search { position: relative; flex: 1 1 100%; }
.field-search svg { position: absolute; left: 10px; top: 9px; width: 18px; height: 18px; color: var(--ink-3); pointer-events: none; }
.field-search input { width: 100%; padding-left: 36px; }
.toolbar > .field:not(.field-search) { flex: 1 1 140px; }
.toolbar .seg { flex: 1 1 100%; }
.tb-acts { display: flex; gap: 8px; flex: 1 1 100%; justify-content: flex-end; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); color: var(--ink); font-weight: 500; font-size: 13.5px; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 17px; height: 17px; }
.btn-pri { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-pri:hover { background: var(--brand-2); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-danger { color: var(--bad); }
.btn-sm { height: 30px; padding: 0 8px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: flex-start; height: 44px; }
.count { font-size: 12.5px; color: var(--ink-3); }

/* ---------- tabele ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl caption { text-align: left; }
.tbl th, .tbl td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.tbl tbody tr:last-child > * { border-bottom: 0; }
.tbl tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.tbl .r { text-align: right; }
.tbl td.r { white-space: nowrap; }
.tbl tbody th { font-weight: 500; }
.sort { display: inline-flex; align-items: center; gap: 4px; padding: 2px 0; border: 0; background: none; font: inherit; color: inherit; }
.sort::after { content: ""; width: 0; height: 0; border: 4px solid transparent; border-top-color: currentColor; opacity: .3; margin-top: 4px; }
[aria-sort="ascending"] .sort::after { border-top-color: transparent; border-bottom-color: currentColor; opacity: 1; margin-top: -4px; }
[aria-sort="descending"] .sort::after { opacity: 1; }
[aria-sort] .sort { color: var(--ink); }
th.r .sort { flex-direction: row; }
.row-btn { border: 0; background: none; padding: 0; color: var(--brand-ink); font-weight: 600; text-align: left; text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }
.row-btn:hover { text-decoration-color: currentColor; }
.sub { display: block; font-size: 12px; color: var(--ink-3); }
.empty { padding: 28px 16px; text-align: center; color: var(--ink-2); background: var(--surface); border: 1px dashed var(--line-2); border-radius: 12px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-nowe { background: var(--st-nowe-bg); color: var(--st-nowe); }
.st-oplacone { background: var(--st-opl-bg); color: var(--st-opl); }
.st-wyslane { background: var(--st-wys-bg); color: var(--st-wys); }
.st-zwrot { background: var(--st-zw-bg); color: var(--st-zw); }
.lv-ok { background: var(--st-opl-bg); color: var(--st-opl); }
.lv-niski { background: var(--warn-soft); color: var(--warn-ink); }
.lv-brak { background: var(--st-zw-bg); color: var(--st-zw); }
.sg-nowi { background: var(--st-nowe-bg); color: var(--st-nowe); }
.sg-powracajacy { background: var(--st-opl-bg); color: var(--st-opl); }
.sg-uspieni { background: var(--st-wys-bg); color: var(--st-wys); }

/* karty zamiast tabel (telefon) */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ocard { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.ocard .oc-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex-wrap: wrap; }
.ocard .oc-sum { font-weight: 600; text-align: right; white-space: nowrap; }
.ocard .oc-meta { grid-column: 1 / -1; font-size: 12.5px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: center; }
.ocard .oc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 100%; }
.ocard .oc-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }

.num-in { width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
.num-in[aria-invalid="true"] { border-color: var(--bad); }
.stock-edit { display: inline-flex; gap: 6px; align-items: center; }
.cover-bar { display: block; width: 70px; height: 5px; border-radius: 3px; background: var(--surface-3); margin-top: 4px; overflow: hidden; margin-left: auto; }
.cover-bar i { display: block; height: 100%; background: var(--brand); }
.cover-bar.lo i { background: var(--accent); }

.stock-sum { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.mini { padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.mini-l { font-size: 12px; color: var(--ink-2); }
.mini-v { font-size: 19px; font-weight: 600; }
.mini.warn .mini-v { color: var(--warn-ink); } .mini.bad .mini-v { color: var(--bad); }

.alerts { border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.alerts h2 { font-size: 14px; display: flex; gap: 8px; align-items: center; }
.alerts h2 svg { width: 18px; height: 18px; color: var(--accent); }
.alerts ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink); display: grid; gap: 2px; }

.segcards { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; min-width: 0; }
.segcard { position: relative; display: block; }
.segcard input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segcard .sc-in { display: grid; gap: 2px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); height: 100%; }
.segcard input:checked + .sc-in { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.segcard input:focus-visible + .sc-in { outline: 2px solid var(--focus); outline-offset: 2px; }
.sc-name { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.sc-n { font-size: 20px; font-weight: 600; }
.sc-d { font-size: 12px; color: var(--ink-3); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pager .pg-info { font-size: 12.5px; color: var(--ink-2); }
.pager .pg-btns { display: flex; gap: 6px; align-items: center; }
.pager .btn[aria-disabled="true"] { opacity: .45; cursor: default; }
.pager .field { grid-auto-flow: column; align-items: center; gap: 6px; }
.pager select { height: 32px; }

/* ---------- dialogi ---------- */
dialog { color: var(--ink); background: var(--surface); border: 1px solid var(--line); padding: 0; box-shadow: var(--shadow-lg); }
dialog::backdrop { background: var(--backdrop); }
.drawer {
  margin: 0 0 0 auto; height: 100%; max-height: 100%; width: min(540px, 100vw); max-width: 100vw; border-radius: 0; border-width: 0 0 0 1px;
}
.drawer[open] { animation: drIn .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes drIn { from { transform: translateX(40px); opacity: 0; } }
.dr-in { display: flex; flex-direction: column; height: 100%; }
.dr-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.dr-head h2 { flex: 1; font-size: 17px; font-weight: 600; outline: none; min-width: 0; }
.dr-back + h2 { padding-left: 0; }
.dr-body { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 18px; align-content: start; }
.dr-sec { display: grid; gap: 8px; }
.dr-sec h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.lines { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.lines th, .lines td { padding: 7px 0; border-bottom: 1px solid var(--line); text-align: left; }
.lines .r { text-align: right; padding-left: 10px; white-space: nowrap; }
.lines thead th { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.lines tfoot th, .lines tfoot td { border-bottom: 0; padding: 4px 0; }
.lines tfoot tr.tot > * { font-weight: 600; font-size: 15px; padding-top: 8px; border-top: 1px solid var(--line-2); }
.lines tbody th { font-weight: 500; }
.st-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.tl { list-style: none; margin: 0; padding: 0 0 0 4px; display: grid; }
.tl li { position: relative; padding: 0 0 14px 22px; font-size: 13.5px; }
.tl li::before { content: ""; position: absolute; left: 0; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
.tl li::after { content: ""; position: absolute; left: 5px; top: 17px; bottom: 0; width: 2px; background: var(--line); }
.tl li:last-child::after { display: none; }
.tl li:last-child { padding-bottom: 0; }
.tl li:last-child::before { background: var(--brand); }
.tl .tl-t { display: block; font-size: 12px; color: var(--ink-3); }
.tl b { font-weight: 600; }
.mini-orders { list-style: none; margin: 0; padding: 0; display: grid; }
.mini-orders li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.mini-orders .mo-d { color: var(--ink-2); font-size: 12.5px; }

.palette { margin: 10vh auto auto; width: min(640px, calc(100vw - 20px)); max-width: none; border-radius: 14px; }
.palette[open] { animation: palIn .16s ease-out; }
@keyframes palIn { from { transform: translateY(-8px) scale(.99); opacity: 0; } }
.pal-field { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.pal-field svg { width: 20px; height: 20px; color: var(--ink-3); }
.pal-field input { flex: 1; min-width: 0; height: 52px; border: 0; background: transparent; font-size: 16px; outline: none; }
#pal-list { list-style: none; margin: 0; padding: 6px; max-height: min(420px, 56vh); overflow-y: auto; }
#pal-list .pg { padding: 8px 10px 4px; font-size: 11.5px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
#pal-list [role="option"] { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
#pal-list [role="option"] .ph { margin-left: auto; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
#pal-list [role="option"][aria-selected="true"] { background: var(--brand-soft); color: var(--ink); box-shadow: inset 3px 0 0 var(--brand); }
#pal-list .pe { padding: 18px 10px; color: var(--ink-2); font-size: 13.5px; }
.pal-foot { display: none; gap: 6px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3); }

.notif { margin: 64px 8px auto auto; width: min(400px, calc(100vw - 16px)); max-width: none; max-height: calc(100vh - 80px); border-radius: 14px; }
.notif[open] { display: flex; flex-direction: column; animation: palIn .16s ease-out; }
.nt-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.nt-head h2 { flex: 1; font-size: 15px; font-weight: 600; outline: none; }
.nt-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; }
.nt-list li { display: grid; grid-template-columns: 8px minmax(0, 1fr); gap: 10px; padding: 10px; border-radius: 8px; font-size: 13.5px; }
.nt-list li + li { border-top: 1px solid var(--line); border-radius: 0; }
.nt-list .ud { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; }
.nt-list .unread .ud { background: var(--accent); }
.nt-list .nt-t { display: block; font-size: 12px; color: var(--ink-3); }
.nt-list .nt-b { font-weight: 600; }
.nt-list .unread .nt-b::after { content: " · nowe"; font-weight: 500; color: var(--accent); font-size: 12px; }
.nt-foot { padding: 8px 16px 12px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line); }

.modal { width: min(520px, calc(100vw - 20px)); max-width: none; border-radius: 14px; padding: 0 0 16px; }
.modal-sm { width: min(400px, calc(100vw - 20px)); }
.modal[open] { animation: palIn .16s ease-out; }
.md-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; }
.md-head h2 { flex: 1; font-size: 16px; font-weight: 600; outline: none; }
.modal > p { padding: 0 16px; color: var(--ink-2); }
.md-acts { display: flex; gap: 8px; justify-content: flex-end; padding: 16px 16px 0; }
.keys { width: calc(100% - 32px); margin: 0 16px; border-collapse: collapse; font-size: 13.5px; }
.keys th, .keys td { padding: 7px 0; border-bottom: 1px solid var(--line); text-align: left; }
.keys th { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.keys td:first-child { white-space: nowrap; padding-right: 14px; }
.more-list { display: grid; gap: 8px; padding: 0 16px; }

.toast {
  position: fixed; left: 50%; bottom: 84px; z-index: 60; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 24px); padding: 10px 14px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 13.5px;
  box-shadow: var(--shadow); transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* dolne menu (telefon, tablet) */
.bnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.bnav a { position: relative; display: grid; justify-items: center; gap: 2px; padding: 6px 2px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-size: 11.5px; font-weight: 500; }
.bnav a svg { width: 22px; height: 22px; }
.bnav a[aria-current="page"] { color: var(--brand-ink); font-weight: 600; }
.bnav a[aria-current="page"] svg { color: var(--brand); }
.bnav .nav-count { position: absolute; top: 2px; left: calc(50% + 6px); }
.nav-count:empty { display: none; }
.nav-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: var(--on-brand); font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
.nav-count.warn { background: var(--accent); color: #fff; }
[data-theme="dark"] .nav-count.warn { color: #1E1208; }

.ftr { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); display: grid; gap: 8px; font-size: 12.5px; color: var(--ink-2); max-width: 110ch; }
.ftr strong { color: var(--ink); }
.nojs { padding: 20px; background: var(--surface); border-radius: 12px; border: 1px solid var(--line); display: grid; gap: 10px; }
.no-js .view, .no-js .bnav, .no-js .top-acts, .no-js .search-btn { display: none; }

/* ---------- szersze ekrany ---------- */
@media (min-width: 480px) {
  .period .seg { display: inline-flex; width: auto; }
  .period { width: auto; }
  .stock-sum { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 640px) {
  main { padding: 20px 20px 100px; }
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi { padding: 14px; }
  .kpi-v { font-size: clamp(20px, 2.4vw, 28px); }
  .segcards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .field-search { flex: 1 1 240px; }
  .tb-acts { flex: 0 0 auto; margin-left: auto; }
  .toolbar .seg { flex: 0 1 auto; }
  .chart-line { height: 260px; }
  .card { padding: 16px; }
}
@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: 236px minmax(0, 1fr); }
  .side {
    display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 16px 12px; border-right: 1px solid var(--line); background: var(--surface);
  }
  .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); padding: 4px 6px; }
  .brand-txt { display: grid; }
  .brand .brand-name { font-weight: 600; font-size: 17px; line-height: 1.1; }
  .brand-shop { font-size: 11.5px; color: var(--ink-3); }
  .nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
  .nav-list a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
  .nav-list a svg { width: 20px; height: 20px; }
  .nav-list a:hover { background: var(--surface-2); color: var(--ink); }
  .nav-list a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
  .nav-list .nav-count { margin-left: auto; }
  .side-foot { margin-top: auto; display: grid; gap: 2px; }
  .side-btn { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 9px; background: none; color: var(--ink-2); text-align: left; font-size: 13.5px; }
  .side-btn:hover { background: var(--surface-2); color: var(--ink); }
  .side-btn svg { width: 18px; height: 18px; }
  .side-btn kbd { margin-left: auto; }
  .side-note { padding: 8px 10px 0; font-size: 12px; color: var(--ink-3); }
  .top { padding: 0 24px; height: 60px; }
  .top-brand, .more-btn, .bnav { display: none; }
  .search-btn { flex: 0 1 440px; margin-right: auto; }
  .search-kbd { display: inline-flex; gap: 3px; }
  .pal-foot { display: flex; }
  main { padding: 22px 28px 40px; }
  .toast { bottom: 24px; }
  .notif { margin-top: 68px; margin-right: 20px; }
  .grid-2 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  .grid-2.grid-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .chart-line { height: 280px; }
  .view { gap: 16px; }
}
@media (min-width: 1280px) {
  .stock-sum { grid-template-columns: repeat(4, minmax(0, 220px)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .seg input:checked + span, .segcard input:checked + .sc-in { outline: 2px solid CanvasText; }
  .badge { border: 1px solid CanvasText; }
}

/* uzupełnienia */
.field-inline { display: inline-flex; align-items: center; gap: 8px; }
.field-inline label { font-size: 12.5px; color: var(--ink-2); }
.h3 { font-size: 14px; font-weight: 600; margin: 0; }
.dr-sec { display: grid; gap: 10px; padding: 16px 0; border-top: 1px solid var(--line); }
.dr-sec:first-of-type { border-top: 0; }
.dr-sec h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin: 0; }
.dr-sec h3:focus { outline: none; }
.dr-sec h3:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.st-now { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0; font-size: 13.5px; color: var(--ink-2); }
.sub { display: block; font-size: 12px; color: var(--ink-2); }
.nt-list .nt-d { display: block; font-size: 13px; color: var(--ink-2); }
.count { font-size: 12.5px; color: var(--ink-2); }
html.ready .no-js-only { display: none; }
h1[tabindex="-1"]:focus-visible, h2[tabindex="-1"]:focus-visible, h3[tabindex="-1"]:focus-visible { outline: none; }
@media (min-width: 1024px) {
  .app { background: linear-gradient(to right, var(--surface) 235px, var(--line) 235px 236px, transparent 236px); }
}
/* tabele alternatywne nie rozpychają kart */
.card { grid-template-columns: minmax(0, 1fr); }
.data-alt, .alt-body { min-width: 0; max-width: 100%; }
.alt-body:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
/* bardzo wąskie ekrany: wyszukiwarka jako ikona (nazwa zostaje dla czytników) */
@media (max-width: 359px) {
  .search-btn { flex: 0 0 40px; width: 40px; padding: 0; justify-content: center; margin-left: auto; }
  .search-txt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
