/* Tablica — motyw grafitowy (domyślny) i jasny: html[data-theme="light"], spójne z panelem */
:root {
  color-scheme: dark;
  --bg: #16181b;
  --panel: #212428;
  --panel-2: #2b2f34;
  --ink: #e6e8eb;
  --muted: #979da5;
  --line: #353a41;
  --accent: #7aa7e6;
  --ok: #4cc38a;
  --warn: #e3a64a;
  --err: #ef6b5f;
  --chip-on: #2a3442;
  --err-soft: rgba(255, 107, 94, .12);
  --err-ink: #ffb3ab;
  --warn-soft: rgba(245, 176, 65, .12);
  --warn-ink: #f8cf8a;
  --button: #4f7fc4;
  --shadow: rgba(0, 0, 0, .6);
  --backdrop: rgba(0, 0, 0, .65);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; font-size: clamp(14px, 0.9vw, 18px); }
a { color: var(--accent); }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.hd { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 20px 28px 12px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75em; color: var(--muted); }
h1 { margin: 2px 0 0; font-size: 2em; font-weight: 600; }
.hd-right { display: flex; align-items: center; gap: 20px; }
.clock { text-align: right; }
.online { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .85em; color: var(--muted); max-width: 46vw; }
.online .who { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); color: var(--ink); padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.online .who::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
#time { font-size: 1.9em; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
select { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: inherit; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 0 28px 14px; font-size: .9em; color: var(--muted); }
.filters label { display: inline-flex; align-items: center; gap: 8px; }
.filters select { max-width: 280px; }
.filters select.on { border-color: var(--accent); color: var(--ink); background: var(--chip-on); }
.filters button { font: inherit; background: none; color: var(--accent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.filters button:hover { border-color: var(--accent); }
.kpi .l .tag { color: var(--accent); }
.ship .part { color: var(--accent); }

main { padding: 0 28px 16px; display: grid; gap: 16px; grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr); grid-template-areas: "kpi kpi" "plan side"; }
.kpis { grid-area: kpi; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi .v { font-size: 1.8em; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85em; margin-top: 2px; }
.kpi.alert { border-color: var(--err); }
.kpi.alert .v { color: var(--err); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; min-width: 0; overflow-x: auto; }
.card h2 { margin: 0 0 12px; font-size: 1em; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.plan { grid-area: plan; }
.side { grid-area: side; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-content: start; min-width: 0; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8em; text-transform: uppercase; letter-spacing: .05em; padding: 0 8px 8px; }
td { padding: 9px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
td .c { color: var(--muted); font-size: .82em; }
.prog { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; min-width: 90px; position: relative; }
.prog i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 99px; }
.prog i.s { background: var(--ok); }
.prog i.over { background: var(--err); border-radius: 0 99px 99px 0; min-width: 8px; left: auto !important; right: 0; }
.prog.overfull { box-shadow: 0 0 0 1px var(--err); }
/* miniatury rysunków */
.thumb-col { width: 64px; padding-right: 4px; }
.thumb { display: flex; align-items: center; justify-content: center; width: 58px; height: 58px; border-radius: 6px;
  background: #fff; overflow: hidden; border: 1px solid var(--line); text-decoration: none; font-size: 1.4em; color: #333; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; transition: transform .15s ease; }
a.thumb:hover, a.thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
a.thumb:hover img { transform: scale(1.08); }
.thumb.none { background: var(--panel-2); color: var(--muted); font-size: .62em; text-align: center; line-height: 1.2; }
.thumb.doc { background: var(--panel-2); }
.card h2 .folder { float: right; font-size: .85em; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--accent); text-decoration: none; }
.card h2 .folder:hover { text-decoration: underline; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.rem-pos { color: var(--warn); font-weight: 600; }
.rem-neg { color: var(--err); font-weight: 600; }
.rem-zero { color: var(--ok); }
.prio { display: inline-block; font-size: .72em; font-weight: 700; border-radius: 4px; padding: 1px 6px; margin-right: 6px; background: var(--err); color: #fff; vertical-align: 1px; }

.ship { padding: 12px 0; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.ship:first-of-type { border-top: 0; padding-top: 0; }
.ship .top { display: flex; gap: 10px; align-items: baseline; }
.ship .name { font-weight: 600; }
.ship .when { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.when.today { color: var(--warn); }
.when.late { color: var(--err); }
.ship .bar { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.ship .bar i { display: block; height: 100%; background: var(--accent); }
.ship .bar.hi i { background: var(--ok); }
.ship .bar.over i { background: var(--err); }

.warns { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .9em; }
.warns li { padding: 6px 10px; border-radius: 6px; background: var(--err-soft); color: var(--err-ink); }
.warns li.warn { background: var(--warn-soft); color: var(--warn-ink); }

.ft { padding: 8px 28px 18px; font-size: .8em; }

/* logowanie na tablicy */
body.locked .filters, body.locked #month { display: none; }
body.locked main { display: block; }
.login { max-width: 380px; margin: 40px auto; display: grid; gap: 14px; }
.login h2 { margin: 0; }
.login label { display: grid; gap: 6px; color: var(--muted); font-size: .9em; }
.login input { font: inherit; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.login input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.login button { font: inherit; font-weight: 600; background: var(--button); color: #fff; border: 0; border-radius: 8px; padding: 11px; cursor: pointer; }
.login .err { color: var(--err); min-height: 1.2em; font-size: .9em; }
.login p { margin: 0; font-size: .85em; }
.empty { padding: 60px; text-align: center; color: var(--muted); grid-column: 1 / -1; }

@media (max-width: 1000px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "kpi" "side" "plan"; }
  .hd { flex-direction: column; align-items: flex-start; }
  .hd-right { flex-wrap: wrap; }
  .online { max-width: none; }
  .plan { overflow-x: auto; }
}
@media (max-width: 600px) {
  .hd, main, .ft, .filters { padding-left: 16px; padding-right: 16px; }
  .filters label { width: 100%; justify-content: space-between; }
  .filters select { max-width: none; flex: 1; }
  .thumb-col { width: 48px; }
  .thumb { width: 44px; height: 44px; }
  .card h2 .folder { float: none; display: block; margin-top: 6px; }
  h1 { font-size: 1.5em; }
  .col-opt { display: none; }
}

/* najbliższe wysyłki: karta otwiera okno ze szczegółami */
.ship[data-ship] { cursor: pointer; border-radius: 8px; margin: 0 -8px; padding-left: 8px; padding-right: 8px; }
.ship[data-ship]:hover { background: var(--panel-2); }
.ship[data-ship]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ship .sum { font-size: .85em; color: var(--ink); line-height: 1.4; }
.ship .sum .more { display: block; color: var(--accent); font-size: .95em; }

/* okno szczegółów wysyłki */
#ship-dlg { width: min(860px, 94vw); max-height: 86vh; padding: 0; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--ink); box-shadow: 0 24px 70px var(--shadow); }
#ship-dlg::backdrop { background: var(--backdrop); }
#ship-dlg .dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 8px; }
#ship-dlg h2 { margin: 2px 0 0; font-size: 1.3em; }
#ship-dlg .x { font: inherit; font-size: 1.1em; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; }
#ship-dlg .x:hover { color: var(--ink); border-color: var(--muted); }
#ship-dlg .dlg-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 0 20px 14px; color: var(--muted); font-size: .9em; border-bottom: 1px solid var(--line); }
#ship-dlg .dlg-meta b { color: var(--ink); font-weight: 600; }
#ship-dlg .dlg-scroll { overflow: auto; max-height: calc(86vh - 170px); padding: 4px 20px 0; }
#ship-dlg .dlg-table td { padding: 8px; }
#ship-dlg .dlg-table td:nth-child(2), #ship-dlg .dlg-table td:nth-child(3), #ship-dlg .dlg-table td:nth-child(4) { white-space: nowrap; }
#ship-dlg .dlg-table th { position: sticky; top: 0; background: var(--panel); padding-top: 10px; }
#ship-dlg .dlg-table a { text-decoration: none; }
#ship-dlg .dlg-table tr.dim td { opacity: .4; }
#ship-dlg tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
#ship-dlg .note { padding: 6px 20px 18px; margin: 0; font-size: .85em; }
@media (max-width: 600px) {
  /* na telefonie: pozycja jako blok — nazwa, pod nią odbiorca i kierunek, ilość po prawej */
  #ship-dlg .dlg-scroll { padding: 4px 14px 0; }
  #ship-dlg .dlg-table thead { display: none; }
  #ship-dlg .dlg-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
  #ship-dlg .dlg-table td { display: block; padding: 0; border: 0; white-space: normal; }
  #ship-dlg .dlg-table tbody td:nth-child(1) { grid-column: 1 / -1; font-weight: 600; }
  #ship-dlg .dlg-table tbody td:nth-child(2), #ship-dlg .dlg-table tbody td:nth-child(3) { grid-column: 1; color: var(--muted); font-size: .9em; }
  #ship-dlg .dlg-table tbody td:nth-child(4) { grid-column: 2; grid-row: 2 / span 2; align-self: center; white-space: nowrap; font-weight: 600; }
  #ship-dlg .dlg-table td:nth-child(5) { display: none; }
  #ship-dlg tfoot tr { border-top: 2px solid var(--line); }
  #ship-dlg tfoot td { border-top: 0; }
  #ship-dlg tfoot td:nth-child(2) { white-space: nowrap; }
}

/* ---------- tryb jasny ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e9ecef;
  --panel: #f6f7f8;
  --panel-2: #e3e7eb;
  --ink: #1f2328;
  --muted: #5f6873;
  --line: #d3d8de;
  --accent: #2c63b8;
  --ok: #1d7a4c;
  --warn: #9a5b00;
  --err: #b42318;
  --chip-on: #dde7f6;
  --err-soft: rgba(180, 35, 24, .1);
  --err-ink: #9b1c12;
  --warn-soft: rgba(201, 125, 0, .13);
  --warn-ink: #7f4b00;
  --button: #2c63b8;
  --shadow: rgba(30, 40, 50, .25);
  --backdrop: rgba(30, 35, 40, .45);
}
.ft .theme { font: inherit; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 2px 8px; cursor: pointer; }
.ft .theme:hover { color: var(--ink); border-color: var(--muted); }
