/* =========================================================================
   Klipvio Rozliczenia - arkusz stylów

   Motyw: zmienne w :root to wariant jasny, [data-theme="dark"] nadpisuje je
   na ciemny. Gdy użytkownik niczego nie wybrał, decyduje ustawienie systemu
   (prefers-color-scheme); wybór z przełącznika zapisuje data-theme na <html>
   i zawsze wygrywa.
   ========================================================================= */

:root {
  color-scheme: light;

  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --surface-3: #e8edf5;
  --sidebar: #101728;
  --sidebar-text: #a9b6cd;
  --sidebar-text-strong: #ffffff;
  --sidebar-hover: rgba(255, 255, 255, .07);
  --sidebar-active: rgba(99, 132, 255, .18);

  --border: #dfe5ee;
  --border-strong: #c3cddd;

  --text: #0d1526;
  --text-soft: #48546b;
  --text-muted: #6b7890;

  --accent: #3355e0;
  --accent-hover: #2843c4;
  --accent-soft: #e8edff;
  --accent-text: #ffffff;

  --ok: #0f7a4f;
  --ok-soft: #e3f7ee;
  --warn: #9a5b06;
  --warn-soft: #fdf3e0;
  --error: #b62222;
  --error-soft: #fdeceb;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(13, 21, 38, .05);
  --shadow: 0 1px 3px rgba(13, 21, 38, .07), 0 10px 28px -12px rgba(13, 21, 38, .18);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 244px;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b1120;
  --surface: #141b2c;
  --surface-2: #1a2336;
  --surface-3: #222d44;
  --sidebar: #080d18;
  --sidebar-text: #8896b0;
  --sidebar-text-strong: #ffffff;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(122, 155, 255, .20);

  --border: #263148;
  --border-strong: #3a4863;

  --text: #eaf0fa;
  --text-soft: #b3c0d6;
  --text-muted: #8494ae;

  --accent: #7a9bff;
  --accent-hover: #93aeff;
  --accent-soft: #1b2748;
  --accent-text: #0b1120;

  --ok: #4ade80;
  --ok-soft: #10291d;
  --warn: #fbbf24;
  --warn-soft: #2c2310;
  --error: #fb7185;
  --error-soft: #2e1520;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 10px 28px -12px rgba(0, 0, 0, .7);
}

/* Bez jawnego wyboru idziemy za ustawieniem systemu. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1120;
    --surface: #141b2c;
    --surface-2: #1a2336;
    --surface-3: #222d44;
    --sidebar: #080d18;
    --sidebar-text: #8896b0;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --sidebar-active: rgba(122, 155, 255, .20);
    --border: #263148;
    --border-strong: #3a4863;
    --text: #eaf0fa;
    --text-soft: #b3c0d6;
    --text-muted: #8494ae;
    --accent: #7a9bff;
    --accent-hover: #93aeff;
    --accent-soft: #1b2748;
    --accent-text: #0b1120;
    --ok: #4ade80;
    --ok-soft: #10291d;
    --warn: #fbbf24;
    --warn-soft: #2c2310;
    --error: #fb7185;
    --error-soft: #2e1520;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 10px 28px -12px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .35em; line-height: 1.25; font-weight: 680; letter-spacing: -.018em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .85em; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }

/* ================================================================ sidebar */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.15rem 1.15rem 1rem;
  color: var(--sidebar-text-strong);
  font-weight: 750;
  font-size: 1.06rem;
  letter-spacing: -.02em;
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(140deg, #4f6dff, #8b5cf6);
  display: grid; place-items: center;
  color: #fff; font-size: .92rem; font-weight: 800;
  flex: 0 0 auto;
}
.sidebar__brand small {
  display: block;
  font-size: .7rem;
  font-weight: 500;
  color: var(--sidebar-text);
  letter-spacing: .02em;
}

