/* Wysyłkomat — skórka jak w Monitorze Circular Clothing (ten sam granat, mosiądz, Archivo + IBM Plex Mono).
   Zasady: 13 px bazowo, tabele 12.5 px, bez wersalików w etykietach, jeden akcent (mosiądz), kolory stanu osobno.
   Moduły dopisują własny CSS przez W.css('<modul>', `...`) — NIE edytują tego pliku. */
:root {
  --paper: #F3F4F1;
  --paper2: #F8F9F6;
  --ink: #1F2630;
  --ink-deep: #171D26;
  --ink-soft: #55606F;
  --dim: #8A93A0;
  --line: #DBDDD7;
  --line2: #E8E9E4;
  --card: #FFFFFF;
  --brass: #B8912E;
  --brass-bg: #F6EFDC;
  --green: #1E6B47;  --green-bg: #E4F0E8;
  --amber: #A8690F;  --amber-bg: #FBF0DA;
  --red: #A8452C;    --red-bg: #F7E5DF;
  --blue: #2F5A85;   --blue-bg: #E6EEF6;
  --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --sans: 'Archivo', 'Segoe UI', system-ui, sans-serif;
  --pasek: 232px;
  --r: 4px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--sans);
  font-size: 13px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; white-space: nowrap; }
.muted { color: var(--ink-soft); }
.dim { color: var(--dim); }
.hidden { display: none !important; }
[hidden] { display: none !important; } /* .field i inne klocki z display:flex nie mogą nadpisać atrybutu hidden */
.nowrap { white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

/* ---------- Logowanie ---------- */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 360px; max-width: 100%; background: var(--card); border: 1px solid var(--line); padding: 34px 30px; box-shadow: 0 2px 20px rgba(31,38,48,.06); }
.login-logo { width: 44px; height: 44px; display: block; margin-bottom: 16px; }
.login-firma { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; color: var(--ink-soft); }
.login-brand { font-weight: 700; font-size: 25px; line-height: 1.15; }
.login-sub { color: var(--ink-soft); font-size: 12.5px; margin: 4px 0 22px; }
.login-box input { width: 100%; padding: 9px 11px; border: 1px solid var(--line); background: var(--paper); font-family: var(--mono); font-size: 14px; margin-bottom: 10px; border-radius: var(--r); }
.login-box button { width: 100%; padding: 10px; background: var(--ink); color: var(--paper); border: none; font-weight: 600; font-size: 14px; cursor: pointer; margin-top: 4px; border-radius: var(--r); }
.login-box button:hover { background: var(--ink-deep); }
.login-error { color: var(--red); font-size: 12.5px; margin-top: 10px; min-height: 18px; }

