/* Kolory marki TRANS-MAR (z logo: ciepła szarość + miodowa żółć) */
:root {
  --brand-yellow: #D4BC2F;
  --brand-yellow-hover: #B8A226;
  --brand-yellow-soft: #FAF3C8;
  --brand-gray: #9B9B95;
  --brand-gray-dark: #5C5C58;
  --brand-gray-darker: #3A3A37;
}

/* Reset i podstawy */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f5f5f7;
}

a { color: var(--brand-gray-dark); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--brand-gray-darker); }

/* Topbar */
.topbar {
  background: var(--brand-gray-darker);
  color: #fff;
  padding: 0.5rem 1rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto;
  align-items: center;
  gap: 0.25rem 0.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  grid-column: 1;
  grid-row: 1;
  white-space: nowrap;
}
.topbar nav {
  display: flex;
  gap: 0.15rem;
  flex-wrap: nowrap;
  grid-column: 2;
  grid-row: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
  color: #ccc;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  font-size: 0.9rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.topbar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.topbar nav a.active { background: var(--brand-yellow); color: var(--brand-gray-darker); font-weight: 600; }
@media (max-width: 600px) {
  .topbar {
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    padding: 0.5rem 0.75rem;
  }
  .topbar .brand { grid-column: 1; grid-row: 1; }
  .user-menu { grid-column: 2; grid-row: 1; margin-left: 0; justify-self: end; }
  .topbar nav { grid-column: 1 / -1; grid-row: 2; }
}

/* Dolny pasek nawigacji — tylko mobile, w zasięgu kciuka */
.bottom-nav { display: none; }
@media (max-width: 600px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 20;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    padding: 0.2rem 0 calc(0.2rem + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    padding: 0.3rem 0;
    font-size: 0.7rem;
    color: #777;
    text-decoration: none;
    min-height: 48px;
  }
  .bottom-nav a .bn-ico { font-size: 1.15rem; line-height: 1; filter: grayscale(0.4); }
  .bottom-nav a.active { color: var(--brand-gray-darker); font-weight: 600; }
  .bottom-nav a.active .bn-ico { filter: none; }
  /* Miejsce na pasek, by nie zasłaniał treści (tylko gdy pasek istnieje) */
  body:has(.bottom-nav) { padding-bottom: 60px; }
}

/* Container */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem;
}
@media (max-width: 600px) {
  .container { padding: 0.75rem; }
}

h1 { margin: 1rem 0 1.25rem; font-size: 1.6rem; }
h2 { margin: 1.5rem 0 0.75rem; font-size: 1.25rem; }
h3 { margin: 1rem 0 0.5rem; font-size: 1.05rem; }
@media (max-width: 600px) {
  h1 { font-size: 1.3rem; margin: 0.75rem 0 1rem; }
  h2 { font-size: 1.1rem; }
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* Grid */
.grid { display: grid; gap: 0.75rem; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; } /* 2×2 na telefonie */
}
@media (max-width: 340px) {
  .grid-4 { grid-template-columns: 1fr; }
}

