:root {
  --topbar-h: 56px;
  --sidebar-w: 260px;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #e1e5eb;
  /* Kolory marki - nadpisywane przez Brand.apply() z ustawień firmy (Ustawienia → Ogólne → Firma). */
  --primary: #0369a1;
  --primary-hover: #035989;
  --primary-soft: #e6f0f6;
  --primary-rgb: 3, 105, 161;
  --topbar-bg: #0a2132;
  --topbar-text: #ffffff;
  --accent: #7dd3fc;
}

* { box-sizing: border-box; }

/* Atrybut hidden zawsze ukrywa element, także gdy jego klasa ustawia display. */
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

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

a { color: var(--primary); }

code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

.muted { color: var(--muted); }

/* ---------- Pasek górny ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  /* Cienka linia w kolorze dodatkowym firmy. */
  box-shadow: inset 0 -3px 0 var(--accent);
  z-index: 20;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--topbar-text);
  text-decoration: none;
  letter-spacing: .3px;
}
.logo em { color: var(--accent); font-style: normal; }
/* Znak firmy ma ciemne elementy, więc w ciemnym pasku stoi na jasnym tle. */
.logo-chip {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  background: #ffffff;
}
.logo-mark { height: 24px; width: auto; display: block; }
.logo-chip-plain { background: none; padding: 0; }
.logo-chip-plain .logo-mark { height: 32px; }

/* ---------- Logo na pulpicie ---------- */

.home-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 4px 0 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.home-brand-logo {
  width: auto;
  max-width: min(440px, 100%);
  max-height: 200px;
  display: block;
}
/* Domyślne logo programu (SVG bez stałej wielkości). */
.home-brand-default { width: min(400px, 100%); }
.home-brand-tagline {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2.4px;
  text-transform: uppercase;
  color: var(--muted);
}
@media (max-width: 600px) {
  .home-brand-tagline { font-size: 10px; letter-spacing: 1.6px; }
}

.user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  font-size: 13px;
}
.user-id { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }

.menu-toggle {
  display: none;
  background: none;
  border: 0;
  color: inherit;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 6px;
}

/* ---------- Układ ---------- */

.layout {
  display: flex;
  padding-top: var(--topbar-h);
  min-height: 100%;
}

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  z-index: 10;
}

.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px 32px;
  min-width: 0;
}

/* ---------- Menu ---------- */

.menu { list-style: none; margin: 0; padding: 0; }
.menu .menu { display: none; padding-left: 14px; }
.menu li.open > .menu { display: block; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  margin: 1px 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu-item:hover { background: var(--bg); }

.menu-level-0 > li > .menu-item { font-weight: 600; }
.menu-level-1 .menu-item,
.menu-level-2 .menu-item { color: #3c4752; }

.menu-icon { width: 20px; text-align: center; }
.menu-label { flex: 1; }

.menu-caret {
  color: var(--muted);
  transition: transform .15s;
}
li.open > .menu-group .menu-caret { transform: rotate(90deg); }

.menu-group.has-active { color: var(--primary); }

li.active > .menu-item {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* ---------- Treść ---------- */

.breadcrumb {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}
.breadcrumb .sep { margin: 0 6px; opacity: .6; }

.page-head h1 {
  margin: 0 0 4px;
  font-size: 22px;
}
.page-head { margin-bottom: 20px; }

.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 32px;
  text-align: center;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 200px));
  justify-content: center;
  gap: 16px;
}
.home-head { text-align: center; }
@media (max-width: 600px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  transition: border-color .15s, box-shadow .15s;
}
.tile:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), .12);
}
.tile-icon { font-size: 30px; }

/* ---------- Mobile ---------- */

@media (max-width: 800px) {
  .menu-toggle { display: block; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s;
    box-shadow: 2px 0 12px rgba(0, 0, 0, .15);
  }
  body.menu-open .sidebar { transform: none; }
  .content { margin-left: 0; padding: 16px; }
  .user-avatar { display: none; }
}

@media (max-width: 480px) {
  /* Na wąskim ekranie w pasku zostaje sam znak; pełna nazwa jest na pulpicie. */
  .logo-text { display: none; }
  .logo-chip { height: 32px; padding: 0 6px; }
  .logo-mark { height: 20px; }
  .topbar { gap: 8px; padding: 0 10px; }
  .user { padding: 5px 9px; font-size: 11px; }
}