/* ---------- Układ ---------- */
#app { display: flex; min-height: 100vh; }
#pasek {
  width: var(--pasek); flex: 0 0 var(--pasek); background: var(--ink-deep); color: #C7CCD4;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  transition: width .18s ease, flex-basis .18s ease; z-index: 30;
}
.marka { display: flex; align-items: center; gap: 10px; padding: 18px 12px 16px 16px; }
.marka-znak { width: 32px; height: 32px; flex: 0 0 32px; }
.marka-txt { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; flex: 1; }
.marka-firma { font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; color: #7C8695; white-space: nowrap; }
.marka-app { font-size: 17px; font-weight: 700; color: #F0F1EE; letter-spacing: .01em; white-space: nowrap; }
.btn-zwin { background: none; border: 1px solid #39414F; color: #7C8695; width: 24px; height: 24px; border-radius: var(--r); cursor: pointer; display: flex; align-items: center; justify-content: center; flex: 0 0 24px; }
.btn-zwin svg { width: 14px; height: 14px; transition: transform .18s ease; }
.btn-zwin:hover { color: #F0F1EE; border-color: #5A6474; }
#nav { display: flex; flex-direction: column; gap: 1px; padding: 4px 8px; flex: 1; overflow-y: auto; }
#nav a {
  display: flex; align-items: center; gap: 10px; color: #A8B0BC; text-decoration: none;
  padding: 8px 11px; font-size: 13.5px; font-weight: 500; border-radius: 3px; border-left: 2px solid transparent; white-space: nowrap;
}
#nav a:hover { background: rgba(255,255,255,.05); color: #E8EAE6; }
#nav a.active { background: rgba(184,145,46,.13); color: #F0F1EE; border-left-color: var(--brass); }
#nav a .ikona { width: 17px; height: 17px; flex: 0 0 17px; color: #6F7887; }
#nav a.active .ikona { color: var(--brass); }
#nav a .licznik { margin-left: auto; font-family: var(--mono); font-size: 11px; color: #7C8695; }
#nav a.active .licznik { color: #E8EAE6; }
.pasek-stopka { padding: 12px 14px 14px; border-top: 1px solid rgba(255,255,255,.07); }
.srodowisko { background: #7A5A12; color: #FFF3D6; font-size: 11px; font-weight: 600; padding: 5px 8px; border-radius: 3px; margin-bottom: 10px; line-height: 1.3; }
.pasek-stopka .kto { display: flex; flex-direction: column; margin-bottom: 9px; line-height: 1.3; min-width: 0; }
.kto-imie { font-size: 13px; font-weight: 600; color: #E8EAE6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kto-rola { font-family: var(--mono); font-size: 11px; color: #7C8695; }
.pasek-akcje { display: flex; gap: 6px; }
.btn-pasek { flex: 1; background: transparent; color: #A8B0BC; border: 1px solid #39414F; padding: 5px 8px; font-size: 12px; cursor: pointer; border-radius: 3px; }
.btn-pasek:hover { color: #F0F1EE; border-color: #5A6474; }

/* pasek zwinięty: same ikony */
body.pasek-zwiniety { --pasek: 60px; }
body.pasek-zwiniety .marka-txt, body.pasek-zwiniety #nav a span.et, body.pasek-zwiniety #nav a .licznik,
body.pasek-zwiniety .pasek-stopka .kto, body.pasek-zwiniety .srodowisko { display: none; }
body.pasek-zwiniety .marka { flex-direction: column; padding: 14px 8px; gap: 10px; }
body.pasek-zwiniety .btn-zwin svg { transform: rotate(180deg); }
body.pasek-zwiniety #nav a { justify-content: center; padding: 9px 0; }
body.pasek-zwiniety .pasek-stopka { padding: 10px 8px; }
body.pasek-zwiniety .btn-pasek { font-size: 10.5px; padding: 5px 2px; }

#app > .tresc { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#gora {
  display: flex; align-items: center; gap: 12px; height: 50px; padding: 0 24px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; font-size: 15px; font-weight: 600;
}
.gora-kontekst { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--ink-soft); display: flex; gap: 8px; align-items: center; }
.btn-menu { display: none; align-items: center; justify-content: center; background: none; border: 1px solid var(--line); padding: 4px 7px; cursor: pointer; border-radius: 3px; color: var(--ink); }
main#view { width: 100%; max-width: 1680px; margin: 0 auto; padding: 20px 24px 60px; }

@media (max-width: 900px) {
  #pasek { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .18s ease; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  #app.menu-otwarte #pasek { transform: translateX(0); }
  /* przyciemnione tło pod otwartym paskiem — klik w nie zamyka menu (core.js) */
  #app.menu-otwarte::after { content: ''; position: fixed; inset: 0; background: rgba(23,29,38,.35); z-index: 25; }
  .btn-menu { display: inline-flex; }
  .btn-zwin { display: none; }
  main#view { padding: 16px 16px 48px; }
  #gora { padding: 0 16px; }
}

/* ---------- Ruch ---------- */
#view.wlot { animation: wlot .16s ease-out both; }
@keyframes wlot { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
body.gasnie #view { opacity: 0; transform: translateY(-4px); transition: opacity .12s ease-in, transform .12s ease-in; }
.modal { animation: mpop .14s ease-out; }
@keyframes mpop { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Typografia i sekcje ---------- */
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.sekcja { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.sekcja-glowa { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sekcja-glowa .akcje { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.opis { color: var(--ink-soft); max-width: 90ch; }

/* ---------- Karty, KPI ---------- */
.card { background: var(--card); border: 1px solid var(--line); padding: 14px 16px; border-radius: var(--r); }
.card.flat { padding: 0; }
.card-glowa { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line2); }
.card-glowa h3 { font-size: 13.5px; }
.card-glowa .akcje { margin-left: auto; display: flex; gap: 6px; }
.card-tresc { padding: 12px 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 1100px) { .grid3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 800px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 11px 13px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit; }
a.kpi:hover { border-color: var(--ink-soft); }
.kpi .v { font-family: var(--mono); font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--ink-soft); }
.kpi.alarm .v { color: var(--red); }

/* ---------- Przyciski i pola ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--ink); color: #fff; border: 1px solid var(--ink); padding: 6px 12px; font-size: 12.5px; font-weight: 600; border-radius: var(--r); cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--ink-deep); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--paper2); border-color: var(--ink-soft); }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #8E3924; }
.btn-brass { background: var(--brass); border-color: var(--brass); color: #fff; }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-lg { padding: 10px 18px; font-size: 14px; }
.btn svg { width: 14px; height: 14px; }
.linkbtn { background: none; border: none; color: var(--blue); cursor: pointer; padding: 0; font-size: inherit; text-decoration: underline; text-underline-offset: 2px; }

.in, select.in, textarea.in {
  width: 100%; padding: 6px 9px; border: 1px solid var(--line); background: var(--card); border-radius: var(--r); font-size: 13px; min-height: 32px;
}
/* pole tekstowe, lista i data w jednym pasku mają tę samą wysokość (32 px); moduły mogą zmniejszyć min-height i padding */
input.in { line-height: 18px; }
input.in[type=date] { line-height: 16px; } /* Chrome dodaje 2 px wewnątrz pola daty */
.in:focus { outline: 2px solid var(--brass); outline-offset: -1px; }
textarea.in { min-height: 70px; resize: vertical; line-height: 1.45; }
.in.mono { font-family: var(--mono); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .lbl { font-size: 12px; color: var(--ink-soft); font-weight: 500; }
.field .pomoc { font-size: 11.5px; color: var(--dim); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .pelna { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.check input { width: 15px; height: 15px; accent-color: var(--ink); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .in, .toolbar select.in { width: auto; min-width: 140px; }
.toolbar .szukaj { min-width: 240px; flex: 1; max-width: 420px; }
.toolbar .prawa { margin-left: auto; display: flex; gap: 6px; }

/* przełącznik (np. reguła włączona) */
.switch { position: relative; display: inline-block; width: 32px; height: 18px; flex: 0 0 32px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #C9CCC4; border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ''; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(14px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }

/* ---------- Tabele ---------- */
.tbl-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-soft); font-size: 12px; padding: 8px 10px; background: var(--paper2); border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--line2); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.klik { cursor: pointer; }
.tbl tr.klik:hover td { background: #FAFAF7; }
.tbl tr.zaznaczony td { background: var(--brass-bg); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl th.num { font-family: var(--sans); } /* nagłówki kolumn liczbowych bez kroju mono */
.tbl .w1 { width: 1%; white-space: nowrap; }
.tbl .sub { display: block; font-size: 11.5px; color: var(--dim); }

/* ---------- Statusy, tagi, plakietki ---------- */
.st { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; padding: 2px 8px 2px 7px; border-radius: 999px; background: var(--paper2); border: 1px solid var(--line); }
.st::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c, #8A93A0); flex: 0 0 8px; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 3px; background: var(--paper2); border: 1px solid var(--line); color: var(--ink-soft); white-space: nowrap; }
.tag.ok { background: var(--green-bg); color: var(--green); border-color: transparent; }
.tag.warn { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.tag.bad { background: var(--red-bg); color: var(--red); border-color: transparent; }
.tag.info { background: var(--blue-bg); color: var(--blue); border-color: transparent; }
.tag.brass { background: var(--brass-bg); color: #7A5A12; border-color: transparent; }
.tag.demo { background: #7A5A12; color: #FFF3D6; border-color: transparent; }
.sklep { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; white-space: nowrap; }
.sklep::before { content: ''; width: 3px; height: 13px; background: var(--c, #55606F); border-radius: 1px; }

/* baner (np. „dane demo”) */
.baner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--r); background: var(--brass-bg); border: 1px solid #E8D9AE; color: #5B4410; margin-bottom: 14px; font-size: 12.5px; }
.baner b { font-weight: 600; }
.baner.info { background: var(--blue-bg); border-color: #C9D8E8; color: #23405F; }
.baner.bad { background: var(--red-bg); border-color: #EBC7BC; color: #7E2F1C; }

/* zakładki */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--ink-soft); font-weight: 500; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brass); }
.tabs .licznik { font-family: var(--mono); font-size: 11px; color: var(--dim); margin-left: 4px; }

/* lista boczna (np. statusy z licznikami obok listy zamówień) */
.uklad-lista { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .uklad-lista { grid-template-columns: 1fr; } }
.boczna { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 6px; position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow-y: auto; }
.boczna .grupa { font-size: 11.5px; font-weight: 600; color: var(--dim); padding: 10px 8px 4px; }
.boczna a { display: flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 3px; color: var(--ink); text-decoration: none; font-size: 12.5px; }
.boczna a:hover { background: var(--paper2); }
.boczna a.on { background: var(--brass-bg); }
.boczna a .kropka { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #8A93A0); flex: 0 0 8px; }
.boczna a .n { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--ink-soft); }
.boczna a.pusty { color: var(--dim); }

/* oś czasu (historia zamówienia, dziennik) */
.os { display: flex; flex-direction: column; }
.os .wpis { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line2); font-size: 12.5px; }
.os .wpis:last-child { border-bottom: 0; }
.os .kiedy { font-family: var(--mono); font-size: 11.5px; color: var(--dim); }
.os .kto { font-size: 11.5px; color: var(--dim); }

/* puste stany */
.pusto { padding: 30px 16px; text-align: center; color: var(--ink-soft); }
.pusto b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; }

/* definicje (etykieta: wartość) */
.def { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 5px 12px; font-size: 12.5px; }
.def dt { color: var(--ink-soft); }
.def dd { min-width: 0; overflow-wrap: anywhere; }
.def .sub { display: block; font-size: 11.5px; color: var(--dim); } /* druga linia wartości, jak w tabelach */

/* ---------- Modal ---------- */
#modal-root .tlo { position: fixed; inset: 0; background: rgba(23,29,38,.42); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto; }
.modal { background: var(--card); border: 1px solid var(--line); width: 640px; max-width: 100%; border-radius: var(--r); box-shadow: 0 10px 40px rgba(23,29,38,.2); display: flex; flex-direction: column; max-height: 88vh; }
.modal.szeroki { width: 980px; }
.modal.waski { width: 440px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line2); }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { margin-left: auto; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-soft); line-height: 1; padding: 0 4px; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 11px 16px; border-top: 1px solid var(--line2); background: var(--paper2); }
.modal-foot .lewa { margin-right: auto; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; right: 18px; top: 62px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 9px 14px; border-radius: var(--r); font-size: 12.5px; box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: 380px; animation: mpop .14s ease-out; }
.toast.bad { background: var(--red); }
.toast.ok { background: var(--green); }
