:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1c2330;
  --muted: #667085;
  --line: #e2e5ea;
  --accent: #1f5fbf;
  --accent-soft: #e8effa;
  --ok: #1a7f4b;
  --ok-soft: #e6f4ec;
  --warn: #a15c00;
  --warn-soft: #fdf1df;
  --err: #b42318;
  --err-soft: #fdeceb;
  --sent: #eef0f3;
  --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 52px; background: #17202e; color: #fff; }
.brand { font-weight: 600; letter-spacing: .2px; }
.topbar nav { display: flex; gap: 4px; align-items: center; flex: 1; }
.topbar nav a, .topbar nav .link { color: #c9d2e0; padding: 7px 12px; border-radius: 6px; font-size: 13.5px; }
.topbar nav a:hover, .topbar nav .link:hover { background: #253247; color: #fff; text-decoration: none; }
.topbar nav a.active { background: #2b3a52; color: #fff; }
.topbar nav .link { background: none; border: 0; cursor: pointer; font: inherit; }
.online { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: #c9d2e0; }
.online .who { display: inline-flex; align-items: center; gap: 5px; background: #222d3f; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.online .who::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #3ccf8e; }
.online .who.self { background: #2b3a52; color: #fff; }
.topbar .me { background: #2b3a52; color: #fff; border: 0; font-size: 13px; padding: 6px 11px; }
.topbar .me:hover { background: #34476a; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c5ccd6; margin-right: 6px; }
.dot.on { background: var(--ok); }

main { padding: 20px; max-width: 1800px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: #c4cad3; background: #fafbfc; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1a51a3; }
button.danger { color: var(--err); }
button.ghost { border-color: transparent; background: transparent; padding: 4px 6px; }
button.ghost:hover { background: #eef1f5; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.f > * { font-size: 14px; color: var(--ink); }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ostrzeżenia */
.warns { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.warns li { padding: 7px 10px; border-radius: 6px; font-size: 13px; }
.warns .error { background: var(--err-soft); color: var(--err); }
.warns .warn { background: var(--warn-soft); color: var(--warn); }
.warns .info { background: var(--accent-soft); color: #234; }

/* transporty */
.ships { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.ship { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: #fff; display: grid; gap: 6px; }
.ship.wyslano { background: var(--sent); }
.ship .t { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.ship .meta { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.wyslano { background: var(--ok-soft); color: var(--ok); }
.badge.opozniony { background: var(--err-soft); color: var(--err); }
.badge.bez_daty { background: #eee; color: var(--muted); }
.bar { height: 6px; background: #e9ecf1; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.hi > i { background: var(--ok); }
.bar.over > i { background: var(--err); }

/* siatka planu */
.grid-wrap { overflow: auto; max-height: calc(100vh - 140px); border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 5px 8px; vertical-align: middle; }
table.grid thead th { position: sticky; top: 0; background: #f8f9fb; z-index: 2; font-weight: 600; font-size: 12px; text-align: left; color: #344054; }
table.grid th.shipcol { min-width: 92px; text-align: center; border-left: 1px solid var(--line); }
table.grid th.shipcol.wyslano, table.grid td.wyslano { background: var(--sent); }
table.grid td.sc { border-left: 1px solid var(--line); text-align: center; }
table.grid .sticky { position: sticky; left: 0; background: #fff; z-index: 1; }
table.grid thead .sticky { z-index: 3; background: #f8f9fb; }
table.grid tr.virtual td { background: #fffaf0; }
table.grid tr:hover td { background: #f6f9ff; }
table.grid tfoot td { position: sticky; bottom: 0; background: #f8f9fb; font-weight: 600; border-top: 1px solid var(--line); }
table.grid input.q { width: 78px; text-align: right; padding: 4px 6px; font-variant-numeric: tabular-nums; }
table.grid input.q.empty { color: var(--muted); }
table.grid select.p { padding: 3px 4px; font-size: 12px; max-width: 120px; }
.name { min-width: 300px; max-width: 400px; }
.name .n { font-weight: 500; }
.rem-neg { color: var(--err); font-weight: 600; }
.rem-pos { color: var(--warn); font-weight: 600; }
.rem-zero { color: var(--ok); }

/* tabele kartotek */
table.list { border-collapse: collapse; width: 100%; font-size: 13px; }
table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
table.list th { font-size: 12px; color: #344054; background: #f8f9fb; position: sticky; top: 52px; }
table.list th.num, table.list td.num { text-align: right; }
table.list input, table.list select { width: 100%; min-width: 60px; }
table.list tr.inactive td { opacity: .55; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.tabs a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* wykres słupkowy */
.chart { display: grid; gap: 6px; }
.chart .r { display: grid; grid-template-columns: 140px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; }
.chart .b { height: 16px; background: var(--accent); border-radius: 3px; min-width: 2px; }

/* dialog */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(520px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 23, 35, .45); }
#dlg-form { padding: 20px; display: grid; gap: 12px; }
#dlg-form .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { background: #17202e; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 420px; }
.toast.error { background: var(--err); }

.login { max-width: 360px; margin: 80px auto; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
table.grid tr.writeoff td { color: var(--muted); }
table.grid tr.writeoff .n { text-decoration: line-through; }
.acts { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
