/* ============================================================
   S5 — App layout overrides (LP Konstal, system 5S)
   Bazuje na tokens.css + components.css (design system Wycena Web).
   Tu tylko to, co specyficzne dla S5: mobile-first hala produkcyjna.
   ============================================================ */

/* ---------- User font-size scaling (9–24 pt, base 13 pt) ---------- */
:root {
  --font-scale: 1;

  --fs-11: calc(11px * var(--font-scale));
  --fs-12: calc(12px * var(--font-scale));
  --fs-13: calc(13px * var(--font-scale));
  --fs-14: calc(14px * var(--font-scale));
  --fs-15: calc(15px * var(--font-scale));
  --fs-16: calc(16px * var(--font-scale));
  --fs-18: calc(18px * var(--font-scale));
  --fs-20: calc(20px * var(--font-scale));
  --fs-24: calc(24px * var(--font-scale));
  --fs-32: calc(32px * var(--font-scale));
  --fs-44: calc(44px * var(--font-scale));
}

/* Font controls w toolbar */
.font-controls {
  display: inline-flex;
  background: var(--c-surface-1);
  border: 1px solid var(--c-surface-3);
  border-radius: var(--r-md);
  overflow: hidden;
}
.font-controls button {
  background: transparent; border: none; color: var(--c-text-muted);
  font: inherit; font-weight: var(--fw-medium);
  padding: 0 var(--s-2); height: 32px; min-width: 32px;
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
  white-space: nowrap;
}
.font-controls button:hover { background: var(--c-surface-2); color: var(--c-text); }
.font-controls button:not(:last-child) { border-right: 1px solid var(--c-surface-3); }
.font-controls button[aria-label="A+"] { font-size: 14px; }
.font-controls button[aria-label="A"]  { font-size: 13px; }
.font-controls button[aria-label="A-"] { font-size: 11px; }

/* ---------- Page wrappers ---------- */
.page {
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: var(--s-5) var(--s-5) var(--s-12);
}
.page--narrow { max-width: 760px; }
.page--auth   { max-width: 420px; padding-top: var(--s-12); }

/* ---------- Toolbar (top navigation bar) ---------- */
.toolbar { position: sticky; top: 0; z-index: var(--z-sticky); }
.toolbar__brand-link {
  color: inherit; text-decoration: none;
  display: inline-flex; align-items: center; gap: var(--s-3);
}
.toolbar__nav {
  display: flex; align-items: center; gap: var(--s-2);
  margin-left: var(--s-5);
}
.toolbar__nav a {
  color: var(--c-text-muted);
  text-decoration: none;
  padding: 6px var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-13); font-weight: var(--fw-medium);
  transition: color var(--dur-fast), background var(--dur-fast);
}
.toolbar__nav a:hover   { color: var(--c-text); background: var(--c-surface-2); }
.toolbar__nav a.is-active { color: var(--c-text); background: var(--c-surface-2); }
.toolbar__user { white-space: nowrap; }

/* Dropdown menu (CSS-only, <details>) */
.tb-menu { position: relative; }
.tb-menu > summary {
  list-style: none; cursor: pointer;
  color: var(--c-text-muted);
  padding: 6px var(--s-3); border-radius: var(--r-sm);
  font-size: var(--fs-13); font-weight: var(--fw-medium);
  display: inline-flex; align-items: center; gap: var(--s-1);
  transition: color var(--dur-fast), background var(--dur-fast);
}
.tb-menu > summary::-webkit-details-marker { display: none; }
.tb-menu > summary::after { content: "▾"; font-size: var(--fs-11); opacity: .7; }
.tb-menu > summary:hover { color: var(--c-text); background: var(--c-surface-2); }
.tb-menu[open] > summary { color: var(--c-text); background: var(--c-surface-2); }
.tb-menu__list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: var(--z-overlay);
  min-width: 220px;
  background: var(--c-surface-1);
  border: 1px solid var(--c-surface-3);
  border-radius: var(--r-md);
  box-shadow: var(--elev-pop);
  padding: var(--s-1);
  display: flex; flex-direction: column;
}
.tb-menu__list a {
  color: var(--c-text); text-decoration: none;
  padding: var(--s-2) var(--s-3); border-radius: var(--r-sm);
  font-size: var(--fs-13); white-space: nowrap;
}
.tb-menu__list a:hover { background: var(--c-surface-2); }

