/* Zwroty — style wspólne (rdzeń, logowanie, panel kierowcy). Panel biura dokłada własne w biuro.css.
 *
 * Kierunek: narzędzie robocze z samochodu dostawczego. Czerń „atramentowa”, chłodny beton w tle,
 * twarde obramowania zamiast miękkich cieni (czytelne w słońcu) i JEDEN wyrazisty akcent —
 * odblaskowa żółć kamizelki — tylko tam, gdzie kierowca ma coś zrobić (główny przycisk, dostawy do zrobienia).
 * Bez fontów z sieci: system (Roboto na Androidzie, Segoe/SF gdzie indziej), ciężkie wagi zamiast osobnego kroju.
 */

:root {
  /* --- zmienne z kontraktu (nazwy stałe, wartości można zmieniać) --- */
  --bg: #e9ecea;
  --surface: #ffffff;
  --text: #14171a;
  --muted: #465058;
  --primary: #0b6285;      /* biały tekst na tym tle: kontrast 6,6:1 (biuro.css też daje tu biały tekst) */
  --ok: #15803d;
  --warn: #b45309;
  --error: #b91c1c;
  --border: #b4bcc2;
  --radius: 6px;

  /* --- dodatkowe --- */
  --on-primary: #ffffff;
  --link: #0b6285;
  --surface-2: #dde2e0;
  --line: #75818a;         /* mocne obramowanie kart i pól */
  --ink: #14171a;
  --on-ink: #ffffff;
  --accent: #ffd400;       /* żółć kamizelki odblaskowej */
  --on-accent: #14171a;

  --ok-ink: #15803d;       /* kolor tekstu/ikon na powierzchni (w ciemnym trybie jaśniejszy) */
  --warn-ink: #b45309;
  --error-ink: #b91c1c;

  --info-bg: #dcecf4;
  --info-fg: #0a3f57;
  --ok-bg: #d9f2e1;
  --ok-fg: #0f4a26;
  --warn-bg: #fff1b8;
  --warn-fg: #5c3300;
  --error-bg: #fde0de;
  --error-fg: #7a1313;
  --gray-bg: #dde2e0;
  --gray-fg: #20262b;

  /* pasek statusu i toasty: pełne kolory, żeby dało się je odczytać w słońcu */
  --sb-gray: #2d343b;
  --sb-ok: #14532d;
  --sb-error: #991b1b;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1013;
    --surface: #171b20;
    --text: #f1f3f4;
    --muted: #a9b3bb;
    --primary: #1f7fa6;    /* nadal znosi biały tekst (4,6:1) i jest widoczny na ciemnej powierzchni */
    --ok: #15803d;
    --warn: #b45309;
    --error: #c62828;
    --border: #343d45;

    --on-primary: #ffffff;
    --link: #6cc4ea;
    --surface-2: #232a31;
    --line: #56626c;
    --ink: #0a0c0e;

    --ok-ink: #5be08a;
    --warn-ink: #fbbf24;
    --error-ink: #ff9a92;

    --info-bg: #11323f;
    --info-fg: #c8e8f6;
    --ok-bg: #11341f;
    --ok-fg: #bdf5cf;
    --warn-bg: #3b2c05;
    --warn-fg: #ffe28a;
    --error-bg: #451313;
    --error-fg: #ffc9c4;
    --gray-bg: #2a3239;
    --gray-fg: #e6e9eb;
  }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.4 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

body.modal-open { overflow: hidden; }

h1, h2, h3 { line-height: 1.15; margin: 0 0 .45em; font-weight: 800; letter-spacing: -.015em; text-wrap: balance; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--link); }

:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: .88rem; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- układ ---------- */
#view { display: block; outline: none; padding: 14px 14px calc(24px + var(--safe-bottom)); }
.container { max-width: 680px; margin: 0 auto; }

