/* Magazyn HUPI — własny CSS (bez CDN). Czytelna typografia, duże przyciski, kolory kurierów jako akcent. */
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --radius: 10px;
  --nav: 232px;
  /* kolory kurierów (stałe) */
  --inpost: #ffcd00;
  --dpd: #dc0032;
  --dhl: #ffcc00;
  --dhl-red: #d40511;
  --orlen: #f39200;
  --orlen-red: #e4002b;
  --fedex: #4d148c;
  --fedex-orange: #ff6200;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}
a { color: var(--primary); }
h1 { font-size: 1.7rem; margin: 0 0 .5rem; }
h1 small, h2 small { font-weight: 400; color: var(--muted); font-size: .7em; margin-left: .4em; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .5rem; }
.mono { font-family: Consolas, "Cascadia Mono", "DejaVu Sans Mono", monospace; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.strong { font-weight: 700; }
.big-text { font-size: 1.35rem; }
.center { text-align: center; }
.lead { font-size: 1.2rem; }
.warn-text { color: var(--warn); font-weight: 700; }
.danger-text { color: var(--danger); font-weight: 700; }
[hidden] { display: none !important; }

/* --- Układ: menu boczne + treść --- */
body.with-nav { padding-left: var(--nav); }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--nav); background: #111827; color: #e5e7eb;
  display: flex; flex-direction: column; padding: 1rem .75rem; overflow-y: auto; z-index: 10;
}
.brand { color: #fff; font-weight: 800; font-size: 1.5rem; text-decoration: none; letter-spacing: .04em; padding: 0 .5rem .75rem; }
.brand span, .brand-big span { font-weight: 400; font-size: .7em; color: #9ca3af; letter-spacing: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: #d1d5db; text-decoration: none; padding: .7rem .75rem; border-radius: 8px; font-size: 1rem;
  display: flex; justify-content: space-between; align-items: center;
}
.nav a:hover { background: #1f2937; color: #fff; }
.nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-toggle { display: none; }
.sidebar-foot { margin-top: auto; padding: 1rem .5rem 0; border-top: 1px solid #374151; font-size: .9rem; display: flex; flex-direction: column; gap: .35rem; }
.sidebar-foot a, .sidebar-foot .btn-link { color: #9ca3af; }
.who { color: #fff; font-weight: 600; }
.main { padding: 1.25rem 1.5rem 3rem; max-width: 1500px; }
body.no-nav .main { margin: 0 auto; }

/* --- Wersja testowa: stały pasek na górze każdej strony (APP_ENV=test) --- */
.env-banner {
  position: fixed; top: 0; left: 0; right: 0; height: 2rem; line-height: 2rem; z-index: 30;
  background: repeating-linear-gradient(45deg, #b45309 0 14px, #d97706 14px 28px);
  color: #fff; font-weight: 800; font-size: .95rem; letter-spacing: .06em; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
body.env-test { padding-top: 2rem; }
body.env-test .sidebar { top: 2rem; }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.card { background: var(--card); border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: 0 1px 2px rgba(0,0,0,.06); border: 1px solid var(--line); margin-bottom: 1rem; }
.card.inner { box-shadow: none; background: #f9fafb; }
.card.narrow { max-width: 480px; }
.narrow-wide { max-width: 760px; }
.login-card { margin: 10vh auto; }
.brand-big { font-size: 2.2rem; text-align: center; letter-spacing: .05em; }
details.card > summary { cursor: pointer; font-size: 1rem; }
details.card[open] > summary { margin-bottom: .75rem; }

/* --- Przyciski i pola --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1rem; min-height: 44px; border-radius: 8px; border: 1px solid #d1d5db; background: #fff; color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #7f1d1d; }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-ghost { background: transparent; }
.btn-mix { border-color: #7c3aed; color: #6d28d9; }
.btn-small { min-height: 34px; padding: .3rem .7rem; font-size: .9rem; }
.btn-lg { font-size: 1.1rem; padding: .75rem 1.3rem; min-height: 52px; }
.btn-xl { font-size: 1.35rem; padding: 1rem 1.6rem; min-height: 64px; width: 100%; }
.btn-xxl { font-size: 2.2rem; padding: 1.2rem 2rem; min-height: 96px; width: 100%; letter-spacing: .08em; margin: .5rem 0; }
.btn-quick { min-width: 64px; font-size: 1.15rem; }
.btn-link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; }
form.inline { display: inline; }

input, select, textarea {
  font: inherit; padding: .5rem .65rem; min-height: 42px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--text);
  max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 3px solid #93c5fd; outline-offset: 0; border-color: var(--primary); }
input[type=checkbox], input[type=radio] { min-height: 0; width: 1.2rem; height: 1.2rem; vertical-align: middle; }
.input-big { font-size: 1.4rem; padding: .6rem .8rem; min-height: 56px; }
.input-count { width: 6.5rem; }
.input-bad { border-color: var(--danger) !important; background: var(--danger-bg); color: var(--danger); font-weight: 700; }
.input-confirm { width: 9rem; text-transform: uppercase; font-weight: 700; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack label { display: flex; flex-direction: column; gap: .25rem; font-weight: 600; }
.stack label.check { flex-direction: row; font-weight: 400; }
label.check { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); }
.filters .quick { display: flex; flex-wrap: wrap; gap: .35rem; }
.radio-btn { display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .7rem; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; cursor: pointer; }
.radio-btn:has(input:checked) { border-color: var(--primary); background: #eff6ff; font-weight: 700; }

/* --- Komunikaty --- */
.alert { padding: .8rem 1rem; border-radius: 8px; margin: 0 0 1rem; border-left: 6px solid; }
.alert-ok { background: var(--ok-bg); border-color: var(--ok); color: #14532d; }
.alert-warn { background: var(--warn-bg); border-color: var(--warn); color: #78350f; }
.alert-error { background: var(--danger-bg); border-color: var(--danger); color: #7f1d1d; }
.alert-big { font-size: 1.1rem; border-left-width: 10px; padding: 1rem 1.2rem; }
.alert .btn { margin-left: .5rem; vertical-align: middle; }
.big-alert { font-size: 1.1rem; }
.dup-list { margin: .5rem 0 0; padding-left: 1.2rem; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: #e5e7eb; color: #374151; vertical-align: middle; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: #f59e0b; color: #111; }
.badge-danger { background: var(--danger); color: #fff; }
.chip { display: inline-flex; gap: .3rem; align-items: center; padding: .2rem .6rem; border-radius: 999px; background: #eef2ff; color: #312e81; text-decoration: none; font-size: .88rem; margin: .1rem; border: 1px solid #c7d2fe; }
a.chip:hover { background: #e0e7ff; }
.chip-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* --- Kurierzy (akcent, nie tło stron) --- */
.courier { display: inline-block; padding: .15rem .6rem; border-radius: 6px; font-weight: 800; font-size: .9rem; letter-spacing: .02em; background: #e5e7eb; color: #111; white-space: nowrap; }
.courier.c-inpost { background: var(--inpost); color: #1f2937; }
.courier.c-dpd { background: var(--dpd); color: #fff; }
.courier.c-dhl { background: var(--dhl); color: var(--dhl-red); }
.courier.c-orlen { background: linear-gradient(90deg, var(--orlen), var(--orlen-red)); color: #fff; }
.courier.c-fedex { background: var(--fedex); color: #fff; box-shadow: inset -6px 0 0 var(--fedex-orange); padding-right: .9rem; }
.c-inpost { --accent: var(--inpost); }
.c-dpd { --accent: var(--dpd); }
.c-dhl { --accent: var(--dhl-red); }
.c-orlen { --accent: var(--orlen); }
.c-fedex { --accent: var(--fedex); }
.card[class*="c-"] { border-top: 6px solid var(--accent, var(--line)); }
.courier-row > th:first-child { border-left: 6px solid var(--accent, transparent); }

/* --- Daty wysyłki --- */
.shipday { display: inline-block; font-weight: 700; font-size: .85rem; padding: .1rem .5rem; border-radius: 6px; white-space: nowrap; }
.shipday-today { background: #dbeafe; color: #1e40af; }
.shipday-next { background: #f3e8ff; color: #6b21a8; }
.shipday-late { background: var(--danger); color: #fff; }

/* --- Tabele --- */
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table thead th { font-size: .78rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; background: #f9fafb; }
.table tfoot th { border-top: 2px solid #d1d5db; }
.table.compact th, .table.compact td { padding: .35rem .5rem; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.mono { white-space: nowrap; }
.table-scroll { overflow-x: auto; }
.row-unprinted { background: #fff1f2; }
.row-unprinted td:first-child { box-shadow: inset 6px 0 0 var(--danger); }
.row-cancelled { color: var(--muted); text-decoration: line-through; }
.row-cancelled .btn, .row-cancelled .badge { text-decoration: none; }
.row-discrepancy { background: #fff7ed; }
.row-error { background: var(--danger-bg); }

/* --- Pulpit: kafle --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; text-decoration: none; color: var(--text); border-left: 6px solid #9ca3af; }
a.tile:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.tile-link { text-decoration: none; color: inherit; display: flex; flex-direction: column; }
.tile-label { font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 2.6rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: .9rem; color: var(--muted); }
.tile-main { border-left-color: var(--primary); }
.tile-ok { border-left-color: var(--ok); }
.tile-warn { border-left-color: #f59e0b; background: #fffbeb; }
.tile-danger { border-left-color: var(--danger); background: var(--danger-bg); }
.tile-danger .tile-value { color: var(--danger); }

/* --- Pula --- */
.pool-heading { font-size: 1.35rem; font-weight: 800; letter-spacing: .02em; display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }
.pool-total { font-size: 1rem; font-weight: 600; color: var(--muted); }
.pool-first { border-top: 6px solid #2563eb; }
.pool-second { border-top: 6px solid #7c3aed; margin-top: 2rem; }
.pool-second .pool-heading { color: #6b21a8; }
.pool-late { border-top: 6px solid var(--danger); background: #fff5f5; }
.pool-late .pool-heading { color: var(--danger); }
.pool-later { border-top: 6px solid #9ca3af; }
.matrix td.num, .matrix th.num { min-width: 54px; text-align: center; padding-left: .3rem; padding-right: .3rem; }
.matrix a.count { display: inline-block; min-width: 46px; padding: .45rem .5rem; border-radius: 8px; background: #eff6ff; border: 1px solid #bfdbfe; font-size: 1.25rem; font-weight: 800; text-decoration: none; color: #1e3a8a; }
.matrix a.count:hover { background: var(--primary); color: #fff; }
.matrix .zero { color: #d1d5db; }
.mix-cell { min-width: 150px; }
.courier-cell { white-space: nowrap; }
.courier-cell .courier { display: block; text-align: center; margin-bottom: .35rem; }
.courier-cell .btn { width: 100%; }

/* --- Nowy pakiet --- */
.pkg-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
.pkg-side { position: sticky; top: 1rem; }
.step { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: .75rem 1rem 1rem; margin: 0 0 .9rem; }
.step legend { font-weight: 800; font-size: 1.05rem; padding: 0 .4rem; }
.choices { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.choice { position: relative; display: inline-flex; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice > span {
  display: inline-flex; align-items: center; gap: .45rem; padding: .7rem 1rem; min-height: 52px; border-radius: 10px;
  border: 2px solid #d1d5db; background: #fff; font-size: 1.05rem; font-weight: 600; user-select: none;
}
.choice:hover > span { border-color: #93c5fd; }
.choice input:checked + span { border-color: var(--primary); background: #eff6ff; box-shadow: 0 0 0 2px var(--primary) inset; }
.choice input:focus-visible + span { outline: 3px solid #93c5fd; }
.choice-courier > span { border-left: 10px solid var(--accent, #d1d5db); }
.choice-empty > span { opacity: .55; }
.choice-late > span { border-color: var(--danger); color: var(--danger); }
.choice-mix > span { border-style: dashed; }
.choice-content.is-mix > span { background: #faf5ff; }
.choice-worker > span { min-width: 180px; justify-content: center; font-size: 1.15rem; min-height: 60px; }
.count-badge { background: #e5e7eb; border-radius: 999px; padding: .05rem .5rem; font-size: .9rem; }
.choice input:checked + span .count-badge { background: var(--primary); color: #fff; }
.preview-box { min-height: 180px; }
.preview-count { font-size: 1.1rem; margin-bottom: .5rem; }
.preview-count .big { font-size: 2.6rem; font-weight: 800; }
.preview-count.short .big { color: var(--warn); }
.actions-big { display: flex; flex-direction: column; gap: .6rem; }

/* --- Pakiet --- */
.pkg-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem 1rem; margin-bottom: 1rem; }
.pkg-facts > div { display: flex; flex-direction: column; align-items: flex-start; gap: .15rem; }
.pkg-facts .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.print-status { font-size: 1.2rem; font-weight: 800; padding: .6rem 1rem; border-radius: 8px; text-align: center; }
.print-status.not-printed { background: var(--danger); color: #fff; letter-spacing: .1em; }
.print-status.printed { background: var(--ok-bg); color: var(--ok); }
.danger-zone { border-color: #fecaca; }
.danger-zone > summary { color: var(--danger); }
.scan-box { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; border-left: 6px solid var(--primary); }
.scan-box label { font-weight: 700; font-size: 1.05rem; }
.scan-box input { flex: 1 1 320px; }

/* --- Protokoły --- */
.proto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 1rem; }
.proto-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-bottom: 1rem; }
.stat { background: #f9fafb; border-radius: 8px; padding: .5rem; text-align: center; }
.stat-value { display: block; font-size: 1.8rem; font-weight: 800; }
.stat-label { font-size: .78rem; color: var(--muted); }
.stat-main { background: #eff6ff; }
.stat-main .stat-value { color: var(--primary); font-size: 2.3rem; }
.stat-warn { background: var(--warn-bg); }
.stat-warn .stat-value { color: var(--warn); }
.confirm-form { display: inline-flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.confirm-form.stack { display: flex; }
.discrepancy-hint { color: var(--danger); font-weight: 700; margin: 0; }
.confirm-row td { background: #f9fafb; }
.confirm-form .grow { flex: 1 1 200px; }
.nowrap { white-space: nowrap; }

/* --- Do sprawdzenia --- */
.review-grid { display: grid; grid-template-columns: 240px minmax(300px, 1fr) minmax(400px, 1.1fr); gap: 1rem; align-items: start; }
.queue-list { list-style: none; margin: 0; padding: 0; max-height: 75vh; overflow-y: auto; }
.queue-list li a { display: flex; flex-direction: column; padding: .5rem; border-radius: 8px; text-decoration: none; color: var(--text); }
.queue-list li a small { color: var(--muted); }
.queue-list li.active a { background: #eff6ff; box-shadow: inset 4px 0 0 var(--primary); }
.pdf-frame { width: 100%; height: 72vh; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; }
.raw-text { white-space: pre-wrap; font-size: .8rem; max-height: 300px; overflow: auto; background: #f9fafb; padding: .5rem; }
.items-table select, .items-table input { width: 100%; min-width: 0; }
.items-table td:nth-child(2) { width: 6rem; }
.items-table td:nth-child(1) { width: 45%; }

/* --- Słowniki --- */
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: 1rem; border-bottom: 2px solid var(--line); }
.tabs a { padding: .65rem 1rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.row-head, .row-form { display: grid; gap: .5rem; align-items: center; padding: .35rem 0; }
.row-head { font-size: .78rem; text-transform: uppercase; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); }
.row-form { border-bottom: 1px solid #f3f4f6; }
.row-form.inactive { opacity: .6; }
.grid-symbols { grid-template-columns: 110px minmax(160px, 2fr) 80px 90px minmax(120px, 1fr) 80px 90px; }
.grid-norms { grid-template-columns: minmax(150px, 1.5fr) 160px 120px 110px 80px 90px; }
.grid-workers { grid-template-columns: minmax(200px, 1fr) 80px 90px; }
.grid-couriers { grid-template-columns: 110px minmax(160px, 1fr) 80px 90px; }
.row-form input:not([type=checkbox]), .row-form select { width: 100%; }

/* --- Użytkownicy --- */
.user-card.inactive { opacity: .7; }
.user-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.section-checks { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.reset-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }

/* --- Import / Apilo --- */
.file-drop { display: flex; flex-direction: column; gap: .5rem; padding: 1.5rem; border: 3px dashed #93c5fd; border-radius: var(--radius); background: #f8fafc; font-weight: 400 !important; }
.file-drop input { font-size: 1.05rem; }
.mode-badge { font-weight: 800; padding: .55rem 1rem; border-radius: 8px; letter-spacing: .03em; }
.mode-read { background: var(--ok); color: #fff; }
.mode-write { background: #ea580c; color: #fff; }
.sticky-actions { position: sticky; top: 0; background: var(--card); padding: .5rem 0; z-index: 2; border-bottom: 1px solid var(--line); }

/* --- Wąskie ekrany (tablet pionowo / telefon) --- */
@media (max-width: 1440px) {
  .review-grid { grid-template-columns: 1fr 1fr; }
  .review-queue { grid-column: 1 / -1; }
  .queue-list { max-height: 220px; }
}
@media (max-width: 1000px) {
  .pkg-grid { grid-template-columns: 1fr; }
  .pkg-side { position: static; }
  .grid-symbols, .grid-norms { grid-template-columns: 1fr 1fr; }
  .row-head.grid-symbols, .row-head.grid-norms { display: none; }
}
@media (max-width: 900px) {
  body.with-nav { padding-left: 0; }
  .sidebar { position: static; width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .5rem .75rem; }
  .brand { padding: 0 .5rem; }
  .nav-toggle { display: inline-block; margin-left: auto; background: none; border: 1px solid #4b5563; color: #fff; border-radius: 6px; font-size: 1.3rem; padding: .2rem .7rem; }
  .nav, .sidebar-foot { display: none; width: 100%; }
  .sidebar.open .nav, .sidebar.open .sidebar-foot { display: flex; }
  .main { padding: 1rem; }
  .grid-2, .proto-grid { grid-template-columns: 1fr; }
  .review-grid { grid-template-columns: 1fr; }
  .proto-stats { grid-template-columns: repeat(2, 1fr); }
}
@media print {
  .sidebar, .toolbar, .btn, .env-banner { display: none !important; }
  body.with-nav { padding-left: 0; }
  body.env-test { padding-top: 0; }
}