.toolbar__lang {
  appearance: none; -webkit-appearance: none;
  background: var(--c-surface-1); color: var(--c-text);
  border: 1px solid var(--c-surface-3); border-radius: var(--r-md);
  padding: 0 28px 0 var(--s-3); height: 32px;
  font-size: var(--fs-12); font-weight: var(--fw-medium);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%238b949e' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3 5 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.icon { width: 16px; height: 16px; stroke-width: 1.75; flex-shrink: 0; }
.icon--lg { width: 20px; height: 20px; }
.brand__mark { color: #fff; }

/* ---------- Headings / flash / forms ---------- */
.page-head { margin-bottom: var(--s-4); }
.page-head h1 { margin-bottom: var(--s-1); }
.flash { margin-bottom: var(--s-4); }
.form-actions {
  display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap;
  margin-top: var(--s-4);
}
.t-error { color: var(--c-red-500); }

.kv {
  display: grid; grid-template-columns: minmax(0, 240px) 1fr; gap: var(--s-2) var(--s-4);
  font-size: var(--fs-13);
}
.kv dt { color: var(--c-text-muted); font-size: var(--fs-11); text-transform: uppercase; letter-spacing: .04em; font-weight: var(--fw-semibold); align-self: center; }
.kv dd { margin: 0; color: var(--c-text); font-variant-numeric: tabular-nums; }

/* Tabele: inline inputs */
.table .input, .table select { height: 28px; padding: 0 var(--s-2); font-size: var(--fs-12); }
.table__actions form { display: inline; margin: 0; }

/* ============================================================
   S5 — komponenty mobile-first (hala: telefon / tablet)
   ============================================================ */

/* ---------- Kafelki modułów (home) ---------- */
.tile-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--s-3);
}
.tile {
  display: flex; flex-direction: column; gap: var(--s-1);
  background: var(--c-surface-1);
  border: 1px solid var(--c-surface-3);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  text-decoration: none; color: var(--c-text);
  min-height: 96px;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.tile:hover { background: var(--c-surface-2); border-color: var(--c-surface-4); }
.tile--primary { border-color: var(--c-primary); background: var(--c-tint-blue, rgba(83,155,245,.08)); }
.tile__icon { font-size: 24px; line-height: 1; }
.tile__title { font-size: var(--fs-15); font-weight: var(--fw-semibold); }
.tile__sub { font-size: var(--fs-12); color: var(--c-text-muted); }

/* ---------- Dolna nawigacja (mobile) ---------- */
.bottom-nav { display: none; }
@media (max-width: 767px) {
  .toolbar__nav--desktop { display: none; }
  body.has-bottom-nav { padding-bottom: 64px; }
  .bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: var(--z-sticky);
    display: flex; justify-content: space-around; align-items: stretch;
    background: var(--c-surface-0);
    border-top: 1px solid var(--c-surface-3);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .bottom-nav__item {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    gap: 2px; padding: var(--s-2) 0 var(--s-2);
    min-height: 56px; justify-content: center;
    color: var(--c-text-muted); text-decoration: none;
    font-size: var(--fs-11);
  }
  .bottom-nav__item:active, .bottom-nav__item:hover { color: var(--c-text); }
  .bottom-nav__icon { font-size: 20px; line-height: 1; }
}

/* ---------- Logowanie PIN: kafle operatorów ---------- */
.pin-users {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--s-2); max-height: 40vh; overflow-y: auto;
}
.pin-user { position: relative; display: block; cursor: pointer; }
.pin-user input { position: absolute; opacity: 0; }
.pin-user__name {
  display: flex; align-items: center; justify-content: center;
  min-height: 52px; padding: var(--s-2) var(--s-3);
  background: var(--c-surface-1);
  border: 1px solid var(--c-surface-3); border-radius: var(--r-md);
  font-size: var(--fs-14); font-weight: var(--fw-medium);
  text-align: center;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.pin-user input:checked + .pin-user__name {
  border-color: var(--c-primary);
  background: var(--c-tint-blue, rgba(83,155,245,.12));
  color: var(--c-text);
}
.input--pin {
  font-size: var(--fs-24); letter-spacing: .5em; text-align: center;
  height: 56px;
}

/* ---------- Checklista: karty pozycji + toggle TAK/NIE ---------- */
.check-card {
  background: var(--c-surface-1);
  border: 1px solid var(--c-surface-3);
  border-radius: var(--r-lg);
  padding: var(--s-3) var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-2);
}
.check-card__head { display: flex; align-items: baseline; gap: var(--s-2); flex-wrap: wrap; }
.check-card__label { font-weight: var(--fw-semibold); font-size: var(--fs-14); }
.check-card__question { color: var(--c-text-muted); font-size: var(--fs-13); }
.check-card--nok { border-color: var(--c-red-500, #e5534b); }

.yn { display: flex; gap: var(--s-2); }
.yn__opt { position: relative; flex: 1; cursor: pointer; }
.yn__opt input { position: absolute; opacity: 0; }
.yn__face {
  display: flex; align-items: center; justify-content: center;
  min-height: 48px; border-radius: var(--r-md);
  border: 1px solid var(--c-surface-3); background: var(--c-surface-0);
  font-size: var(--fs-15); font-weight: var(--fw-semibold);
  transition: border-color var(--dur-fast), background var(--dur-fast), color var(--dur-fast);
  user-select: none;
}
.yn__opt input:checked + .yn__face--yes {
  background: rgba(87,171,90,.15); border-color: var(--c-green-500, #57ab5a);
  color: var(--c-green-400, #57ab5a);
}
.yn__opt input:checked + .yn__face--no {
  background: rgba(229,83,75,.15); border-color: var(--c-red-500, #e5534b);
  color: var(--c-red-400, #e5534b);
}
.check-card__comment { display: none; }
.check-card__comment.is-open, .check-card__comment:focus-within { display: block; }

/* Sticky pasek zapisu na dole formularza (nad bottom-nav) */
.sticky-save {
  position: sticky; bottom: 0; z-index: 5;
  background: var(--c-bg);
  padding: var(--s-3) 0;
  border-top: 1px solid var(--c-surface-3);
}
@media (max-width: 767px) {
  body.has-bottom-nav .sticky-save { bottom: 64px; }
}

/* ---------- Ocena audytu 1–5 ---------- */
.score-pick { display: flex; gap: var(--s-2); }
.score-pick__opt { position: relative; flex: 1; cursor: pointer; }
.score-pick__opt input { position: absolute; opacity: 0; }
.score-pick__face {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; border-radius: var(--r-md);
  border: 1px solid var(--c-surface-3); background: var(--c-surface-0);
  font-size: var(--fs-18); font-weight: var(--fw-bold);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.score-pick__face small { font-size: var(--fs-11); font-weight: var(--fw-medium); color: var(--c-text-muted); }
.score-pick__opt input:checked + .score-pick__face {
  border-color: var(--c-primary); background: var(--c-tint-blue, rgba(83,155,245,.12));
}
.score-pick__opt input:focus-visible + .score-pick__face { outline: 2px solid var(--c-primary); }

/* Badge oceny w listach */
.score-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 28px; padding: 0 var(--s-2);
  border-radius: var(--r-md); font-weight: var(--fw-bold); font-size: var(--fs-14);
}
.score-badge--1, .score-badge--2 { background: rgba(229,83,75,.18); color: var(--c-red-400, #e5534b); }
.score-badge--3 { background: rgba(198,144,38,.18); color: var(--c-yellow-400, #c69026); }
.score-badge--4, .score-badge--5 { background: rgba(87,171,90,.18); color: var(--c-green-400, #57ab5a); }

/* ---------- Zakładki (Red Tag: otwarte/przeterminowane/zamknięte) ---------- */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--c-surface-3); margin-bottom: var(--s-4); overflow-x: auto; }
.tabs a {
  padding: var(--s-2) var(--s-3); text-decoration: none;
  color: var(--c-text-muted); font-size: var(--fs-13); font-weight: var(--fw-medium);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a.is-active { color: var(--c-text); border-bottom-color: var(--c-primary); }

/* ---------- Galeria zdjęć ---------- */
.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--s-2);
}
.photo-grid a { display: block; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--c-surface-3); }
.photo-grid img { display: block; width: 100%; height: 120px; object-fit: cover; }
.photo-grid figcaption { font-size: var(--fs-11); color: var(--c-text-muted); padding: var(--s-1) var(--s-2); }

/* ---------- Wykresy SVG (raporty) ---------- */
.chart-card svg { width: 100%; height: auto; display: block; }
.chart-card { overflow-x: auto; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--s-3); }
.kpi {
  background: var(--c-surface-1); border: 1px solid var(--c-surface-3);
  border-radius: var(--r-lg); padding: var(--s-4);
}
.kpi__value { font-size: var(--fs-32); font-weight: var(--fw-bold); line-height: 1.1; }
.kpi__label { font-size: var(--fs-12); color: var(--c-text-muted); margin-top: var(--s-1); }
.kpi--good .kpi__value { color: var(--c-green-400, #57ab5a); }
.kpi--warn .kpi__value { color: var(--c-yellow-400, #c69026); }
.kpi--bad .kpi__value  { color: var(--c-red-400, #e5534b); }

/* ---------- Kalendarz miesięczny ---------- */
.cal { display: flex; flex-direction: column; gap: 4px; }
.cal__head, .cal__row {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.cal__wd {
  text-align: center; font-size: var(--fs-11); font-weight: var(--fw-semibold);
  color: var(--c-text-muted); padding: 2px 0;
}
.cal__cell {
  display: flex; flex-direction: column; gap: 2px;
  min-height: 76px; padding: 4px 6px;
  background: var(--c-surface-1);
  border: 1px solid var(--c-surface-3); border-radius: var(--r-md);
  text-decoration: none; color: var(--c-text);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
a.cal__cell:hover { background: var(--c-surface-2); border-color: var(--c-surface-4); }
.cal__cell--empty { background: transparent; border-color: transparent; }
.cal__cell--today { border-color: var(--c-primary); }
.cal__cell--absent { background: var(--c-tint-amber, rgba(198,144,38,.12)); border-color: var(--c-warning, #c69026); }
.cal__day { font-size: var(--fs-13); font-weight: var(--fw-semibold); }
.cal__absent-tag {
  font-size: 9px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--c-warning, #c69026); font-weight: var(--fw-bold);
}
.cal__marks { margin-top: auto; display: flex; flex-wrap: wrap; gap: 4px; }
.cal__mark { font-size: var(--fs-11); white-space: nowrap; }
@media (max-width: 767px) {
  .cal__cell { min-height: 56px; padding: 3px 4px; }
  .cal__mark { font-size: 10px; }
}

/* Mobile: formularze pełna szerokość, większe pola dotykowe */
@media (max-width: 767px) {
  .page { padding: var(--s-3) var(--s-3) var(--s-10); }
  .input, select.input { min-height: 44px; }
  .btn--lg { min-height: 48px; }
}