/* ---------- przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 18px;
  border: 2px solid transparent; border-radius: 4px;
  font: inherit; font-weight: 800; text-decoration: none; text-align: center;
  cursor: pointer; background: var(--surface-2); color: var(--text);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--text); }
.btn-danger { background: var(--error); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-sm { min-height: 48px; padding: 0 12px; font-size: .92rem; }
.btn-block { display: flex; width: 100%; }

/* ---------- pola ---------- */
label { display: block; font-weight: 700; margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], input[type="number"], select, textarea {
  width: 100%; min-height: 52px; padding: 8px 12px;
  border: 2px solid var(--line); border-radius: 4px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 1.05rem; /* >=16px — iOS nie przybliża strony */
}
input:focus, textarea:focus, select:focus { border-color: var(--text); outline: 2px solid var(--link); outline-offset: 1px; }
textarea { min-height: 88px; resize: vertical; }
input.invalid { border-color: var(--error-ink); background: var(--error-bg); }
.form-row { margin-bottom: 14px; }
.form-error {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 4px;
  background: var(--error-bg); color: var(--error-fg); font-weight: 700;
  border: 2px solid var(--error-ink);
}
.check-row { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 400; }
.check-row input { width: 22px; height: 22px; accent-color: var(--primary); }

/* ---------- pasek statusu synchronizacji (pełne kolory — czytelne w słońcu) ---------- */
.statusbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px; min-height: 46px;
  font-weight: 800; font-size: .95rem;
  background: var(--sb-gray); color: #fff;
}
.statusbar.ok { background: var(--sb-ok); color: #fff; }
.statusbar.warn { background: var(--accent); color: var(--on-accent); }
.statusbar.error { background: var(--sb-error); color: #fff; }
.statusbar.gray { background: var(--sb-gray); color: #fff; }
.statusbar .btn { min-height: 40px; padding: 0 12px; background: rgba(255, 255, 255, .2); color: inherit; border: 0; }
.statusbar.warn .btn { background: rgba(0, 0, 0, .14); }

.update-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 14px; background: var(--ink); color: var(--on-ink); font-weight: 800;
}
.update-banner .btn-primary { background: var(--accent); color: var(--on-accent); }

/* ---------- górny pasek (zwarty, jednowierszowy także na 390 px, cele dotyku >= 48 px) ---------- */
.topbar {
  display: flex; flex-wrap: nowrap; align-items: center; gap: 8px;
  padding: 6px 14px; background: var(--ink); color: var(--on-ink);
  border-bottom: 3px solid var(--accent);
}
.topbar-brand { flex: 0 0 auto; font-weight: 900; font-size: 1.15rem; letter-spacing: -.02em; color: var(--accent); }
.topbar-user {
  flex: 1 1 60px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: #c9d1d7; font-size: .9rem;
}
.topbar-actions { display: flex; flex: 0 0 auto; gap: 6px; }
.topbar .btn-ghost {
  min-height: 48px; padding: 0 10px; font-size: .85rem; font-weight: 700;
  background: transparent; color: var(--on-ink); border: 1px solid rgba(255, 255, 255, .3);
}
.topbar .btn-ghost:active { background: rgba(255, 255, 255, .12); }
.topbar :focus-visible { outline-color: var(--accent); }

/* ---------- karty, chipy ---------- */
.card {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto;
  padding: 2px 8px; border-radius: 3px;
  font-size: .82rem; font-weight: 800; white-space: nowrap;
  background: var(--gray-bg); color: var(--gray-fg);
}
/* kształt przed nazwą statusu = postęp dostawy, więc status czytelny także bez koloru */
.chip-otwarta::before { content: "○"; }
.chip-uzupelniona::before { content: "◐"; }
.chip-zatwierdzona::before { content: "●"; }
.chip-zafakturowana::before { content: "■"; }
.chip-otwarta { background: var(--accent); color: var(--on-accent); }
.chip-uzupelniona { background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-ink); }
.chip-zatwierdzona { background: var(--ok-bg); color: var(--ok-fg); border: 1px solid var(--ok-ink); }
.chip-zafakturowana { background: var(--gray-bg); color: var(--gray-fg); border: 1px solid var(--line); }

.sync { font-size: 1.1rem; font-weight: 900; }
.sync-pending { color: var(--warn-ink); }
.sync-synced { color: var(--ok-ink); }
.sync-rejected { color: var(--error-ink); }

.note-box { padding: 9px 12px; border-radius: 4px; margin: 8px 0; font-weight: 700; font-size: .95rem; border: 2px solid transparent; }
.note-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--primary); }
.note-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-ink); }
.note-error { background: var(--error-bg); color: var(--error-fg); border-color: var(--error-ink); }
.note-ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-ink); }

