:root {
  --page-bg: #f9f9f7;
  --surface-1: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --brand-red: #ED1E28;
  --brand-blue: #17479B;
  --series-blue: #2a78d6;
  --series-orange: #eb6834;
  --series-aqua: #1baf7a;
  --series-yellow: #eda100;
  --status-good: #0ca30c;
  --status-critical: #d03b3b;
  --status-warning: #b97300;
  --radius: 10px;
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  font-size: 14px;
}

a { color: inherit; }

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

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #ffffff;
  border-right: 1px solid var(--gridline);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--gridline);
}

.sidebar-brand img { height: 34px; width: auto; }

.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
}

.sidebar-user {
  padding: 12px 16px;
  font-size: 12.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--gridline);
}

.sidebar-user strong { color: var(--text-primary); display: block; font-size: 13.5px; }

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 10px 8px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav li { margin-bottom: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover { background: #f2f4f8; color: var(--text-primary); }

.nav-link.active {
  background: var(--brand-blue);
  color: #ffffff;
}

.nav-link.disabled {
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

.badge-soon {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--gridline);
  color: var(--text-secondary);
  padding: 2px 6px;
  border-radius: 999px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--gridline);
}

.logout-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--brand-red);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}

/* ---------- Main content ---------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 32px 60px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: 22px;
  margin: 0;
}

.page-header p.subtitle {
  color: var(--text-secondary);
  margin: 4px 0 0;
  font-size: 13px;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card h2, .card h3 {
  margin-top: 0;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

@media (max-width: 1100px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ---------- Stat tiles ---------- */

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-tile .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.stat-tile .stat-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.stat-tile.accent-blue .stat-value { color: var(--series-blue); }
.stat-tile.accent-orange .stat-value { color: var(--series-orange); }
.stat-tile.accent-aqua .stat-value { color: var(--series-aqua); }
.stat-tile.accent-yellow .stat-value { color: #a3720b; }

/* ---------- Filters ---------- */

.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.filter-field { display: flex; flex-direction: column; gap: 4px; }
.filter-field label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }

select, input[type="text"], input[type="number"], input[type="date"], input[type="month"], input[type="password"] {
  font-family: inherit;
  font-size: 13.5px;
  padding: 7px 10px;
  border: 1px solid var(--gridline);
  border-radius: 7px;
  background: #fff;
  color: var(--text-primary);
}

select:focus, input:focus { outline: 2px solid var(--brand-blue); outline-offset: 1px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--gridline);
  background: #fff;
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: #f2f4f8; }

