:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --text: #16202e;
  --muted: #6b7684;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --border: #e3e7ee;
  --border-strong: #d3d9e3;
  --ok: #067647;
  --ok-bg: #e7f7ee;
  --warn: #b54708;
  --warn-bg: #fef4e2;
  --err: #b42318;
  --err-bg: #fdECEA;
  --row-alt: #f7f9fc;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 4px 12px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== Nawigacja ===== */
nav {
  display: flex; align-items: center; gap: 1.1rem;
  background: #0d1524; padding: .7rem 1.5rem; flex-wrap: wrap;
  box-shadow: var(--shadow);
}
nav a { color: #b8c2d1; text-decoration: none; font-weight: 500; font-size: .92rem; transition: color .12s; }
nav a:hover { color: #fff; }
nav .brand { display: flex; align-items: center; gap: .55rem; margin-right: .4rem; }
nav .brand img { height: 30px; width: auto; display: block; }
nav .brand .brand-app {
  color: #fff; font-weight: 700; font-size: .95rem; letter-spacing: .06em;
  text-transform: uppercase; border-left: 1px solid #33415e; padding-left: .55rem;
}
nav .spacer { flex: 1; }

main { max-width: 1720px; margin: 1.6rem auto; padding: 0 1.4rem; }
h1 { font-size: 1.5rem; margin: 0 0 1.2rem; letter-spacing: -.02em; }
h2 { font-size: 1.02rem; margin: 0 0 .9rem; letter-spacing: -.01em; }

/* ===== Karty ===== */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.3rem 1.4rem; margin-bottom: 1.3rem;
  box-shadow: var(--shadow);
}

/* ===== Kafelki statystyk ===== */
.grid { display: grid; gap: 1rem; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); }
.stat {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.1rem 1.3rem; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent); opacity: .85;
}
.stat.ok::before { background: var(--ok); }
.stat.warn::before { background: var(--warn); }
.stat.err::before { background: var(--err); }
.stat .num { font-size: 1.75rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: .82rem; margin-top: .15rem; }

/* ===== Tabele ===== */
.table-wrap {
  overflow: auto; max-height: 76vh;
  border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f4f6fa; color: #55606f;
  font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .045em;
  text-align: left; padding: .8rem .95rem; white-space: nowrap;
  border-bottom: 2px solid var(--border-strong);
  user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--accent); background: #eef2f9; }
th.sort-asc::after { content: " ▲"; font-size: .62rem; color: var(--accent); }
th.sort-desc::after { content: " ▼"; font-size: .62rem; color: var(--accent); }
tbody td {
  padding: .78rem .95rem; border-bottom: 1px solid var(--border);
  vertical-align: middle; font-size: .95rem; line-height: 1.45;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) td { background: var(--row-alt); }