/* ---------- logowanie: ciemny nagłówek z twardą krawędzią + arkusz formularza ---------- */
.login-layer {
  position: fixed; inset: 0; z-index: 200; overflow-y: auto;
  display: flex; flex-direction: column;
  background: var(--surface);
  --gutter: max(20px, calc((100% - 420px) / 2));
}
.login-hero {
  flex: 0 0 auto; background: var(--ink); color: var(--on-ink);
  padding: calc(28px + env(safe-area-inset-top, 0px)) var(--gutter) 20px;
  border-bottom: 4px solid var(--accent);
}
.login-hero h1 { margin: 0 0 6px; font-size: 2.1rem; line-height: 1.05; font-weight: 900; letter-spacing: -.03em; color: var(--accent); }
.login-tag { margin: 0; max-width: 24em; font-size: .98rem; line-height: 1.35; color: #d3d9de; }
.login-box {
  flex: 1 0 auto; width: 100%; margin: 0;
  padding: 22px var(--gutter) calc(24px + var(--safe-bottom));
  background: var(--surface);
}
.login-msg { padding: 10px 12px; border-radius: 4px; background: var(--warn-bg); color: var(--warn-fg); font-weight: 700; border: 2px solid var(--warn-ink); }
.login-box .btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--on-accent); min-height: 56px; font-size: 1.05rem; margin-top: 6px; }

/* ---------- lista dostaw kierowcy ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.page-head-titles { min-width: 0; }
.page-head h1 { margin: 0; }
.page-stamp { margin: 2px 0 0; }
.group-title { display: flex; align-items: center; gap: 8px; margin: 18px 0 6px; font-size: 1.15rem; }
.group-count {
  min-width: 1.65em; padding: 0 .42em; border-radius: 3px; text-align: center;
  background: var(--text); color: var(--bg); font-size: .82rem; font-weight: 800; line-height: 1.55;
}
/* jedna tabliczka z wierszami zamiast osobnych kafelków */
.delivery-list {
  display: block; overflow: hidden;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
}
.delivery-list > div + div { border-top: 1px solid var(--border); }
.delivery-card, .delivery-card.card {
  display: block; text-decoration: none; color: inherit; min-height: 72px;
  border: 0; border-radius: 0; background: transparent; padding: 12px 14px;
}
/* do zrobienia = żółty znacznik z lewej, żeby dało się je wyłowić wzrokiem */
.delivery-card.status-otwarta { box-shadow: inset 6px 0 0 var(--accent); padding-left: 18px; }
.delivery-card:active { background: var(--surface-2); }
.delivery-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.delivery-name { font-weight: 800; font-size: 1.12rem; line-height: 1.2; }
.delivery-addr { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.delivery-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 0; margin-top: 6px; color: var(--muted); font-size: .9rem; }
.delivery-meta > span + span::before { content: "·"; margin: 0 8px; color: var(--line); font-weight: 700; }
.delivery-meta .sync { margin-left: auto; }
.rejected-note { margin: 0; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; }
.rejected-note .btn { min-height: 48px; margin-top: 6px; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }

/* ---------- szczegóły dostawy ---------- */
.back-link { display: inline-flex; align-items: center; min-height: 48px; margin-bottom: 2px; font-weight: 800; font-size: .95rem; text-decoration: none; }
.detail-head { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 2px solid var(--border); }
.detail-head h1 { margin-bottom: 2px; }
.detail-head .row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; margin-top: 6px; font-size: .95rem; }
.detail-head .row .sync { margin-left: auto; }

.items { display: grid; gap: 10px; margin-bottom: 14px; }
.item { padding: 11px 12px; }
.item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.item-name { font-weight: 800; font-size: 1.08rem; line-height: 1.2; }
.item-unit { color: var(--muted); font-size: .88rem; font-weight: 700; white-space: nowrap; }

.field-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 12px;
  margin-bottom: 8px; padding: 6px 0 8px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.field-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.field-meta label { margin: 0; font-size: .95rem; line-height: 1.2; }