.sidebar__nav { padding: .35rem .6rem; display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar__section {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  font-weight: 700;
  color: var(--sidebar-text);
  opacity: .55;
  padding: 1rem .6rem .3rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .65rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: .93rem;
  font-weight: 550;
  line-height: 1.2;
  position: relative;
}
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); text-decoration: none; }
.nav-link.is-active { background: var(--sidebar-active); color: var(--sidebar-text-strong); font-weight: 650; }
.nav-link.is-active::before {
  content: "";
  position: absolute;
  left: -.6rem; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  border-radius: 0 3px 3px 0;
  background: #7a9bff;
}
.nav-link svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }

.sidebar__foot {
  padding: .8rem .9rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, .08);
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.sidebar__user { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.sidebar__avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--sidebar-active);
  color: var(--sidebar-text-strong);
  display: grid; place-items: center;
  font-size: .82rem; font-weight: 700;
  flex: 0 0 auto;
}
.sidebar__who { min-width: 0; }
.sidebar__name {
  color: var(--sidebar-text-strong);
  font-size: .88rem; font-weight: 620;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar__role { font-size: .74rem; color: var(--sidebar-text); }
.sidebar__actions { display: flex; gap: .4rem; }
.sidebar__actions form { margin: 0; flex: 1; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, .12);
  background: transparent;
  color: var(--sidebar-text);
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn .icon-dark { display: none; }
[data-theme="dark"] .icon-btn .icon-dark { display: block; }
[data-theme="dark"] .icon-btn .icon-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .icon-dark { display: block; }
  :root:not([data-theme="light"]) .icon-btn .icon-light { display: none; }
}

.sidebar__logout {
  width: 100%;
  padding: .45rem .6rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, .12);
  background: transparent;
  color: var(--sidebar-text);
  font: inherit; font-size: .84rem; font-weight: 600;
  cursor: pointer;
}
.sidebar__logout:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }

/* Pasek mobilny - widoczny tylko na wąskich ekranach. */
.mobilebar { display: none; }
.sidebar__backdrop { display: none; }

/* =================================================================== page */

.main { flex: 1; min-width: 0; }

.page { max-width: 1500px; margin: 0 auto; padding: 1.9rem 1.75rem 5rem; }
.page--centered { max-width: 430px; padding-top: 9vh; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-head p { color: var(--text-muted); margin: .2rem 0 0; font-size: .96rem; }
.page-head__actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.page-head__actions form { margin: 0; }

/* =================================================================== card */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.4rem;
  overflow: hidden;
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .95rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.card__title { margin: 0; font-size: 1rem; font-weight: 660; letter-spacing: -.01em; }
.card__actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.card__actions form { margin: 0; }
.card__body { padding: 1.25rem; }

/* =================================================================== stat */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem 1.15rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, #4f6dff, #8b5cf6);
  opacity: .9;
}
.stat__label {
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  font-weight: 700;
}
.stat__value {
  font-size: 1.85rem;
  font-weight: 700;
  margin-top: .3rem;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat__hint { font-size: .84rem; color: var(--text-muted); margin-top: .3rem; }

/* ================================================================== table */

.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .93rem;
}
table.data th,
table.data td {
  padding: .62rem .8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
  z-index: 1;
  border-bottom: 1px solid var(--border-strong);
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tfoot td {
  font-weight: 690;
  background: var(--surface-3);
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
}
/* Kolumna liczbowa.
   Selektor musi być co najmniej tak szczegółowy jak `table.data th, td`
   powyżej. Samo `.num` przegrywało z nim niezależnie od kolejności reguł,
   więc liczby w tabelach stały przy lewej krawędzi i cyfry nie układały się
   w słupek - „1 204” i „988” kończyły się w różnych miejscach. */
.num,
table.data th.num,
table.data td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Pole liczbowe osadzone w kolumnie liczbowej. Bez zawężenia rozlewało się
   na całą szerokość komórki i wpisana liczba odjeżdżała od reszty kolumny. */
table.data td.num input[type=number] { width: 6rem; text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: .87em; }
.muted { color: var(--text-muted); }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================================================================== forms */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 1rem 1.15rem;
  /* Pola rozciągają się na wysokość najwyższego w rzędzie. Przy `end`
     wyrównywały się dolnymi krawędziami, więc pole z podpowiedzią miało
     kontrolkę wyżej niż pole bez podpowiedzi i formularz wyglądał
     na rozjechany. */
  align-items: stretch;
}
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field--wide { grid-column: 1 / -1; }
/* Stała wysokość etykiety trzyma kontrolki w jednej linii także wtedy,
   gdy sąsiednia etykieta zawinie się do dwóch wierszy. */