.btn-primary { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.btn-primary:hover { background: #123a80; }

.btn-danger { background: #fff; border-color: var(--status-critical); color: var(--status-critical); }
.btn-danger:hover { background: #fdeceb; }

.btn-success { background: var(--status-good); border-color: var(--status-good); color: #fff; }
.btn-success:hover { background: #08890c; }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Tables ---------- */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

/* table-layout:fixed tylko dla tabeli Kosztow (ma zdefiniowane szerokosci
   kolumn ponizej) - inne tabele (Uzytkownicy, Klienci, Towary...) zostaja
   przy domyslnym auto-layout, zeby nie zmienic ich wygladu. */
#koszty-table { table-layout: fixed; }

table.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--gridline);
  padding: 6px 7px;
  white-space: normal;
}

table.data-table td {
  padding: 6px 7px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: middle;
  overflow-wrap: break-word;
}

table.data-table tbody tr:hover { background: #f7f8fa; }

.num { text-align: right; font-variant-numeric: tabular-nums; }

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

/* Tabela Kosztow ma sporo kolumn (14) - zeby zmiescila sie na ekranie bez
   przewijania w bok i BEZ zmniejszania czcionki, kolumny z dlugim tekstem
   (klient/adres/odbiorca/magazyn/opis) zawijaja sie zamiast rozpychac tabele
   w szerokosc; table-layout: fixed powyzej rozklada szerokosc wg ponizszych
   proporcji zamiast wg naturalnej szerokosci tresci. Na waskich oknach
   przegladarki tabela nadal moze wymagac przewiniecia (.table-wrap) - to
   nieuniknione przy tylu kolumnach bez zmniejszania liter, ale na typowym
   ekranie laptopa/desktopu powinna miescic sie w calosci. */
#koszty-table th:nth-child(1), #koszty-table td:nth-child(1) { width: 6%; }
#koszty-table th:nth-child(2), #koszty-table td:nth-child(2) { width: 6%; }
#koszty-table th:nth-child(3), #koszty-table td:nth-child(3) { width: 7%; }
#koszty-table th:nth-child(4), #koszty-table td:nth-child(4) { width: 8%; }
#koszty-table th:nth-child(5), #koszty-table td:nth-child(5) { width: 9%; }
#koszty-table th:nth-child(6), #koszty-table td:nth-child(6) { width: 7%; }
#koszty-table th:nth-child(7), #koszty-table td:nth-child(7) { width: 7%; }
#koszty-table th:nth-child(8), #koszty-table td:nth-child(8) { width: 7%; }
#koszty-table th:nth-child(9), #koszty-table td:nth-child(9) { width: 7%; }
#koszty-table th:nth-child(10), #koszty-table td:nth-child(10) { width: 7%; }
#koszty-table th:nth-child(11), #koszty-table td:nth-child(11) { width: 8%; }
#koszty-table th:nth-child(12), #koszty-table td:nth-child(12) { width: 6%; }
#koszty-table th:nth-child(13), #koszty-table td:nth-child(13) { width: 7%; }
#koszty-table th:nth-child(14), #koszty-table td:nth-child(14) { width: 8%; }

#koszty-table td:nth-child(4),
#koszty-table td:nth-child(5),
#koszty-table td:nth-child(6),
#koszty-table td:nth-child(7) {
  word-break: break-word;
}

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

.pill-good { background: #e6f7e6; color: var(--status-good); }
.pill-pending { background: #fdf1de; color: var(--status-warning); }

.input-inline {
  width: 100%;
  min-width: 0;
  padding: 5px 7px;
  font-size: 12.5px;
}

/* ---------- Empty / placeholder ---------- */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state .icon { font-size: 40px; margin-bottom: 10px; }

/* ---------- Login page ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #f9f9f7 0%, #eef1f6 100%);
}

.login-card {
  background: #fff;
  border: 1px solid var(--gridline);
  border-radius: 14px;
  padding: 36px 34px;
  width: 360px;
  box-shadow: 0 10px 30px rgba(11,11,11,0.06);
}

.login-card img { display: block; margin: 0 auto 18px; height: 70px; }

.login-card h1 { text-align: center; font-size: 18px; margin: 0 0 22px; }

.login-field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
.login-field label { font-size: 12px; color: var(--text-secondary); }
.login-field select, .login-field input { width: 100%; padding: 9px 10px; }

.flash {
  background: #fdeceb;
  color: var(--status-critical);
  border: 1px solid #f6c8c5;
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 13px;
  margin-bottom: 14px;
}

.login-submit { width: 100%; margin-top: 6px; justify-content: center; }

/* ---------- Szafa: kanban ---------- */

.zone-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 14px;
}

.zone {
  background: #fbfbfa;
  border: 1px dashed var(--gridline);
  border-radius: var(--radius);
  min-height: 220px;
  padding: 10px;
}

.zone-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

.zone.drag-over { border-color: var(--brand-blue); background: #eef4ff; }

.towar-card {
  background: #fff;
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  cursor: grab;
  font-size: 12.5px;
}

.towar-card:active { cursor: grabbing; }
.towar-card.sortable-ghost { opacity: 0.4; }

.towar-card .tc-nazwa { font-weight: 600; }
.towar-card .tc-indeks { color: var(--text-muted); font-size: 11px; }
.towar-card .tc-qty { margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--brand-blue); font-weight: 700; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(11,11,11,0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

.modal-box {
  background: #fff; border-radius: 12px; padding: 22px 24px;
  width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}

.modal-box h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.hidden { display: none !important; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--gridline); }
.tab-btn {
  background: none; border: none; padding: 10px 14px; font-size: 13.5px; font-weight: 600;
  color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--brand-blue); border-bottom-color: var(--brand-blue); }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text-primary); color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.toast.error { background: var(--status-critical); }