.item-meta { color: var(--muted); font-size: .85rem; margin: 0; padding: 0; border: 0; }
.item-meta b { color: var(--text); font-weight: 800; }
.field-ctrl { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.num-small { width: 88px !important; min-height: 48px !important; padding: 4px 10px !important; text-align: right; font-weight: 800; font-size: 1.15rem !important; }
.changed-note { color: var(--warn-ink); font-weight: 800; font-size: .84rem; white-space: nowrap; }
.zwr-label { margin-bottom: 4px; font-size: .88rem; color: var(--muted); }

.stepper { display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px; gap: 8px; }
.step-btn {
  min-height: 64px; min-width: 56px; border-radius: 4px; border: 2px solid var(--text);
  background: var(--surface); color: var(--text); font: inherit; font-size: 2rem; font-weight: 800; line-height: 1;
  cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.step-btn:active { background: var(--surface-2); }
/* „+” pełny kolor, „−” obrys: da się je odróżnić bez patrzenia na znak */
.step-btn:last-child { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.stepper input { min-height: 64px; text-align: center; font-size: 1.95rem; font-weight: 900; padding: 0 4px; }
.warn-box { margin-top: 8px; padding: 8px 10px; border-radius: 4px; background: var(--warn-bg); color: var(--warn-fg); font-weight: 800; font-size: .92rem; border: 2px solid var(--warn-ink); }

/* tryb tylko do odczytu: jedna tabliczka zamiast 5 osobnych pudełek */
.items.is-readonly {
  display: block; overflow: hidden;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
}
.items.is-readonly > .item-ro { border: 0; border-radius: 0; padding: 10px 14px; background: transparent; }
.items.is-readonly > .item-ro + .item-ro { border-top: 1px solid var(--border); }
.read-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
  margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--border);
}
.read-row { display: flex; flex-direction: column; gap: 1px; padding: 0; }
.read-row > span { color: var(--muted); font-size: .8rem; font-weight: 700; }
.read-row > b { font-size: 1.08rem; font-weight: 800; }
.read-row > b.has-val { color: var(--warn-ink); }
.read-row:nth-child(2) { text-align: center; }
.read-row:last-child { text-align: right; }

.actionbar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; gap: 10px; margin: 14px -14px calc(-24px - var(--safe-bottom));
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: var(--surface); border-top: 2px solid var(--line);
}
.actionbar .btn { flex: 1 1 0; min-height: 56px; font-size: 1.02rem; }
/* jedyny żółty przycisk na ekranie = to, co kierowca ma teraz zrobić */
.actionbar .btn-primary { flex: 1.7 1 0; background: var(--accent); color: var(--on-accent); border-color: var(--on-accent); }

/* ---------- toasty ---------- */
.toasts {
  position: fixed; left: 0; right: 0; bottom: calc(92px + var(--safe-bottom)); z-index: 300;
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 14px; pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 560px; width: 100%;
  padding: 11px 14px; border-radius: 4px; font-weight: 800; font-size: .95rem;
  background: var(--sb-gray); color: #fff; border: 2px solid rgba(255, 255, 255, .25);
}
.toast-ok { background: var(--sb-ok); }
.toast-warn { background: var(--accent); color: var(--on-accent); border-color: var(--on-accent); }
.toast-error { background: var(--sb-error); }
.toast-info { background: var(--sb-gray); }

/* ---------- okno dialogowe ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 250; overflow-y: auto;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .6);
}
.modal {
  width: 100%; max-width: 520px; background: var(--surface); color: var(--text);
  border-top: 4px solid var(--accent);
  border-radius: 6px 6px 0 0; padding: 18px 16px calc(16px + var(--safe-bottom));
  max-height: 100vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 10px; }
.modal-text { white-space: pre-line; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.modal-actions .btn { width: 100%; }
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 6px; padding-bottom: 18px; border: 2px solid var(--line); border-top: 4px solid var(--accent); }
  .modal-actions { flex-direction: row; justify-content: flex-end; }
  .modal-actions .btn { width: auto; min-width: 120px; }
}

/* ---------- błysk po zapisie ---------- */
@keyframes flash-ok { 0% { opacity: .5; } 100% { opacity: 0; } }
.flash-ok-layer { position: fixed; inset: 0; z-index: 400; background: var(--accent); pointer-events: none; animation: flash-ok .45s ease-out forwards; }
@keyframes flash-ok-el { 0% { box-shadow: inset 0 0 0 999px rgba(255, 212, 0, .5); } 100% { box-shadow: inset 0 0 0 999px transparent; } }
.flash-ok-el { animation: flash-ok-el .6s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .flash-ok-layer, .flash-ok-el { animation-duration: .01s; }
  .btn:active:not(:disabled) { transform: none; }
}

/* ---------- druk ---------- */
@media print {
  .statusbar, .update-banner, .topbar, .toasts, #modal-root, .actionbar, .login-layer { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  #view { padding: 0; }
  .card { border-color: #999; break-inside: avoid; }
}