.field > label {
  font-size: .84rem;
  font-weight: 640;
  color: var(--text-soft);
  line-height: 1.2;
  min-height: 1.15rem;
}
/* Podpowiedź spada do dolnej krawędzi pola, dzięki czemu same pola wejściowe
   zostają wyrównane niezależnie od tego, jak długi jest opis pod nimi. */
.field small { font-size: .82rem; color: var(--text-muted); line-height: 1.45; margin-top: auto; }
/* Pole, w którym jedyną kontrolką jest przełącznik, nie ma etykiety nad sobą.
   Bez odstępu przełącznik stałby w linii etykiet sąsiadów zamiast w linii ich
   pól wejściowych, a bez wysokości - przy górnej krawędzi zamiast na osi. */
.field > .checkbox:first-child {
  margin-top: calc(1.15rem + .35rem);
  min-height: 2.375rem;
}

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=file], select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .94rem;
}
textarea { min-height: 110px; resize: vertical; font-family: inherit; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
input[readonly] { background: var(--surface-2); color: var(--text-muted); }
select[multiple] { min-height: 150px; }

.checkbox { display: flex; align-items: center; gap: .5rem; font-size: .92rem; font-weight: 500; color: var(--text); }
.checkbox input { width: auto; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }

/* Grupa pól w długim formularzu - dzieli go na czytelne sekcje. */
.fieldgroup { border: 0; margin: 0 0 1.5rem; padding: 0; }
.fieldgroup:last-of-type { margin-bottom: 0; }
.fieldgroup > legend {
  padding: 0 0 .2rem;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 720;
  color: var(--text-muted);
}
.fieldgroup > .fieldgroup__hint {
  margin: 0 0 .85rem;
  font-size: .87rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.fieldgroup > .form-grid { padding-top: .55rem; border-top: 1px solid var(--border); }

.form-actions { display: flex; gap: .6rem; margin-top: 1.15rem; align-items: center; flex-wrap: wrap; }
.form-actions--inset { margin-top: 0; padding: 0 1.25rem 1.15rem; }
.select--narrow { max-width: 280px; }
/* Kompaktowa lista wyboru osadzona w komórce tabeli. */
.select--row { padding: .25rem .4rem; font-size: .86rem; min-width: 130px; max-width: 190px; }
.bulk-label { font-size: .88rem; }

/* ================================================================ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .52rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .92rem;
  font-weight: 620;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--danger { color: var(--error); border-color: var(--error); background: var(--surface); }
.btn--danger:hover { background: var(--error-soft); }
.btn--ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--sm { padding: .33rem .68rem; font-size: .86rem; }

/* ================================================================= badges */

.badge {
  display: inline-block;
  padding: .16rem .58rem;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 680;
  letter-spacing: .01em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge--role      { background: var(--accent-soft); color: var(--accent); }
.badge--draft     { background: var(--surface-3);   color: var(--text-muted); border-color: var(--border); }
.badge--issued    { background: var(--accent-soft); color: var(--accent); }
.badge--sent      { background: var(--warn-soft);   color: var(--warn); }
.badge--paid      { background: var(--ok-soft);     color: var(--ok); }
.badge--cancelled { background: var(--error-soft);  color: var(--error); }
.badge--us        { background: var(--warn-soft);   color: var(--warn); }

/* ================================================================== flash */

.flash {
  display: flex;
  gap: .6rem;
  padding: .85rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid;
  border-left-width: 4px;
  margin-bottom: 1.3rem;
  font-size: .95rem;
  font-weight: 520;
  line-height: 1.5;
}
.flash--ok    { background: var(--ok-soft);    border-color: var(--ok);    color: var(--ok); }
.flash--warn  { background: var(--warn-soft);  border-color: var(--warn);  color: var(--warn); }
.flash--error { background: var(--error-soft); border-color: var(--error); color: var(--error); }

.notice-list { margin: 0; padding-left: 1.2rem; font-size: .93rem; line-height: 1.6; }
.notice-list li { margin-bottom: .35rem; }

.empty { color: var(--text-muted); font-style: italic; padding: 2rem 0; text-align: center; margin: 0; }

/* ================================================================ wykresy */

/* Paleta wykresów - te same cztery tony w obu motywach. */
:root {
  --tone-1: #4f6dff;
  --tone-2: #8b5cf6;
  --tone-3: #14b8a6;
  --tone-4: #f59e0b;
}
[data-theme="dark"] {
  --tone-1: #7a9bff;
  --tone-2: #a78bfa;
  --tone-3: #2dd4bf;
  --tone-4: #fbbf24;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tone-1: #7a9bff;
    --tone-2: #a78bfa;
    --tone-3: #2dd4bf;
    --tone-4: #fbbf24;
  }
}

.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart__grid { stroke: var(--border); stroke-width: 1; }
.chart__bar { fill: var(--tone-1); transition: fill .12s ease; }
.chart__col:hover .chart__bar { fill: var(--tone-2); }
.chart__value {
  fill: var(--text-soft);
  font-size: 15px;
  font-weight: 650;
  text-anchor: middle;
  font-variant-numeric: tabular-nums;
}
.chart__label { fill: var(--text-muted); font-size: 15px; text-anchor: middle; }

.stackbar { width: 100%; height: 26px; border-radius: 6px; overflow: hidden; }
.stackbar svg { width: 100%; height: 100%; display: block; }
.stackbar__seg--1 { fill: var(--tone-1); }
.stackbar__seg--2 { fill: var(--tone-2); }
.stackbar__seg--3 { fill: var(--tone-3); }
.stackbar__seg--4 { fill: var(--tone-4); }

.legend { list-style: none; margin: .9rem 0 0; padding: 0; display: grid; gap: .35rem; }
.legend__item {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  gap: .6rem;
  align-items: center;
  font-size: .92rem;
}
.legend__dot { width: 11px; height: 11px; border-radius: 3px; }
.legend__dot--1 { background: var(--tone-1); }
.legend__dot--2 { background: var(--tone-2); }
.legend__dot--3 { background: var(--tone-3); }
.legend__dot--4 { background: var(--tone-4); }
.legend__label { color: var(--text-soft); }
.legend__value { font-variant-numeric: tabular-nums; font-weight: 620; }
.legend__share { color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 3.4rem; text-align: right; }

/* ================================================================== pager */

.pager { display: flex; gap: .3rem; align-items: center; padding: .9rem 1.25rem; flex-wrap: wrap; }
.pager__item {
  min-width: 34px;
  padding: .3rem .55rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .89rem;
  font-weight: 560;
  color: var(--text-soft);
}
.pager__item:hover { background: var(--surface-2); text-decoration: none; }
.pager__item.is-current { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.pager__gap { color: var(--text-muted); padding: 0 .2rem; }

/* ================================================================== login */

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; justify-content: center; margin-bottom: 1.1rem; }
.login-brand .sidebar__mark { width: 44px; height: 44px; border-radius: 12px; font-size: 1.2rem; }
.login-card h1 { text-align: center; margin-bottom: .2rem; font-size: 1.4rem; }
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: .93rem; margin-bottom: 1.6rem; }
.login-card .field { margin-bottom: 1rem; }
.login-card .btn { width: 100%; justify-content: center; padding: .62rem 1rem; }

/* ============================================================== utilities */

.row { display: flex; gap: .65rem; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row form { margin: 0; }
/* Kontrolki w pasku filtrów mają się układać w rzędzie, a nie rozciągać
   na całą szerokość i spadać jedna pod drugą. */
.row select,
.row input[type=text],
.row input[type=date],
.row input[type=number] { width: auto; min-width: 150px; }
.row label { font-size: .88rem; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 1.4rem; }
.mt-1 { margin-top: .7rem; }
.mt-2 { margin-top: 1.3rem; }
.mb-0 { margin-bottom: 0; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-error { color: var(--error); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.4rem; margin: 0; font-size: .95rem; }
dl.kv dt { color: var(--text-muted); font-weight: 620; }
dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ============================================================ responsive */

@media (max-width: 1000px) {
  .shell { flex-direction: column; }

  .mobilebar {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .9rem;
    background: var(--sidebar);
    position: sticky;
    top: 0;
    z-index: 40;
  }
  .mobilebar .sidebar__brand { padding: 0; flex: 1; font-size: .98rem; }
  .mobilebar .icon-btn { border-color: rgba(255, 255, 255, .14); }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .5);
  }
  .sidebar.is-open { transform: translateX(0); }

  .sidebar__backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 18, .55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
    z-index: 25;
  }
  .sidebar__backdrop.is-open { opacity: 1; pointer-events: auto; }

  .page { padding: 1.2rem 1rem 3.5rem; }
  h1 { font-size: 1.5rem; }
  .truncate { max-width: 200px; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ======================================================== edytor wzoru PDF */

.canvas-wrap { max-width: 1040px; }

/* Płótno odwzorowuje obszar zadruku A4 poziomo (778 × 531 pt). */
.canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 778 / 531;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
  background-image:
    linear-gradient(to right, var(--border) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 6.42% 9.42%;
}

.tile {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: .3rem .45rem;
  font-size: .78rem;
  line-height: 1.25;
  color: var(--accent);
  cursor: grab;
  overflow: hidden;
  user-select: none;
}
.tile:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.tile.is-dragging { cursor: grabbing; opacity: .85; z-index: 5; }
.tile.is-hidden { border-style: dashed; opacity: .4; background: transparent; }
.tile.is-right { text-align: right; }
.tile__name { display: block; font-weight: 680; }
.tile__size { display: block; font-size: .7rem; opacity: .75; font-variant-numeric: tabular-nums; }

.tile__grip {
  position: absolute;
  right: 0; bottom: 0;
  width: 14px; height: 14px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 45%, currentColor 45%, currentColor 55%, transparent 55%),
    linear-gradient(135deg, transparent 70%, currentColor 70%, currentColor 80%, transparent 80%);
}
.tile__grip--v { cursor: ns-resize; }

.canvas__table {
  position: absolute;
  left: 0; right: 0;
  border-top: 2px dashed var(--tone-3);
  background: color-mix(in srgb, var(--tone-3) 10%, transparent);
  cursor: ns-resize;
  touch-action: none;
}
.canvas__table-label {
  position: absolute;
  top: 4px; left: 8px;
  font-size: .74rem;
  font-weight: 620;
  color: var(--tone-3);
}

.block-hint { font-size: .82rem; line-height: 1.45; max-width: 46ch; }

.js-col-row { cursor: default; }
.js-col-row.is-dragging { opacity: .5; }
.js-col-handle { cursor: grab; color: var(--text-muted); user-select: none; width: 1.5rem; }
.js-col-row input[type=number] { max-width: 6.5rem; }
.js-col-row input[type=text] { max-width: 12rem; }

.blockcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 1rem; }