tbody tr:hover td { background: var(--accent-soft); }
.right { text-align: right; }
.num-cell {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
  font-feature-settings: "tnum"; font-weight: 570; color: #101a29;
}
td.date-cell { white-space: nowrap; color: #4a5665; font-variant-numeric: tabular-nums; }
td.clip { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.total-row td { background: #0d1524 !important; color: #fff; font-weight: 700; font-size: .95rem; border: 0; }
tr.year-row td { background: #e9edf4 !important; border-top: 2px solid var(--border-strong); }
tr.mc-active td { background: var(--accent-soft) !important; box-shadow: inset 3px 0 0 var(--accent); }
.total-row td:first-child { border-radius: 0 0 0 10px; }
.total-row td:last-child { border-radius: 0 0 10px 0; }

/* Zagnieżdżona tabela pozycji faktury */
tr.items-row > td { background: #eef2f8 !important; padding: .45rem .7rem .8rem 2.4rem; }
table.items { border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; box-shadow: none; margin: .2rem 0; }
table.items thead th { background: #e6ebf3; font-size: .68rem; padding: .5rem .7rem; position: static; }
table.items td { padding: .5rem .7rem; font-size: .86rem; }
table.items tbody tr:hover td { background: #fff; }

/* ===== Pigułki / badge ===== */
.badge {
  display: inline-block; padding: .2rem .6rem; border-radius: 99px;
  font-size: .74rem; font-weight: 650; white-space: nowrap; line-height: 1.3;
}
.badge.s-DoOpracowania { background: var(--warn-bg); color: var(--warn); }
.badge.s-PRZENIESIONO { background: var(--ok-bg); color: var(--ok); }
.badge.s-PRZETWARZANIE { background: var(--accent-soft); color: var(--accent); }
.badge.s-DUPLIKAT, .badge.s-BŁĄD { background: var(--err-bg); color: var(--err); }
.badge.s-NIEREJESTRUJEMY { background: #eef0f3; color: var(--muted); }
.badge.cat { background: #edf1f7; color: #3a4657; border: 1px solid #e0e6ee; }

/* ===== Przyciski / linki / formularze ===== */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
tbody td a { font-weight: 600; }
button, .btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: .5rem 1.05rem; font-size: .9rem; font-weight: 650; cursor: pointer;
  text-decoration: none; display: inline-block; transition: filter .12s, box-shadow .12s;
}
button:hover, .btn:hover { filter: brightness(1.07); text-decoration: none; box-shadow: var(--shadow); }
button.secondary, .btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border-strong); }
button.secondary:hover, .btn.secondary:hover { background: #f7f9fc; }
button.danger { background: var(--err); }
button:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }
form.filters { display: flex; gap: .55rem; flex-wrap: wrap; margin-bottom: 1.1rem; align-items: center; }
form.filters input, form.filters select { width: auto; }
input, select, textarea {
  border: 1px solid var(--border-strong); border-radius: 9px; padding: .5rem .7rem;
  font-size: .9rem; font-family: inherit; background: #fff; width: 100%; color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
label { display: block; font-size: .78rem; font-weight: 650; color: var(--muted); margin: .7rem 0 .25rem; }
.muted { color: var(--muted); font-size: .85rem; }

button.toggle {
  background: none; border: 1px solid var(--border-strong); border-radius: 7px;
  color: var(--accent); font-size: .8rem; padding: .1rem .4rem; cursor: pointer; line-height: 1;
}
button.toggle:hover { background: var(--accent-soft); filter: none; box-shadow: none; }
select.assign { max-width: 230px; }
/* Naprzemienne tła pozycji w listach rozwijanych inwestycji */
select.striped option:nth-child(odd) { background: #ffffff; }
select.striped option:nth-child(even) { background: #e9edf4; }
select.striped option { padding: .3rem .5rem; }

/* ===== Kolory inwestycji ===== */
.dot {
  display: inline-block; width: .72rem; height: .72rem; border-radius: 50%;
  vertical-align: baseline; margin-right: .35rem;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.dot.lg { width: 1rem; height: 1rem; margin-right: .15rem; }
input[type="color"] {
  width: 3.2rem; height: 2.2rem; padding: .15rem; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 8px; background: #fff;
}
.color-pick input[type="color"] { margin: 0; }
.color-row { display: flex; align-items: center; gap: .7rem; }
.swatches { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .5rem; }
.swatch {
  width: 1.55rem; height: 1.55rem; border-radius: 6px; border: 1px solid rgba(0,0,0,.15);
  cursor: pointer; padding: 0;
}
.swatch:hover { transform: scale(1.15); box-shadow: var(--shadow); filter: none; }

/* ===== Chipy filtrów kategorii ===== */
.chip {
  display: inline-block; padding: .3rem .85rem; border-radius: 99px;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  font-size: .84rem; font-weight: 600; text-decoration: none;
}
.chip:hover { background: var(--accent-soft); text-decoration: none; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== Paginacja ===== */
.pagination { display: flex; gap: .4rem; margin-top: 1.1rem; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: .35rem .75rem; border: 1px solid var(--border-strong); border-radius: 8px;
  text-decoration: none; background: #fff; font-size: .88rem; font-weight: 600;
}
.pagination a:hover { background: var(--accent-soft); text-decoration: none; }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== Komunikaty ===== */
.error { background: var(--err-bg); color: var(--err); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid #f4cfcb; }
.success { background: var(--ok-bg); color: var(--ok); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid #c4ecd3; }
.login-box { max-width: 400px; margin: 9vh auto; }
iframe.preview { width: 100%; height: 76vh; border: 1px solid var(--border); border-radius: 12px; background: #fff; }

/* ===== Strefa uploadu ===== */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: 14px; padding: 3rem 1rem;
  text-align: center; color: var(--muted); background: var(--card); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 700px) {
  thead th, tbody td { padding: .45rem .5rem; font-size: .82rem; }
  h1 { font-size: 1.25rem; }
}
