/* Panel — motyw grafitowy (domyślny) i jasny: html[data-theme="light"] */
:root {
  color-scheme: dark;     /* ciemne kontrolki przeglądarki: listy, kalendarz, przewijanie */
  --bg: #1b1d20;
  --panel: #24272b;
  --panel-2: #2b2f34;     /* nagłówki tabel, pola */
  --panel-3: #33383e;     /* najechanie */
  --field: #1f2226;
  --ink: #e4e6e9;
  --muted: #9aa0a8;
  --line: #383d44;
  --line-strong: #4b5159;
  --accent: #7aa7e6;
  --accent-strong: #4f7fc4;
  --accent-soft: rgba(122, 167, 230, .14);
  --ok: #4cc38a;
  --ok-soft: rgba(76, 195, 138, .14);
  --warn: #e3a64a;
  --warn-soft: rgba(227, 166, 74, .14);
  --err: #ef6b5f;
  --err-soft: rgba(239, 107, 95, .15);
  --sent: #1f3a2c;        /* zrealizowana (wysłana) wysyłka */
  --sent-strong: #26503a;
  --sent-line: #2f6b4a;
  --virtual: #2e2a20;     /* zaległość bez pozycji */
  --topbar: #141618;
  --head-ink: #c3c8cf;     /* nagłówki tabel */
  --placeholder: #6c727a;
  --err-ink: #f4a39b;
  --warn-ink: #ecc483;
  --info-ink: #b3cdf1;
  --sent-ink: #8fe0b6;
  --sent-field: #182e23;
  --primary-hover: #5d8ed4;
  --toast: #3a3f46;
  --shadow: rgba(0, 0, 0, .55);
  --backdrop: rgba(0, 0, 0, .6);
  --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: var(--topbar); color: #fff; border-bottom: 1px solid #000; }
.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: #b8bec6; padding: 7px 12px; border-radius: 6px; font-size: 13.5px; }
.topbar nav a:hover, .topbar nav .link:hover { background: #2a2e33; color: #fff; text-decoration: none; }
.topbar nav a.active { background: #33383e; 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: #b8bec6; }
.online .who { display: inline-flex; align-items: center; gap: 5px; background: #24272b; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.online .who::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.online .who.self { background: #33383e; color: #fff; }
.topbar .me { background: #33383e; color: #fff; border: 0; font-size: 13px; padding: 6px 11px; }
.topbar .me:hover { background: #3d434a; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); 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: var(--panel-2); color: var(--ink);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--line-strong); background: var(--panel-3); text-decoration: none; }
button.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.danger { color: var(--err); }
button.ghost { border-color: transparent; background: transparent; padding: 4px 6px; }
button.ghost:hover { background: var(--panel-3); }
button:disabled { opacity: .4; cursor: default; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--field); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
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-ink); }
.warns .warn { background: var(--warn-soft); color: var(--warn-ink); }
.warns .info { background: var(--accent-soft); color: var(--info-ink); }

/* 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: var(--panel-2); display: grid; gap: 6px; }
.ship.wyslano { background: var(--sent); border-color: var(--sent-line); }
.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: var(--panel-3); color: var(--muted); }
.bar { height: 6px; background: var(--field); 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: var(--panel); }
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: var(--panel-2); z-index: 2; font-weight: 600; font-size: 12px; text-align: left; color: var(--head-ink); }
table.grid th.shipcol { min-width: 92px; text-align: center; border-left: 1px solid var(--line); }
table.grid td.sc { border-left: 1px solid var(--line); text-align: center; }
table.grid .sticky { position: sticky; left: 0; background: var(--panel); z-index: 1; }
table.grid thead .sticky { z-index: 3; background: var(--panel-2); }
table.grid tr.virtual td { background: var(--virtual); }
table.grid tr:hover td { background: var(--panel-3); }
table.grid tfoot td { position: sticky; bottom: 0; background: var(--panel-2); font-weight: 600; border-top: 1px solid var(--line-strong); }
/* kolumna zrealizowanej wysyłki: zielona, także przy najechaniu na wiersz */
table.grid td.wyslano, table.grid tr:hover td.wyslano { background: var(--sent); border-left-color: var(--sent-line); }
table.grid thead th.shipcol.wyslano { background: var(--sent-strong); color: var(--sent-ink); border-left-color: var(--sent-line); }
table.grid tfoot td.wyslano { background: var(--sent-strong); }
table.grid td.wyslano input.q { border-color: var(--sent-line); background: var(--sent-field); }
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; }
table.grid tr.writeoff td { color: var(--muted); }
table.grid tr.writeoff .n { text-decoration: line-through; }
.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); }
.acts { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }

/* 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: var(--head-ink); background: var(--panel-2); 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: .5; }
.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: var(--panel); color: var(--ink); }
.tabs a:hover { background: var(--panel-3); text-decoration: none; }
.tabs a.active { background: var(--accent-strong); color: #fff; border-color: var(--accent-strong); }

/* 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; }
.chart .b.alt { background: var(--ok); }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(520px, 94vw); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px var(--shadow); }
dialog::backdrop { background: var(--backdrop); }
#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: var(--toast); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); max-width: 420px; }
.toast.error { background: #a8392f; }

.login { max-width: 360px; margin: 80px auto; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
#dlg-form .intro { margin: -4px 0 0; color: var(--muted); line-height: 1.45; }
button.primary.danger-solid { background: #b23b30; border-color: #b23b30; color: #fff; }
button.primary.danger-solid:hover { background: #c8473b; }

/* ---------- tryb jasny: stonowane szarości zamiast czystej bieli ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e9ecef;
  --panel: #f6f7f8;
  --panel-2: #eceff2;
  --panel-3: #e2e6ea;
  --field: #ffffff;
  --ink: #1f2328;
  --muted: #5f6873;
  --line: #d3d8de;
  --line-strong: #b8bfc8;
  --accent: #2c63b8;
  --accent-strong: #2c63b8;
  --accent-soft: rgba(44, 99, 184, .12);
  --ok: #1d7a4c;
  --ok-soft: rgba(29, 122, 76, .12);
  --warn: #9a5b00;
  --warn-soft: rgba(201, 125, 0, .13);
  --err: #b42318;
  --err-soft: rgba(180, 35, 24, .1);
  --sent: #dcefe3;
  --sent-strong: #c3e4cf;
  --sent-line: #97cfac;
  --virtual: #f6edd9;
  --head-ink: #3a424c;
  --placeholder: #9aa2ab;
  --err-ink: #9b1c12;
  --warn-ink: #7f4b00;
  --info-ink: #1f4a8a;
  --sent-ink: #145c38;
  --sent-field: #f3faf6;
  --primary-hover: #24539c;
  --toast: #2b2f34;
  --shadow: rgba(30, 40, 50, .25);
  --backdrop: rgba(30, 35, 40, .45);
}

/* przełącznik trybu w górnym pasku */
.topbar .theme { background: none; border: 1px solid #3a3f46; color: #c9ced5; font-size: 15px; line-height: 1; padding: 6px 9px; }
.topbar .theme:hover { background: #2a2e33; border-color: #50565e; color: #fff; }

/* historia zmian */
table.list.audit td { vertical-align: top; }
table.list.audit .chg { margin-top: 4px; font-size: 12px; line-height: 1.5; }
table.list.audit .chg s { color: var(--muted); }
table.list.audit .chg ul { margin: 2px 0 2px 18px; padding: 0; }
.nowrap { white-space: nowrap; }
dialog.wide { width: min(900px, 96vw); }
.hist-wrap { max-height: 60vh; overflow: auto; }
.hist-wrap table.list th { top: 0; }
button.hist { padding: 0 4px; margin-right: 4px; font-size: 12px; vertical-align: baseline; }
table.list.audit .chg { overflow-wrap: anywhere; }
@media (max-width: 700px) {
  table.list.audit, table.list.audit tbody, table.list.audit tr { display: block; }
  table.list.audit thead { display: none; }
  table.list.audit tr { border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.list.audit td { display: block; border: 0; padding: 2px 4px; }
  table.list.audit td:nth-child(2), table.list.audit td:nth-child(3) { display: inline-block; }
  table.list.audit td:first-child div { display: inline; margin-left: 6px; }
}
/* telefon: zakładki panelu zawijają się zamiast poszerzać stronę */
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 6px 12px; gap: 6px 12px; position: static; }
  table.list th { top: 0; }
  .topbar { justify-content: space-between; }
  .topbar nav { flex-wrap: wrap; min-width: 0; flex: 1 0 100%; order: 3; row-gap: 2px; }
  .topbar nav a, .topbar nav .link { padding: 6px 8px; }
}