.blockcard {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem 1rem;
  background: var(--surface-2);
}
.blockcard__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: .35rem;
}
.blockcard__head .js-block-pos { font-size: .8rem; white-space: nowrap; }
.blockcard .block-hint { margin: 0 0 .7rem; }

/* Pojedyncze dane w bloku - pigułka z polem wyboru. */
.fieldtoggles { display: flex; flex-wrap: wrap; gap: .3rem .5rem; }
.fieldtoggle {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .55rem .2rem .4rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: .84rem;
  cursor: pointer;
  user-select: none;
}
.fieldtoggle:hover { border-color: var(--accent); }
.fieldtoggle input { width: 14px; height: 14px; }
.fieldtoggle:has(input:not(:checked)) { opacity: .5; }
.fieldtoggle:has(input:checked) { border-color: var(--accent); color: var(--accent); }

/* ============================================== dokumentacja w aplikacji */

/* Spis treści obok tekstu na szerokim ekranie, nad nim na wąskim. */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.6rem; }
@media (min-width: 1100px) {
  .doc-layout { grid-template-columns: 220px minmax(0, 1fr); align-items: start; }
  .doc-toc { position: sticky; top: 1rem; }
}

.doc-toc { border-left: 2px solid var(--border); padding-left: .9rem; }
.doc-toc__title {
  margin: 0 0 .5rem;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 720;
  color: var(--text-muted);
}
.doc-toc ol { margin: 0; padding: 0; list-style: none; counter-reset: toc; }
.doc-toc li { counter-increment: toc; margin-bottom: .4rem; font-size: .88rem; line-height: 1.4; }
.doc-toc a { color: var(--text-soft); text-decoration: none; }
.doc-toc a:hover { color: var(--accent); }