/* ---------- Przyciski ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #c4ccd6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: #b91c1c; margin-left: auto; }
.btn-danger:hover { border-color: #b91c1c; background: #fef2f2; }

/* ---------- Lista ---------- */

.page-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.count {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  vertical-align: middle;
}

/* Duże przyciski widoków nad listą (np. Wszyscy / Klienci / Przewoźnicy). */
.view-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: -4px auto 18px;
}
.view-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 0 1 auto;
  min-width: 120px;
  white-space: nowrap;
  min-height: 38px;
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  transition: border-color .15s, background .15s;
}
.view-tab:hover { border-color: var(--primary); }
.view-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), .25);
}
.view-tab-count {
  min-width: 26px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.view-tab.active .view-tab-count { background: rgba(255, 255, 255, .2); color: #fff; }
@media (max-width: 600px) {
  /* Na telefonie przyciski zajmują całą szerokość i w razie potrzeby przechodzą do drugiego rzędu. */
  .view-tabs { gap: 6px; }
  .view-tab { flex: 1 1 auto; min-width: 0; min-height: 36px; padding: 4px 10px; font-size: 13px; gap: 6px; }
  .view-tab-count { min-width: 22px; padding: 1px 6px; font-size: 11px; }
}

.toolbar { margin-bottom: 12px; }
.search {
  width: 100%;
  max-width: 360px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--surface);
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.table th { background: #f9fafb; }
.table th.num, .table td.num { text-align: right; }
.table td.strong { font-weight: 600; }
.table tbody tr[data-id] { cursor: pointer; }
.table tbody tr[data-id]:hover, .table tbody tr[data-id]:focus { background: var(--primary-soft); outline: none; }
.table tbody tr:last-child td { border-bottom: 0; }
.empty-row { text-align: center !important; color: var(--muted); padding: 32px !important; }

.th-sort {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--muted);
  cursor: pointer;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-klient { background: #e0f2fe; color: #075985; }
.badge-przewoznik { background: #fef3c7; color: #92400e; }

/* ---------- Formularz ---------- */

.entity-form { max-width: 960px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px 20px;
  margin-bottom: 16px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 20px;
}
.grid .wide { grid-column: 1 / -1; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.field > span, .field > legend {
  font-size: 13px;
  font-weight: 600;
  color: #3c4752;
  padding: 0;
}
.field > legend { margin-bottom: 5px; }
.req { color: #b91c1c; }

.field input:not([type=checkbox]), .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
.field input:focus, .field textarea:focus, .search:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

.checks { display: flex; gap: 20px; flex-wrap: wrap; padding: 6px 0; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { width: 16px; height: 16px; }

.address { gap: 10px; }
.address-parts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 14px;
}
.address-parts[hidden] { display: none; }
.address-parts > label { font-weight: 400; }
.address-parts > label > span { font-weight: 400; font-size: 12px; color: var(--muted); }

.error { color: #b91c1c; font-size: 12px; min-height: 0; }
.error:empty { display: none; }
.invalid input:not([type=checkbox]), .invalid textarea { border-color: #b91c1c; }

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  padding: 12px 0;
  background: var(--bg);
}

/* ---------- Komunikaty ---------- */

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  color: #fff;
  background: #15803d;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: #b91c1c; }

@media (max-width: 800px) {
  .grid, .address-parts { grid-template-columns: 1fr; }
}

/* ---------- Listy wyboru i powiązania ---------- */

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }

.select, .field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
.toolbar .select { width: auto; max-width: 100%; }
.invalid select { border-color: #b91c1c; }
.field select:focus, .select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

.hint { font-size: 12px; color: var(--muted); }

.badge-adr { background: #ffedd5; color: #9a3412; }

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.related h3 { margin: 0 0 6px; font-size: 13px; }
.related ul { margin: 0 0 8px; padding-left: 18px; }
.related li { margin: 2px 0; }
.add-link { font-size: 13px; font-weight: 600; text-decoration: none; }

/* ---------- Zestawy ---------- */

.btn-sm { padding: 4px 10px; font-size: 13px; }

.zestawy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.zestaw {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.zestaw-differs { border-color: #f59e0b; background: #fffbeb; }
.zestaw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.zestaw-head h3 { margin: 0; font-size: 14px; }
.zestaw dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
}
.zestaw dt { color: var(--muted); }
.zestaw dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.note-warn { color: #b45309; font-size: 12px; margin: 8px 0 0; }
.note-warn:empty { display: none; }
.field .note-warn { margin: 0; }

/* ---------- Okno dialogowe ---------- */

.modal {
  width: min(520px, calc(100% - 32px));
  border: 0;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.modal::backdrop { background: rgba(15, 30, 54, .45); }
.modal h2 { margin: 0 0 4px; font-size: 17px; }
.modal-fields { display: grid; gap: 14px; margin: 16px 0 20px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.modal-actions .spacer { flex: 1; }

/* ---------- Lista z wyszukiwaniem (combo) ---------- */

.combo { position: relative; }
.combo-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
.combo-input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.invalid .combo-input { border-color: #b91c1c; }
.combo-list {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 260px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
}
.combo-list li { padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.combo-list li.active { background: var(--primary-soft); color: var(--primary); }
.combo-list li[aria-selected="true"] { font-weight: 600; }
.combo-list .combo-empty { color: var(--muted); cursor: default; }

/* ---------- Ustawienia ---------- */

.settings { max-width: 720px; margin-inline: auto; }
.settings > .muted { margin: -6px 0 12px; }
/* Ustawienia → Firma: wgrywanie logo i znaku z podglądem. */
.logo-uploads {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin: 16px 0;
}
.logo-upload {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.logo-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  padding: 10px;
  border-radius: 6px;
  background: var(--bg);
  text-align: center;
  font-size: 12px;
}
.logo-preview img { max-width: 100%; max-height: 96px; display: block; }
.brand-colors {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.brand-colors > .muted { margin: 0; }
.brand-colors-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; }
.color-field { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.color-field span { display: grid; }
.color-field input[type=color] {
  width: 46px;
  height: 46px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.brand-colors-row .head-actions { margin-left: auto; }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.switch-text { display: flex; flex-direction: column; gap: 2px; }
.switch { position: relative; flex: none; width: 44px; height: 24px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd2da;
  transition: background .15s;
  pointer-events: none;
}
.switch-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: transform .15s;
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--primary); outline-offset: 2px; }

.currency-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px 16px;
}
.currency .muted { font-size: 12px; }

.modal-wide { width: min(860px, calc(100% - 32px)); background: var(--bg); }
.modal-wide .entity-form { max-width: none; }
.modal-wide .form-actions { position: static; }
.dialog-title { margin: 0 0 14px; font-size: 18px; }

/* ---------- Ładunki ---------- */

.banner {
  margin: 8px 0 0;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
}
.hint-link { font-size: 12px; font-weight: 600; text-decoration: none; }
.price-row { display: flex; gap: 8px; }
.price-row input { flex: 1; min-width: 0; }
.price-row select { width: auto; flex: none; }

.with-action { display: flex; gap: 8px; align-items: flex-start; }
.with-action .combo { flex: 1; min-width: 0; }
.btn-icon { padding: 6px 10px; line-height: 1; }
.btn:disabled { opacity: .4; cursor: default; }
.link-btn {
  border: 0;
  background: none;
  padding: 4px 0;
  color: var(--primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.points { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.point {
  border: 1px solid var(--border);
  border-left: 4px solid #0ea5e9;
  border-radius: 8px;
  padding: 12px 14px 14px;
  background: #fff;
}
.point-rozladunek { border-left-color: #f59e0b; }
.point.dragging { opacity: .5; }
.point.drop-target { outline: 2px dashed var(--primary); outline-offset: 2px; }
.point-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.point-head .spacer { flex: 1; }
.point-no { font-weight: 700; color: var(--muted); }
.point-type { width: auto; font-weight: 600; }
.drag-handle { cursor: grab; color: var(--muted); letter-spacing: -2px; user-select: none; padding: 0 2px; }
.point-place { margin: 0 0 4px; font-weight: 600; }
.point-readonly p { margin: 2px 0; }
.point-readonly .table-wrap { margin-top: 10px; }

.goods { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.goods h3 { margin: 0 0 8px; font-size: 13px; }
.goods-line {
  display: grid;
  grid-template-columns: 2fr .8fr 1fr 1.6fr auto 1.2fr 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid #f0f2f5;
}
.goods-line .field > span { font-size: 12px; font-weight: 400; color: var(--muted); }
.goods-line .check { padding-top: 8px; }
.goods-remove { margin-top: 22px; }
.route-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.badge-zaladunek { background: #e0f2fe; color: #075985; }
.badge-rozladunek { background: #fef3c7; color: #92400e; }
.badge-status { background: #dbeafe; color: #1e40af; font-size: 12px; vertical-align: middle; }
.badge-done { background: #dcfce7; color: #166534; font-size: 12px; vertical-align: middle; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.table-compact th, .table-compact td { padding: 6px 10px; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 1100px) {
  .goods-line { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .goods-line > .field:first-child { grid-column: 1 / -1; }
  .goods-remove { margin-top: 0; justify-self: start; }
}
@media (max-width: 800px) {
  .goods-line { grid-template-columns: 1fr; }
  .details { grid-template-columns: 1fr; }
  .details dd { margin-bottom: 6px; }
}

/* ---------- Plan załadunków ---------- */

.plan-day { margin-bottom: 20px; }
.plan-day h2 { font-size: 15px; margin: 0 0 8px; }
.plan-today h2 { color: var(--primary); }
.plan-past { opacity: .65; }
.plan-table td { vertical-align: top; }
.plan-table td.wrap { white-space: normal; min-width: 180px; }

.plan-table .muted { font-size: 12px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-head .dialog-title { margin: 0; }
.modal-wide .modal-actions { margin-top: 4px; }
/* Jednakowe kolumny we wszystkich dniach planu. */
.plan-table { table-layout: fixed; min-width: 960px; }
.plan-table th, .plan-table td { white-space: normal; overflow-wrap: anywhere; }
.plan-table th:nth-child(1) { width: 70px; }
.plan-table th:nth-child(2) { width: 150px; }
.plan-table th:nth-child(3) { width: 26%; }
.plan-table th:nth-child(5) { width: 12%; }
.plan-table th:nth-child(6) { width: 130px; }
.plan-table th:nth-child(7) { width: 120px; }

/* ---------- Wykonawca zlecenia ---------- */

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.with-action select { flex: 1; min-width: 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 14px; background: #fff; }
.segmented label { padding: 8px 16px; cursor: pointer; font-weight: 600; }
.segmented label + label { border-left: 1px solid var(--border); }
.segmented label.active { background: var(--primary); color: #fff; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.margin { margin: 6px 0 0; font-weight: 700; color: #15803d; }
.margin-neg { color: #b91c1c; font-weight: 700; }
.modal-wide .card { margin-bottom: 12px; }

/* Kolumny planu z wykonawcą. */
.plan-table th:nth-child(3) { width: 22%; }
.plan-table th:nth-child(5) { width: 10%; }
.plan-table th:nth-child(6) { width: 16%; }
.plan-table th:nth-child(7) { width: 120px; }
.plan-table th:nth-child(8) { width: 110px; }

@media (max-width: 800px) {
  .grid-3 { grid-template-columns: 1fr; }
}

/* ---------- Tabela zestawów (okno wykonawcy) ---------- */

.sets-table td { vertical-align: middle; }
.sets-table td:first-child, .sets-table th:first-child { width: 36px; padding-right: 0; }
.set-row { cursor: pointer; }
.set-row:hover { background: #f9fafb; }
.set-row.selected { background: var(--primary-soft); }
.set-row.selected td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.set-busy { cursor: not-allowed; color: #9aa4af; background: #f6f7f9; }
.set-busy:hover { background: #f6f7f9; }
.set-busy a, .set-busy .badge { opacity: .6; }
.set-notes { white-space: normal !important; font-size: 12px; color: var(--muted); min-width: 160px; }
.set-warn .set-notes { color: #b45309; }
.set-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}
.set-status-ok { background: #dcfce7; color: #15803d; }
.set-status-warn { background: #fef3c7; color: #b45309; }
.set-status-busy { background: #eceef1; color: #6b7785; }
.set-legend .set-status { width: 18px; height: 18px; font-size: 11px; }
.manual { margin-top: 12px; }
.manual summary { cursor: pointer; font-weight: 600; color: var(--primary); margin-bottom: 10px; }
.default-currency { max-width: 320px; margin-bottom: 16px; }

/* ---------- Pole czasu ---------- */

.time-field { display: flex; align-items: center; gap: 4px; }
.time-field .time-part {
  width: 64px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  text-align: center;
  background: #fff;
}
.time-field .time-part:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.invalid .time-part { border-color: #b91c1c; }

/* ---------- Rozładunek: towary z załadunków powyżej ---------- */

.inherit-toggle { margin-bottom: 8px; font-weight: 600; }
.inherited-goods { margin: 0; padding: 8px 12px 8px 28px; background: #f9fafb; border-radius: 6px; }
.inherited-goods li { margin: 2px 0; }

/* ---------- Pomoc ---------- */

.help-btn {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .55);
  background: transparent;
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  flex: none;
}
.help-btn:hover, .help-btn:focus-visible { background: rgba(255, 255, 255, .15); border-color: #fff; }
.help-btn + .user { margin-left: 0; }
.help-btn-sm {
  margin-left: 6px;
  width: 22px;
  height: 22px;
  font-size: 13px;
  border: 1.5px solid var(--primary);
  color: var(--primary);
  vertical-align: middle;
}
.help-btn-sm:hover, .help-btn-sm:focus-visible { background: var(--primary-soft); border-color: var(--primary); }
.help-modal { width: min(640px, calc(100% - 32px)); }
.help-intro { font-size: 15px; margin: 0 0 12px; }
.help-list { margin: 0 0 16px; padding-left: 20px; line-height: 1.55; }
.help-list li { margin-bottom: 8px; }
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  margin-right: 4px;
}
.field .time-field .time-part { width: 72px; flex: none; }

/* ---------- Edycja zestawów ---------- */

.zestaw h3 { margin: 0 0 8px; font-size: 14px; }
.zestaw dd .badge { margin-left: 4px; }
.table-title { margin: 14px 0 6px; font-size: 14px; }
.zestaw-summary { margin: 0 0 6px; padding: 8px 12px; background: var(--primary-soft); border-radius: 6px; }
.badge-expired { background: #fee2e2; color: #b91c1c; text-decoration: line-through; }

.badge-test { background: #ede9fe; color: #6d28d9; font-size: 11px; letter-spacing: .3px; }

/* ---------- Wybór języka ---------- */

.lang-select {
  margin-left: auto;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 6px;
  padding: 5px 6px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.lang-select option { color: #000; }
/* Ukryty wybór języka (sam polski) nie zabiera pomocy i sesji z prawej strony. */
.lang-select:not([hidden]) + .help-btn { margin-left: 0; }
/* Długie słowa (np. niemieckie) w nagłówkach dzielone poprawnie; numery zleceń bez łamania. */
.plan-table th { overflow-wrap: normal; hyphens: auto; }
.plan-table th:nth-child(7) { width: 130px; }
.plan-table th:nth-child(8) { width: 120px; }
.plan-table td:nth-child(7) .link-btn, .plan-table td:nth-child(7) .muted { white-space: nowrap; }
.table th { hyphens: auto; }
.plan-table th, .plan-table td { overflow-wrap: break-word; }
.plan-table th:nth-child(3) { width: 20%; }
.plan-table th:nth-child(4) { width: 14%; }
.plan-table th:nth-child(8) { width: 140px; }

/* ---------- Wydruk zlecenia (A4) ---------- */

.doc-lang { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.doc-wrap {
  max-width: 820px;
  margin: 16px auto 0;
  padding: 36px 40px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, .08);
}
.doc { font-size: 12.5px; line-height: 1.45; color: #111827; }
.doc h1 { font-size: 22px; margin: 0 0 4px; text-transform: uppercase; letter-spacing: .04em; }
.doc h3 {
  font-size: 11px;
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #4b5563;
}
.doc p { margin: 0; }
.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--primary);
}
.doc-logo { max-height: 64px; max-width: 260px; display: block; }
.doc-title { text-align: right; }
.doc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.doc-box { border: 1px solid #d1d5db; border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; }
.doc-grid .doc-box { margin-bottom: 0; }
.doc-dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 0; }
.doc-dl dt { color: #4b5563; }
.doc-dl dd { margin: 0; font-weight: 600; }
.doc-amount { font-size: 16px; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.doc-table th, .doc-table td { border: 1px solid #d1d5db; padding: 6px 7px; text-align: left; vertical-align: top; }
.doc-table th { background: #f3f4f6; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #374151; }
.doc-table hr { border: 0; border-top: 1px dashed #d1d5db; margin: 4px 0; }
.doc-num { width: 28px; text-align: center !important; font-weight: 700; }
.doc-terms { border-top: 1px solid #d1d5db; padding-top: 10px; margin-top: 4px; font-size: 11.5px; }
.doc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 48px; font-size: 11px; color: #4b5563; text-align: center; }
.doc-sign span { display: block; border-top: 1px solid #6b7280; margin-bottom: 4px; }
@media (max-width: 700px) {
  .doc-wrap { padding: 18px 14px; }
  .doc-grid { grid-template-columns: 1fr; }
  .doc-table { font-size: 11px; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .topbar, .sidebar, .no-print, .toast, #toast { display: none !important; }
  .content { margin: 0 !important; padding: 0 !important; }
  .doc-wrap { max-width: none; margin: 0; padding: 0; border: 0; box-shadow: none; }
  .doc-box, .doc-table tr, .doc-sign { break-inside: avoid; }
  .doc-head { border-bottom-color: #111827; }
}

/* ---------- Wspólna baza (PocketBase): logowanie i stan połączenia ---------- */

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(160deg, var(--topbar-bg), var(--primary));
}
.login-card {
  width: min(400px, 100%);
  display: grid;
  gap: 12px;
  padding: 28px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
  text-align: left;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-logo { max-height: 72px; max-width: 100%; justify-self: center; margin-bottom: 4px; }
.login-error { color: #b91c1c; font-size: 13px; }
.login-card .btn { justify-content: center; }
.login-card .btn-link {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}
.sync-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.sync-ok { background: #22c55e; }
.sync-saving { background: #f59e0b; }
.sync-offline { background: #ef4444; }
.user-logout {
  display: inline-flex;
  border: 0;
  background: none;
  color: inherit;
  font-size: 15px;
  line-height: 1;
  padding: 0 0 0 2px;
  cursor: pointer;
  opacity: .8;
}
.user-logout:hover { opacity: 1; }
.data-mode input[type=radio] { width: 20px; height: 20px; flex: none; accent-color: var(--primary); }
#dataForm .field { margin: 12px 0; }

/* Blokada edycji (wspólna baza): wpis edytowany przez inną osobę - tylko podgląd. */
.lock-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid #f59e0b;
  border-left-width: 5px;
  border-radius: 8px;
  background: #fffbeb;
}
.lock-banner p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.lock-banner .btn { margin-left: auto; flex: none; }
.lock-icon { font-size: 22px; }
.is-locked input, .is-locked select, .is-locked textarea { background: var(--bg); cursor: not-allowed; }
@media (max-width: 600px) { .lock-banner { flex-wrap: wrap; } .lock-banner .btn { margin-left: 0; } }

/* ---------- Faktury ---------- */

.badge-draft { background: #f3f4f6; color: #374151; font-size: 12px; vertical-align: middle; }
.badge-overdue { background: #fee2e2; color: #b91c1c; font-size: 12px; vertical-align: middle; }

/* Nowa faktura: wybór rodzaju. */
.choice-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; max-width: 900px; }
.choice-card {
  display: flex; flex-direction: column; gap: 6px; padding: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s;
}
.choice-card:hover, .choice-card:focus-visible { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); outline: none; }
.choice-card strong { font-size: 16px; }
.choice-icon { font-size: 28px; line-height: 1; }
@media (max-width: 760px) { .choice-cards { grid-template-columns: 1fr; } }

/* Wybór ładunków do faktury. */
.pick-table td { vertical-align: top; }
.pick-table tr.selected { background: var(--primary-soft); }
.pick-table tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.pick-table tr.is-blocked { opacity: .45; cursor: not-allowed !important; }
.pick-table input[type=checkbox], .pick-table input[type=radio] { width: 18px; height: 18px; accent-color: var(--primary); }
.pick-bar {
  position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 14px;
  margin-top: 12px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}

/* Ekran faktury: dwie kolumny jak w programach księgowych. */
.invoice-form { max-width: none; }
.invoice-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); gap: 16px; align-items: start; }
.invoice-grid .grid .wide-2 { grid-column: span 2; }
.field-links { margin: 0; padding: 7px 0; line-height: 1.5; }
.lines-table td { vertical-align: middle; padding: 6px 8px; }
.lines-table input, .lines-table select { width: 100%; min-width: 0; padding: 5px 7px; font: inherit; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.lines-table .line-name { min-width: 260px; }
.lines-table .line-num { width: 96px; text-align: right; }
.lines-table .line-unit { width: 64px; }
.lines-table .line-vat { width: 76px; }
.lines-table input:disabled, .lines-table select:disabled { background: transparent; border-color: transparent; color: inherit; }
.vat-summary { display: flex; justify-content: flex-end; margin-top: 12px; }
.vat-table { width: auto; min-width: 360px; border: 1px solid var(--border); border-radius: 8px; }
.vat-table tr.total td, .doc-table tr.total td { font-weight: 700; }
.vat-pln { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.vat-pln h3, .parties h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); }
.vat-pln p { margin: 0 0 10px; font-size: 13px; }
.parties { display: grid; gap: 16px; }
.parties p { margin: 6px 0 0; line-height: 1.5; }
.activity { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.activity li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity li:last-child { border-bottom: 0; }
.activity .muted { font-size: 12px; }
@media (max-width: 1100px) { .invoice-grid { grid-template-columns: 1fr; } }

/* Wydruk faktury. */
.doc-draft { margin: 0 0 12px; padding: 6px 10px; border: 1px dashed #b45309; color: #b45309; text-align: center; font-weight: 600; }
.doc-vat { margin-bottom: 8px; }
.doc-small { font-size: 11px; color: #4b5563; margin: 6px 0 0; }
.invoice-doc .doc-table td.num { white-space: nowrap; }
.invoice-doc .doc-table td.num { text-align: right; }
.payments-table th, .payments-table td { white-space: normal; padding: 7px 9px; font-size: 13px; }
.lines-table td:nth-child(3) { width: 45%; }
.invoice-doc .doc-table th { white-space: normal; }
.invoice-doc .doc-table td:nth-child(2) { width: 34%; }
.invoice-doc .doc-iban { white-space: nowrap; }
@media (min-width: 701px) { .invoice-doc .doc-grid { grid-template-columns: 1.15fr 1fr; } }
.payments-table td.num, .payments-table .badge { white-space: nowrap; }

/* Faktury: odwrotne obciążenie, zestawienie w PLN, płatność w dwóch walutach. */
.reverse-charge, .doc-reverse { margin: 0 0 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; color: #92400e; }
.vat-summary { flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.sum-title { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); }
.fx-line { margin: 6px 0 0; font-size: 13px; }
.vat-split { display: flex; gap: 8px; align-items: flex-start; margin: 14px 0 10px; font-size: 14px; }
.vat-split input { margin-top: 3px; }
.doc-grid-3 { grid-template-columns: 1fr 1fr 1fr !important; }
.doc-sums { display: flex; flex-direction: column; align-items: flex-end; margin-bottom: 12px; }
.doc-sums .doc-table { width: auto; min-width: 60%; margin-bottom: 4px; }
.doc-sums .doc-small { align-self: flex-end; margin: 6px 0 4px; }
.doc-pay { border: 1px solid #d1d5db; border-radius: 6px; margin-bottom: 12px; }
.doc-pay-head { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; background: #f3f4f6; border-bottom: 1px solid #d1d5db; }
.doc-pay-amount { background: #fff; font-size: 14px; }
.doc-pay-amount b { font-size: 15px; }
.doc-pay-line { margin: 0; padding: 5px 10px; border-bottom: 1px solid #e5e7eb; font-size: 11.5px; }
.doc-pay-line:last-child { border-bottom: 0; }
@media (max-width: 700px) { .doc-grid-3 { grid-template-columns: 1fr !important; } .doc-sums .doc-table { min-width: 0; width: 100%; } }
.fx-info { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.fx-info p { margin: 0; font-size: 14px; line-height: 1.6; }
.nota-doc .doc-table td:nth-child(2) { width: auto; }
.nota-doc .doc-table th:last-child, .nota-doc .doc-table td:last-child { width: 22%; text-align: right; }