/* Stat cards */
.stat-card {
  background: #fff;
  padding: 1.25rem;
  border-radius: 12px;
  border: 1px solid #e5e5e7;
  text-align: center;
  display: block;
  color: inherit;
}
.stat-card:hover { border-color: var(--brand-yellow); text-decoration: none; }
.stat-num { font-size: 2.4rem; font-weight: 700; color: var(--brand-gray-dark); line-height: 1; }
.stat-label { color: #666; margin-top: 0.5rem; font-size: 0.9rem; }
@media (max-width: 700px) {
  .stat-card { padding: 1rem; }
  .stat-num { font-size: 1.9rem; }
}

/* Forms */
.form { display: flex; flex-direction: column; gap: 0.85rem; max-width: 800px; }
.form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.form label > span { color: #444; font-weight: 500; }
.form label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; }
.form input, .form select, .form textarea {
  padding: 0.55rem 0.65rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font: inherit;
  background: #fff;
  width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: 2px solid var(--brand-yellow);
  outline-offset: 1px;
  border-color: var(--brand-yellow);
}
@media (max-width: 700px) {
  /* iOS nie powiększa inputów z font-size >= 16px */
  .form input, .form select, .form textarea {
    font-size: 16px;
    min-height: 44px;
  }
  .form textarea { min-height: auto; }
}
/* Wyłącz checkbox/radio z generycznego stylu .form input (inaczej rozjeżdżają
   się do 100% szerokości i 44 px wysokości na mobile). */
.form input[type=checkbox], .form input[type=radio] {
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  accent-color: var(--brand-yellow);
  cursor: pointer;
  flex-shrink: 0;
}
@media (max-width: 700px) {
  .form input[type=checkbox], .form input[type=radio] {
    width: 1.3rem;
    height: 1.3rem;
    min-height: 0;
  }
}
.form label.checkbox { cursor: pointer; }
.form label.checkbox > span { font-weight: 400; color: #1a1a1a; }
.form fieldset {
  border: 1px dashed #bbb;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin: 0;
}
.form fieldset legend { padding: 0 0.5rem; color: #666; font-size: 0.85rem; }
/* Grupa pól wyboru łamana w poziomie — kompaktuje filtry (np. statusy w statystyce). */
.check-row { display: flex; flex-wrap: wrap; gap: 0.35rem 1.1rem; }
.check-row label.checkbox { white-space: nowrap; }

/* Pasek filtrowania list (szukaj klienta + zakres dat) */
.list-filter { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; margin: 0.75rem 0; }
.list-filter input[type="search"] { min-width: 180px; flex: 1 1 180px; }
.list-filter select, .list-filter input[type="date"] { min-height: 36px; }
.list-filter .list-filter-range { display: flex; flex-direction: column; gap: 0.1rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid #ccc;
  background: #fff;
  color: #1a1a1a;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  min-height: 38px;
}
.btn:hover { background: #f0f0f2; text-decoration: none; }
.btn-primary { background: var(--brand-gray-dark); color: #fff; border-color: var(--brand-gray-dark); }
.btn-primary:hover { background: var(--brand-gray-darker); border-color: var(--brand-gray-darker); color: #fff; }
.btn-accent { background: var(--brand-yellow); color: var(--brand-gray-darker); border-color: var(--brand-yellow); font-weight: 600; }
.btn-accent:hover { background: var(--brand-yellow-hover); border-color: var(--brand-yellow-hover); color: var(--brand-gray-darker); }
.btn-danger { background: #d33; color: #fff; border-color: #d33; }
.btn-danger:hover { background: #b22; }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.85rem; min-height: 30px; }
@media (max-width: 700px) {
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
}

.actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 0.5rem; }

/* Duży przycisk akcji głównej (np. następny status) */
.btn-lg { padding: 0.7rem 1.4rem; font-size: 1.05rem; min-height: 48px; font-weight: 600; }

/* Pasek akcji etapu: akcja główna dominuje, reszta drugorzędna */
.stage-actions { margin: 0 0 1.5rem; }
.stage-primary { margin: 0 0 0.6rem; }
.stage-secondary { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.stage-secondary form { display: inline; margin: 0; }
@media (max-width: 700px) {
  /* Na telefonie akcja główna na pełną szerokość — w zasięgu kciuka */
  .stage-primary, .stage-primary .btn { display: block; width: 100%; }
}

/* Stepper etapów produkcji */
.stepper {
  display: flex;
  list-style: none;
  padding: 0.25rem 0 0;
  margin: 0 0 1.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.stepper::-webkit-scrollbar { display: none; }
.stepper-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1 0 auto;
  min-width: 88px;
  position: relative;
  padding: 0 0.25rem;
  color: #999;
  font-size: 0.76rem;
  line-height: 1.2;
}
/* łącznik do poprzedniego kroku */
.stepper-step::before {
  content: '';
  position: absolute;
  top: 13px;
  left: -50%;
  width: 100%;
  height: 2px;
  background: #ddd;
  z-index: 0;
}
.stepper-step:first-child::before { display: none; }
.stepper-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eee;
  border: 2px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  color: #999;
  position: relative;
  z-index: 1;
  margin-bottom: 0.35rem;
}
.stepper-step.done { color: var(--brand-gray-dark); }
.stepper-step.done .stepper-dot {
  background: var(--brand-gray-dark);
  border-color: var(--brand-gray-dark);
  color: #fff;
}
.stepper-step.done::before { background: var(--brand-gray-dark); }
.stepper-step.current { color: var(--brand-gray-darker); font-weight: 700; }
.stepper-step.current .stepper-dot {
  background: var(--brand-yellow);
  border-color: var(--brand-yellow-hover);
  color: var(--brand-gray-darker);
  box-shadow: 0 0 0 3px var(--brand-yellow-soft);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.5rem 0;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  /* Wskaźnik scrolla: gradient po prawej i lewej pokazuje, że można przewijać */
  background:
    linear-gradient(90deg, #fff 30%, rgba(255,255,255,0)) left center / 24px 100% no-repeat,
    linear-gradient(-90deg, #fff 30%, rgba(255,255,255,0)) right center / 24px 100% no-repeat,
    linear-gradient(90deg, rgba(0,0,0,0.15), rgba(0,0,0,0)) left center / 12px 100% no-repeat,
    linear-gradient(-90deg, rgba(0,0,0,0.15), rgba(0,0,0,0)) right center / 12px 100% no-repeat,
    #fff;
  background-attachment: local, local, scroll, scroll;
}
.table-wrap > .data { margin: 0; box-shadow: none; border-radius: 0; background: transparent; }
@media (max-width: 700px) {
  /* Na mobile pokazujemy zawsze pasek scrolla, żeby było widać, że tabela się przewija */
  .table-wrap { scrollbar-width: thin; scrollbar-color: #bbb #f0f0f0; }
  .table-wrap::-webkit-scrollbar { height: 6px; }
  .table-wrap::-webkit-scrollbar-thumb { background: #bbb; border-radius: 3px; }
  .table-wrap::-webkit-scrollbar-track { background: #f0f0f0; }
  /* Nie zawijaj zawartości komórek — niech tabela wyraźnie wystaje, żeby gradient zadziałał */
  .data th, .data td { white-space: nowrap; }
  /* Wyjątek: kolumny tekstowe, gdzie zawijanie jest pożądane */
  .data td.wrap, .data th.wrap { white-space: normal; }
}

/* Karta-na-wiersz dla list mobilnych
   Dodaj klasę .cards-on-mobile do <table class="data">, a komórki opisz przez data-label="...".
   Najważniejszą kolumnę oznacz dodatkową klasą .card-title, kolumny z akcjami klasą .card-actions.
   Kolumny do ukrycia na mobile (np. numer porządkowy włączony w tytuł) → klasa .hide-mobile.
*/
.mobile-only { display: none; }
/* Producent w karcie farby — tylko na mobile (na desktopie jest kolumna „Dostawca”). */
.card-producent { display: none; }
/* Kontrolka sortowania widoczna tylko na mobile (na desktopie sortują nagłówki). */
.mobile-sort { display: none; }
@media (max-width: 700px) {
  .mobile-only { display: inline; }
  .mobile-hidden { display: none; }
  .card-producent { display: block; font-size: 0.85em; margin-top: 0.15rem; font-weight: normal; }
  .mobile-sort { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
  .mobile-sort .mobile-sort-field { flex: 2; display: flex; align-items: center; gap: 0.4rem; }
  .mobile-sort select { flex: 1; min-width: 0; }

  /* Wycisz kontener-tabeli, gdy w środku karty — bez gradientu/scrolla */
  .table-wrap:has(> .data.cards-on-mobile) {
    overflow: visible;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    margin: 0.5rem 0;
  }
  .table-wrap:has(> .data.cards-on-mobile)::-webkit-scrollbar { display: none; }

  .data.cards-on-mobile {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    font-size: 0.95rem;
  }
  .data.cards-on-mobile thead { display: none; }
  .data.cards-on-mobile,
  .data.cards-on-mobile tbody,
  .data.cards-on-mobile tr { display: block; width: 100%; }
  /* display:block powyżej bije atrybut [hidden] — przywróć ukrywanie wierszy edycji. */
  .data.cards-on-mobile tr[hidden] { display: none; }

  .data.cards-on-mobile tr {
    background: #fff;
    border: 1px solid #e5e5e7;
    border-radius: 10px;
    margin-bottom: 0.6rem;
    padding: 0.7rem 0.9rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  }
  .data.cards-on-mobile tr.row-warn {
    background: #fff8e8;
    border-color: #f0d98c;
  }
  .data.cards-on-mobile tr.row-archived {
    background: #f5f5f6;
    border-color: #d8d8da;
    opacity: 0.78;
  }

  .data.cards-on-mobile td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    border-bottom: none;
    padding: 0.3rem 0;
    text-align: right;
    white-space: normal;
  }
  .data.cards-on-mobile td::before {
    content: attr(data-label);
    color: #666;
    font-size: 0.85rem;
    font-weight: 500;
    flex-shrink: 0;
    text-align: left;
  }
  .data.cards-on-mobile td:not([data-label])::before,
  .data.cards-on-mobile td[data-label=""]::before { content: none; }

  /* Tytuł karty: najważniejsze pole, na pełną szerokość */
  .data.cards-on-mobile td.card-title {
    display: block;
    text-align: left;
    font-size: 1.05rem;
    font-weight: 600;
    border-bottom: 1px solid #eee;
    margin: -0.1rem -0.1rem 0.45rem;
    padding: 0 0 0.5rem;
  }
  .data.cards-on-mobile td.card-title::before { display: none; }
  .data.cards-on-mobile td.card-title a { color: var(--brand-gray-dark); }

  /* Akcje (przyciski) — wyrównane do prawej, odsunięte separatorem */
  .data.cards-on-mobile td.card-actions {
    justify-content: flex-end;
    margin-top: 0.4rem;
    padding-top: 0.5rem;
    border-top: 1px solid #eee;
  }
  .data.cards-on-mobile td.card-actions::before { display: none; }

  /* Kolumny, które na mobile chowamy całkiem (bo zawarte w tytule) */
  .data.cards-on-mobile td.hide-mobile,
  .data.cards-on-mobile th.hide-mobile { display: none; }

  /* tfoot w trybie kart — schowane (suma i tak jest w nagłówku sekcji) */
  .data.cards-on-mobile tfoot { display: none; }

  /* Pozycje zlecenia: na mobile formularz „+ Dodaj pozycję" na górę,
     żeby nie trzeba było przewijać listy pozycji przy dorzucaniu kolejnych. */
  .items-block { display: flex; flex-direction: column; }
  .items-block .add-item { order: -1; margin-bottom: 1rem; }

  /* Rozwijalne karty: dodaj klasę .expandable do <table class="data cards-on-mobile">
     Komórki z .hide-when-collapsed są ukryte do czasu, aż użytkownik dotknie kartę.
     Strzałka ▾ obraca się przy rozwinięciu. */
  .data.cards-on-mobile.expandable tr { cursor: pointer; user-select: none; position: relative; }
  .data.cards-on-mobile.expandable tr td.card-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    border-bottom: none;
    margin-bottom: 0;
    padding: 0 1.4rem 0 0;
    text-align: left;
  }
  .data.cards-on-mobile.expandable tr td.card-title .card-name {
    flex: 1;
    font-weight: 600;
    font-size: 1.05rem;
  }
  .data.cards-on-mobile.expandable tr td.card-title .card-summary {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
  }
  /* Strzałka — wskaźnik rozwijalności */
  .data.cards-on-mobile.expandable tr td.card-title::after {
    content: '';
    position: absolute;
    right: 0.85rem;
    top: 50%;
    width: 8px;
    height: 8px;
    border-right: 2px solid #888;
    border-bottom: 2px solid #888;
    transform: translateY(-75%) rotate(45deg);
    transition: transform 0.15s ease;
  }
  .data.cards-on-mobile.expandable tr.expanded td.card-title {
    border-bottom: 1px solid #eee;
    margin-bottom: 0.5rem;
    padding-bottom: 0.55rem;
  }
  .data.cards-on-mobile.expandable tr.expanded td.card-title::after {
    transform: translateY(-25%) rotate(225deg);
  }
  /* Komórki ukrywane do rozwinięcia */
  .data.cards-on-mobile.expandable tr:not(.expanded) td.hide-when-collapsed { display: none; }
  /* Po rozwinięciu — schowaj duplikat ze streszczenia w tytule */
  .data.cards-on-mobile.expandable tr.expanded .card-summary { display: none; }
}
.data {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  font-size: 0.92rem;
  margin: 0.5rem 0;
}
.data th, .data td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
.data th { background: #fafafa; font-weight: 600; color: #555; font-size: 0.85rem; }
/* Nagłówki sortujące — klikalny link w <th>, dziedziczy wygląd nagłówka. */
.data th a.sort { color: inherit; text-decoration: none; cursor: pointer; display: inline-flex; align-items: center; gap: 0.25rem; white-space: nowrap; }
.data th a.sort:hover { color: var(--brand-gray-darker); text-decoration: underline; }
.data th a.sort.active { color: var(--brand-gray-darker); }
.data th a.sort .sort-ind { font-size: 0.7em; opacity: 0.8; }
/* Wąska kolumna m² (lista zleceń) — minimalna szerokość, liczba do prawej. */
.data th.col-m2, .data td.col-m2 { width: 1%; white-space: nowrap; text-align: right; }
.data tfoot td { background: #fafafa; }
.data tr:last-child td { border-bottom: none; }
/* Akcje wiersza (Edytuj + Usuń) obok siebie — bez tego form spada pod przycisk. */
.data td.card-actions { display: flex; gap: 0.4rem; align-items: center; }
.row-warn { background: #fff8e8; }
.row-archived { background: #f5f5f6; color: #777; }
.row-archived a { color: #555; }
.data tr.clickable-row { cursor: pointer; }
.data tr.clickable-row:hover { background: #f3f6fb; }
.data tr.clickable-row.row-warn:hover { background: #fdf3da; }
.data tr.clickable-row.row-archived:hover { background: #eeeef0; }

.banner {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  margin: 0.5rem 0 1rem;
  font-size: 0.95rem;
}
.banner-archived {
  background: #f0f0f2;
  border: 1px solid #d8d8da;
  color: #555;
}
@media (max-width: 700px) {
  .data { font-size: 0.85rem; }
  .data th, .data td { padding: 0.45rem 0.5rem; }
}

/* Cards (collapsible) */
.card {
  background: #fff;
  border: 1px solid #e5e5e7;
  border-radius: 10px;
  padding: 0.5rem 1rem;
  margin: 1rem 0;
}
.card summary {
  cursor: pointer;
  padding: 0.4rem 0;
  user-select: none;
}
.card[open] summary { border-bottom: 1px solid #eee; margin-bottom: 0.75rem; }

/* Badges — wszystkie typy używane w aplikacji */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  background: #eee;
  color: #444;
}

.badge-archived { background: #e0e0e0; color: #555; }

/* etapy produkcji */
.badge-oczekuje { background: #f0f0f0; color: #555; }
.badge-piaskowanie { background: #ffe5b4; color: #8a4a00; }
.badge-malowanie { background: #c4e0ff; color: #0a4ba0; }
.badge-wypiek { background: #ffd0c4; color: #a83000; }
.badge-kontrola { background: #f5d0ff; color: #6a0a90; }
.badge-gotowe { background: #d0f4d8; color: #1a6a25; }
.badge-gotowe_do_odbioru { background: #d0f4d8; color: #1a6a25; }
.badge-powiadomiony { background: #d8ecff; color: #0a4ba0; }
.badge-odebrane { background: #d0d0d0; color: #555; }
.badge-rozliczone { background: #cfe8d4; color: #15602a; }

/* etapy pracy */
.badge-pakowanie { background: #e0d0ff; color: #4a0a90; }
.badge-inne { background: #e0e0e0; color: #555; }

/* role pracowników */
.badge-produkcja { background: #ffe5b4; color: #8a4a00; }
.badge-biuro { background: #d8e8ff; color: #0a4ba0; }
.badge-wlasciciel { background: #ffd4d4; color: #8a0000; }

/* typy wydarzeń kalendarza */
.badge-przyjecie { background: #d4f4d8; color: #1a6a25; }
.badge-odbior { background: #ffd4d4; color: #8a0000; }
.badge-piec { background: #ffd0c4; color: #a83000; }
.badge-dostawa_farby { background: #d8e8ff; color: #0a4ba0; }

/* statusy reklamacji */
.badge-open { background: #ffe0c4; color: #b85b00; }
.badge-resolved { background: #d4f4d8; color: #1a6a25; }
.badge-rejected { background: #e0e0e0; color: #555; }

/* statusy wsadów */
.badge-planned { background: #fff4d4; color: #8a6700; }
.badge-in_oven { background: #ffd0c4; color: #a83000; }

/* fazy zdjęć */
.badge-before { background: #ffe5b4; color: #8a4a00; }
.badge-after { background: #d0f4d8; color: #1a6a25; }

.badge-regular { background: #fff0c4; color: #8a6700; }

/* Sygnalizacja nieprzeczytanych zmian */
.badge-new { background: var(--brand-yellow); color: var(--brand-gray-darker); font-weight: 700; }

/* statusy zleceń */
.badge-przyjete { background: #d8e8ff; color: #0a4ba0; }
.badge-w_realizacji { background: #ffe0c4; color: #b85b00; }

/* Sub-nav modułu (np. „Lista zleceń · Słownik kształtów") */
.subnav {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.5rem 0;
  margin: 0.25rem 0 0.75rem;
  border-bottom: 1px solid #e5e5e7;
  flex-wrap: wrap;
}
.subnav a {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  color: var(--brand-gray-dark);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid transparent;
}
.subnav a:hover { background: #f0f0f2; color: #1a1a1a; text-decoration: none; }
.subnav a.active {
  background: var(--brand-yellow-soft);
  border-color: var(--brand-yellow);
  color: var(--brand-gray-darker);
  font-weight: 700;
}
.subnav-count {
  background: var(--brand-gray);
  color: #fff;
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 0.05rem 0.45rem;
  font-weight: 600;
  line-height: 1.4;
}
.subnav a.active .subnav-count {
  background: var(--brand-gray-darker);
  color: var(--brand-yellow);
}
@media (max-width: 600px) {
  .subnav { gap: 0.3rem; margin: 0.15rem 0 0.5rem; }
  .subnav a { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
}

/* Zakładki filtrowania statusów */
.status-tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin: 0.75rem 0 0;
  border-bottom: 2px solid #e5e5e7;
  padding-bottom: 0;
}
.status-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border-radius: 8px 8px 0 0;
  font-size: 0.9rem;
  color: #555;
  border: 1px solid transparent;
  border-bottom: none;
  margin-bottom: -2px;
  text-decoration: none;
  white-space: nowrap;
}
.status-tabs a:hover { background: #f0f0f2; color: #1a1a1a; }
.status-tabs a.active {
  background: #fff;
  color: #1a1a1a;
  border-color: #e5e5e7;
  font-weight: 600;
}
.tab-count {
  background: #e0e0e0;
  color: #555;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 0.05rem 0.4rem;
  font-weight: 600;
}
.status-tabs a.active .tab-count { background: var(--brand-yellow); color: var(--brand-gray-darker); }
@media (max-width: 600px) {
  /* Na mobile odchodzimy od metafory zakładek (jeden rząd) na rzecz
     segmented controla — siatka 3×2 z pigułkami. Bez horyzontalnego scrolla,
     wszystkie filtry zawsze widoczne. */
  .status-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
    border-bottom: 0;
    padding-bottom: 0;
    margin: 0.5rem 0 1rem;
  }
  .status-tabs a {
    justify-content: center;
    text-align: center;
    padding: 0.5rem 0.5rem;
    border-radius: 999px;
    border: 1px solid #d8d8d8;
    margin-bottom: 0;
    background: #fff;
    font-size: 0.85rem;
    line-height: 1.15;
    white-space: normal;
    min-height: 38px;
  }
  .status-tabs a.active {
    background: var(--brand-yellow);
    border-color: var(--brand-yellow-hover);
    color: var(--brand-gray-darker);
  }
  .status-tabs a.active .tab-count {
    background: var(--brand-gray-darker);
    color: var(--brand-yellow);
  }
  .tab-count {
    font-size: 0.7rem;
    padding: 0.05rem 0.35rem;
  }
}

/* Siatka zdjęć */
.photo-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.5rem 0;
}
.photo-thumb {
  width: 140px;
}
.photo-thumb img {
  width: 140px;
  height: 100px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #e5e5e7;
  display: block;
}
.photo-thumb p { margin: 0.25rem 0; }
.photo-thumb img { cursor: zoom-in; }

/* Lightbox (otwierany przez :target via #foto-id) */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.lightbox:target { display: flex; }
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  cursor: zoom-out;
}
.lightbox-content {
  position: relative;
  z-index: 1;
  max-width: 95vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lightbox-content img {
  max-width: 95vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}
.lightbox-caption {
  color: #fff;
  margin: 0.75rem 0 0;
  text-align: center;
}
.lightbox-close {
  position: absolute;
  top: -2.5rem;
  right: -0.25rem;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  line-height: 1;
  color: #fff;
  text-decoration: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.3); }
@media (max-width: 600px) {
  .lightbox-close { top: -0.25rem; right: -0.25rem; }
}

/* Logowanie */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f7;
  padding: 1rem;
}
.login-box {
  background: #fff;
  border: 1px solid #e5e5e7;
  border-radius: 14px;
  padding: 2rem 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
@media (max-width: 440px) {
  .login-wrap { align-items: flex-start; padding-top: 2rem; }
  .login-box { padding: 1.75rem 1.25rem; border-radius: 12px; }
}
/* iOS — zapobiegaj zoomowi na inputach logowania */
.login-box input { font-size: 16px; min-height: 44px; }
.login-brand {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
  color: #1a1a1a;
}
.login-title {
  font-size: 1.1rem;
  color: #666;
  text-align: center;
  margin: 0 0 1.5rem;
  font-weight: 400;
}
.alert-error {
  background: #ffd4d4;
  color: #8a0000;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.alert-success {
  background: #d4f4d8;
  color: #1a6a25;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* Topbar — menu użytkownika po prawej (rozwijane) */
.user-menu {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}
.user-menu > summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  list-style: none;
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  color: #ddd;
  font-size: 0.85rem;
  white-space: nowrap;
  min-height: 36px;
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary::marker { content: ''; }
.user-menu > summary:hover { background: rgba(255,255,255,0.08); }
.user-menu[open] > summary { background: rgba(255,255,255,0.12); }
.user-name { font-weight: 500; color: #fff; }
.user-menu-caret {
  width: 7px; height: 7px;
  border-right: 2px solid #bbb;
  border-bottom: 2px solid #bbb;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.user-menu[open] .user-menu-caret { transform: rotate(-135deg) translateY(1px); }
.user-menu-panel {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.35rem;
  min-width: 184px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 0.3rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.user-menu-panel form { margin: 0; }
.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0.65rem 0.7rem;
  border-radius: 7px;
  font: inherit;
  color: #1a1a1a;
  cursor: pointer;
  text-decoration: none;
}
.user-menu-item:hover { background: #f0f0f2; text-decoration: none; }
@media (max-width: 700px) {
  .user-menu > summary { min-height: 44px; }
  .user-menu-item { padding: 0.8rem 0.7rem; }
}

/* Misc */
.muted { color: #666; }
.text-success { color: #2a7a2a; }
.text-warn { color: #b85b00; }
.text-danger { color: #c00; }
small { font-size: 0.8rem; }
.small { font-size: 0.85rem; }

/* Listy wydarzeń */
.event-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}
.event-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid #eee;
}
.event-list li:last-child { border-bottom: none; }

/* Bar progress */
.bar {
  background: #eee;
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.bar-fill {
  background: linear-gradient(90deg, var(--brand-gray-dark), var(--brand-yellow));
  height: 100%;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bar-row .bar { flex: 1; }
.bar-pct {
  min-width: 3ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted, #666);
  font-size: 0.85em;
}

/* Kanban */
.kanban {
  display: grid;
  grid-template-columns: repeat(7, minmax(180px, 1fr));
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 1rem;
}
.kanban-col {
  background: #ececef;
  border-radius: 10px;
  padding: 0.5rem;
  min-height: 200px;
}
.kanban-head {
  font-size: 0.9rem;
  padding: 0.25rem 0.5rem 0.5rem;
  border-bottom: 1px solid #d0d0d3;
  margin-bottom: 0.5rem;
}
.kanban-card {
  background: #fff;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.5rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  font-size: 0.9rem;
}
.kanban-actions {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.4rem;
  justify-content: flex-end;
}
.kanban-empty {
  text-align: center;
  font-style: italic;
  padding: 1rem 0;
  font-size: 0.85rem;
}
@media (max-width: 1100px) {
  .kanban { grid-template-columns: repeat(4, minmax(220px, 1fr)); }
}

/* Kalendarz */
.cal-nav { display: flex; gap: 0.5rem; margin-bottom: 1rem; align-items: center; }
.cal-grid {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
}
.cal-grid th {
  padding: 0.5rem;
  background: #fafafa;
  font-weight: 600;
  text-align: center;
  font-size: 0.85rem;
  border-bottom: 1px solid #eee;
  color: #555;
}
.cal-grid td {
  border: 1px solid #eee;
  height: 90px;
  vertical-align: top;
  padding: 0.3rem;
  font-size: 0.85rem;
}
.cal-grid td.other-month { background: #fafafa; color: #aaa; }
.cal-day-num { font-weight: 600; margin-bottom: 0.2rem; }
.cal-day-num a { color: inherit; }
.cal-ev {
  background: #f0f4ff;
  border-radius: 4px;
  padding: 1px 4px;
  margin-bottom: 2px;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* File upload — ładny dropzone zamiast natywnego "Choose file" */
.file-upload {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex: 1;
  min-width: 240px;
  padding: 0.9rem 1rem;
  border: 2px dashed #ccc;
  border-radius: 12px;
  background: #fafafa;
  cursor: pointer;
  transition: border-color 150ms, background 150ms, transform 80ms;
}
.file-upload:hover {
  border-color: var(--brand-yellow);
  background: var(--brand-yellow-soft);
}
.file-upload.is-dragover {
  border-color: var(--brand-yellow-hover);
  background: var(--brand-yellow-soft);
  transform: scale(1.01);
}
.file-upload.has-file {
  border-style: solid;
  border-color: var(--brand-yellow-hover);
  background: #fff;
}
/* Ukryj natywny input — klikamy w cały label */
.file-upload input[type=file] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.file-upload-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fff;
  color: var(--brand-gray-dark);
  border: 1px solid #e5e5e7;
}
.file-upload.has-file .file-upload-icon {
  color: var(--brand-yellow-hover);
  border-color: var(--brand-yellow);
}
.file-upload-icon svg { width: 20px; height: 20px; display: block; }
.file-upload-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  flex: 1;
}
.file-upload-title {
  font-weight: 600;
  color: #1a1a1a;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-upload-hint {
  color: #777;
  font-size: 0.8rem;
}
.photo-upload-form {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}
.photo-upload-form .btn { align-self: stretch; }

/* Spinner w przycisku podczas wysyłki (np. upload zdjęć) */
.btn.is-loading { pointer-events: none; opacity: 0.85; gap: 0.5rem; }
.btn.is-loading::before {
  content: "";
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* Kafle zadań na pulpicie produkcji */
.task-cards { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.task-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: #fff;
  border: 1px solid #e5e5e7;
  border-radius: 10px;
  padding: 0.8rem 1rem;
  color: inherit;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  min-height: 56px;
}
.task-card:hover { border-color: var(--brand-yellow); text-decoration: none; }
.task-card-danger { border-color: #f0b4b4; background: #fff6f6; }
.task-card-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.task-card-client { font-weight: 600; color: var(--brand-gray-darker); }
.task-card-meta { color: #777; font-size: 0.85rem; }
.task-card .badge { flex-shrink: 0; }

/* Wątek uwag biuro↔produkcja */
.msg-thread {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0.5rem 0 1rem;
}
.msg {
  background: #fff;
  border: 1px solid #e5e5e7;
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  max-width: 85%;
  align-self: flex-start;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.msg-mine {
  align-self: flex-end;
  background: var(--brand-yellow-soft);
  border-color: var(--brand-yellow);
}
.msg-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.2rem;
}
.msg-body { white-space: pre-wrap; line-height: 1.4; }
.badge-sm { font-size: 0.68rem; padding: 0.05rem 0.4rem; }
.msg-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.msg-form textarea {
  flex: 1;
  min-width: 220px;
  padding: 0.55rem 0.65rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font: inherit;
  resize: vertical;
}
.msg-form textarea:focus {
  outline: 2px solid var(--brand-yellow);
  outline-offset: 1px;
  border-color: var(--brand-yellow);
}
@media (max-width: 700px) {
  .msg { max-width: 92%; }
  .msg-form textarea { font-size: 16px; }
  .msg-form .btn { min-height: 44px; }
}

/* Toast — jednorazowe powiadomienia po PRG */
.toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  font-weight: 500;
  max-width: 32rem;
  animation: toast-in 200ms ease-out;
}
.toast-success {
  background: #e3f5e6;
  color: #1b5e20;
  border: 1px solid #b6dfb9;
}
.toast-error {
  background: #fde7e9;
  color: #8a1c1c;
  border: 1px solid #f5c2c7;
}
.toast-msg { line-height: 1.3; }
.toast-close {
  background: transparent;
  border: 0;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  opacity: 0.65;
  padding: 0 0.25rem;
}
.toast-close:hover { opacity: 1; }
.toast-hide { animation: toast-out 400ms forwards; }
@keyframes toast-in {
  from { transform: translateY(-0.75rem); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateY(-0.75rem); opacity: 0; }
}
@media (max-width: 600px) {
  .toast { left: 0.5rem; right: 0.5rem; top: 0.5rem; max-width: none; }
}

/* Widok read-only szczegółu — lista par etykieta/wartość */
.dl { margin: 0.5rem 0; display: grid; gap: 0.5rem; }
.dl-row { display: grid; grid-template-columns: 13rem 1fr; gap: 0.25rem 1rem; align-items: baseline; }
.dl-row dt { margin: 0; font-weight: 600; color: #555; }
.dl-row dd { margin: 0; }
.dl-row dd.empty { color: #999; }
@media (max-width: 600px) {
  .dl-row { grid-template-columns: 1fr; gap: 0.1rem; }
  .dl-row dt { font-size: 0.85rem; }
  .dl-row dd { margin-bottom: 0.35rem; }
}