/* Sam tekst dokumentu. Miara wiersza ograniczona - długie linijki męczą. */
/* Miara wiersza ogranicza tekst, ale nie zrzuty ekranu - te przy 74ch bylyby
   nieczytelne, bo powstaja w szerokosci 1600 px. */
.doc { max-width: none; font-size: .96rem; line-height: 1.68; color: var(--text); }
.doc p, .doc ul, .doc ol, .doc blockquote, .doc h1, .doc h2, .doc h3 { max-width: 74ch; }
.doc > :first-child { margin-top: 0; }
.doc h1 { font-size: 1.5rem; margin: 0 0 .3rem; }
.doc h2 {
  font-size: 1.16rem;
  margin: 2.4rem 0 .8rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
  /* Kotwica ma się zatrzymać poniżej krawędzi okna, a nie tuż przy niej. */
  scroll-margin-top: 1rem;
}
.doc h3 { font-size: 1rem; margin: 1.7rem 0 .5rem; color: var(--text-soft); scroll-margin-top: 1rem; }
.doc p { margin: 0 0 .9rem; }
.doc ul, .doc ol { margin: 0 0 1rem; padding-left: 1.3rem; }
.doc li { margin-bottom: .35rem; }
.doc hr { display: none; }  /* nagłówki mają już własną kreskę */
.doc code {
  font-family: var(--mono);
  font-size: .87em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .08em .34em;
}
.doc pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  overflow-x: auto;
  margin: 0 0 1rem;
}
.doc pre code { background: none; border: 0; padding: 0; font-size: .85rem; }
.doc blockquote {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-soft);
}
.doc blockquote p:last-child { margin-bottom: 0; }
.doc .table-wrap { margin-bottom: 1.1rem; }
.doc a { color: var(--accent); }

/* Zrzuty ekranu osadzone w instrukcji. */
.doc-fig { margin: 1.4rem 0 1.8rem; max-width: 1100px; }
.doc-fig a { display: block; }
.doc-fig img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.doc-fig figcaption {
  margin-top: .5rem;
  font-size: .84rem;
  color: var(--text-muted);
  text-align: center;
}

/* ================================================= konfigurator ról */

.perm-group { margin-bottom: 1.1rem; }
.perm-group:last-of-type { margin-bottom: .4rem; }
.perm-group__title {
  margin: 0 0 .45rem;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 720;
  color: var(--text-muted);
}
/* Uprawnienie zablokowane do edycji ma być czytelne, ale wyraźnie nieaktywne. */
.fieldtoggle:has(input:disabled) { opacity: .55; cursor: default; border-style: dashed; }
.fieldtoggle:has(input:disabled):hover { border-color: var(--border-strong); }
