/*
 * Warstwa wizualna wg iOS HIG (clarity, deference, depth) i zlotego podzialu.
 * Skala odstepow to ciag Fibonacciego 8/13/21/34/55 - stosunek sasiednich dazy do phi.
 * Zadnych wartosci posrednich: kazdy odstep w tym pliku pochodzi z tej piatki.
 * Typografia 13/17/28/34, gdzie 28 = 17 x 1,618.
 */

:root {
  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --label: #1c1c1e;
  --label-secondary: #6c6c70;
  --separator: #d1d1d6;
  --accent: #1d6871;              /* turkus odczytany z icon-512.png */
  --accent-kontrast: #ffffff;
  --danger: #c00e0e;
  --schatten: 0 1px 3px #0000000f;

  --s1: 8px;
  --s2: 13px;
  --s3: 21px;
  --s4: 34px;
  --s5: 55px;
  --radius: 13px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --label: #ffffff;
    --label-secondary: #98989f;
    --separator: #38383a;
    --accent: #5cc5d0;
    --accent-kontrast: #000000;
    --danger: #ff6961;
    --schatten: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg);
  color: var(--label);
  -webkit-text-size-adjust: 100%;
}

/* ---------- pasek ---------- */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  min-height: 44px;
  padding: var(--s1) var(--s3);
  padding-top: calc(var(--s1) + env(safe-area-inset-top));
  padding-left: calc(var(--s3) + env(safe-area-inset-left));
  padding-right: calc(var(--s3) + env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(21px);
  border-bottom: 1px solid transparent;
  transition: border-color .25s ease-out;
}
header.gescrollt { border-bottom-color: var(--separator); }

/* Tytul w pasku pojawia sie dopiero, gdy duzy tytul wyjedzie za gore. */
#crumb {
  font-size: 17px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .25s ease-out;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
header.gescrollt #crumb { opacity: 1; }

#aktion {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  box-shadow: none;                /* w pasku ma byc sama ikona, bez plyty przycisku */
  color: var(--accent);
  font-size: 21px;
  line-height: 1;
}

/* ---------- tresc ---------- */

main {
  max-width: 34rem;
  margin: 0 auto;
  padding: 0 var(--s3) calc(var(--s5) + env(safe-area-inset-bottom));
}

h1 {
  margin: var(--s2) 0 var(--s3);
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: -.02em;
  font-weight: 700;
}

/* Naglowek sekcji w stylu grupowanej listy iOS. */
h2 {
  margin: var(--s3) 0 var(--s1);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--label-secondary);
}

/* ---------- listy grupowane ---------- */

ul {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  overflow: hidden;
}

li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  min-height: 44px;
  padding: var(--s2) var(--s3);      /* 21/13 = 1,615 - proporcja wciecia blizej phi */
  background: none;
  border: 0;
}
/* Separator tylko MIEDZY wierszami i wciety od lewej - nie ramka wokol kazdego. */
li + li { box-shadow: inset 0 1px 0 var(--separator); }
li + li { background-clip: padding-box; }
ul.getrennt li + li { box-shadow: none; border-top: 1px solid var(--separator); margin-left: var(--s3); padding-left: 0; }

li .meta { color: var(--label-secondary); font-size: 13px; }
.qty { min-width: var(--s4); text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.row { display: flex; gap: var(--s1); align-items: center; }

/* ---------- przyciski ---------- */

button, .knopf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  min-height: 44px;
  padding: var(--s2) var(--s3);
  font: inherit;
  font-weight: 500;
  color: var(--accent);
  background: var(--bg-elevated);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  cursor: pointer;
  transition: opacity .25s ease-out;
}
button:active, .knopf:active { opacity: .55; }

button.primary, .knopf.primary {
  background: var(--accent);
  color: var(--accent-kontrast);
  font-weight: 600;
}
button.gross, .knopf.gross { width: 100%; margin-top: var(--s2); }

/* Akcja drugorzedna: sam tekst, bez plyty - nie konkuruje z aparatem. */
button.leise {
  background: none;
  box-shadow: none;
  font-weight: 400;
}
.abmelden { display: block; width: 100%; margin-top: var(--s5); color: var(--label-secondary);
            background: none; box-shadow: none; }

li .row button { min-width: 44px; min-height: 44px; padding: 0; font-size: 21px; }

/* ---------- formularze ---------- */

input, select {
  width: 100%;
  min-height: 44px;
  padding: var(--s2);
  font: inherit;
  color: var(--label);
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
}
select { width: auto; }
label { display: block; margin: var(--s2) 0; }
.err { color: var(--danger); font-size: 13px; }
a { color: var(--accent); text-decoration: none; }

/* ---------- zdjecia ---------- */

/*
 * Podzial pionowy ekranu Stockwerk: pas zdjec zajmuje 38,2% wysokosci widoku,
 * lista materialu dostaje pozostale 61,8% - podzial phi, nie polowa na polowe.
 */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(89px, 1fr));
  gap: var(--s1);
  max-height: 38.2vh;
  overflow-y: auto;
  margin-top: var(--s1);
  padding: 1px;
}
.grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--s1);
  background: var(--separator);
  cursor: pointer;
  display: block;
  /* Bez tego dlugie przytrzymanie miniatury otwiera natywne menu iOS nad akcjami appki. */
  -webkit-touch-callout: none;
}

/* Kafelek nosi haczyk zaznaczenia - img nie ma pseudoelementow, wiec potrzebna otoczka. */
.kachel { position: relative; display: block; }
.kachel.gewaehlt img { opacity: .55; }
.kachel.gewaehlt::after {
  content: '✓';
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-kontrast);
  font-size: 14px; font-weight: 700;
}

/* ---------- pasek klatek ---------- */

/*
 * Stoi pod adresem budowy i nad segmentami. Przewija sie w poziomie, bo przy 36 klatkach
 * zadne zawijanie nie pomoze, a monter ma trafiac kciukiem bez celowania.
 */
.stiegen-leiste {
  display: flex;
  gap: var(--s1);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  margin: var(--s2) 0;
  padding-bottom: var(--s1);
  scrollbar-width: none;
}
.stiegen-leiste::-webkit-scrollbar { display: none; }

.stiege-chip {
  flex: none;
  min-height: 44px;
  padding: 0 var(--s3);
  border-radius: 999px;
  border: 1px solid var(--separator);
  background: var(--bg-elevated);
  color: var(--label);
  box-shadow: none;
  white-space: nowrap;
  scroll-snap-align: center;
}
.stiege-chip.aktiv {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-kontrast);
  font-weight: 600;
}
.stiege-chip.neu, .stiege-chip.mehr { color: var(--accent); }
.stiege-chip.ausgeblendet { opacity: .45; }

/* Upload wolany WYLACZNIE z paska: postep widac, wlasnych przyciskow juz nie trzeba. */
.nur-leiste .aufnahme { display: none; }

.auswahl-start { align-self: flex-start; margin-top: var(--s1); }
.auswahl-leiste {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: var(--s1); align-items: center;
  margin-top: var(--s1); padding: var(--s1) 0;
  background: var(--bg);
}
.auswahl-leiste button { min-height: 44px; flex: 1; }
.auswahl-leiste .warnung { color: var(--danger); }

.versteckt { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.aufnahme { flex-wrap: wrap; gap: var(--s1); margin: var(--s1) 0; }
.aufnahme .knopf { flex: 1 1 13rem; }

.uploads { margin-top: var(--s1); }
.uploads:empty { display: none; }
.uploads .dateiname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads .ok { color: var(--accent); }
.uploads .err { text-align: right; }

/* ---------- arkusz eksportu ---------- */

.kopf-aktionen { display: flex; align-items: center; gap: var(--s1); }
#teilen {
  flex: none;
  min-width: 44px; min-height: 44px;
  padding: 0;
  border: 0; border-radius: var(--radius);
  background: transparent; box-shadow: none;
  color: var(--accent);
  line-height: 0;
}

.blatt-hinter {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
  background: #00000066;
}
.blatt {
  width: 100%; max-width: 34rem;
  padding: var(--s3) var(--s3) calc(var(--s3) + env(safe-area-inset-bottom));
  background: var(--bg);
  border-radius: var(--radius) var(--radius) 0 0;
  animation: hoch .25s ease-out;
}
@keyframes hoch { from { transform: translateY(21px); } to { transform: none; } }

.blatt-titel { margin: 0 0 var(--s2); }

/* Wybor zakresu - segmenty w stylu iOS. */
.segment { display: flex; gap: var(--s1); margin-bottom: var(--s3); }
.segment-knopf {
  flex: 1; min-height: 44px; padding: var(--s1);
  font-size: 13px; font-weight: 500;
  background: var(--bg-elevated); color: var(--label);
  box-shadow: none; border: 1px solid var(--separator);
}
.segment-knopf.aktiv { background: var(--accent); color: var(--accent-kontrast); border-color: var(--accent); }

.blatt-aktionen { display: flex; flex-direction: column; gap: var(--s1); }
.blatt-knopf {
  flex-direction: column; align-items: flex-start; gap: 0;
  width: 100%; min-height: 55px;
  text-align: left;
}
.blatt-knopf .meta { color: var(--label-secondary); font-size: 13px; }
.blatt-knopf.primary .meta { color: var(--accent-kontrast); opacity: .8; }
.blatt-knopf.abbrechen { margin-top: var(--s2); justify-content: center; align-items: center;
                         color: var(--label-secondary); }

/* ---------- gest, toast, stany ---------- */

#menu { flex: none; min-width: 44px; min-height: 44px; padding: 0; border: 0;
        border-radius: var(--radius); background: transparent; box-shadow: none;
        color: var(--accent); line-height: 0; }

/* Bez touch-action Safari na iPhone anuluje wskaznik przy panie i gest nigdy nie dochodzi. */
li.wischbar { position: relative; overflow: hidden; padding: 0; touch-action: pan-y; }
/* Tresc musi lezec NAD schowanymi akcjami, inaczej przejmuja one klikniecie w wiersz. */
.wisch-inhalt { position: relative; z-index: 1;
                display: flex; align-items: center; justify-content: space-between;
                gap: var(--s2); width: 100%; min-height: 44px;
                padding: var(--s2) var(--s3); background: var(--bg-elevated);
                transition: transform .25s ease-out; }
.wisch-aktionen { position: absolute; inset: 0 0 0 auto; display: flex; }
.wisch-knopf { min-width: 89px; min-height: 44px; height: 100%; border: 0; border-radius: 0;
               box-shadow: none; background: var(--separator); color: var(--label); }
.wisch-knopf.warnung { background: var(--danger); color: #fff; }

li.ausgeblendet .wisch-inhalt { opacity: .45; }
.leerzeile { justify-content: center; padding: var(--s4) var(--s3); }
.haken { min-width: var(--s3); color: var(--accent); font-weight: 700; }
/* Widoczny wyzwalacz akcji w wierszu - 44x44, ta sama ikona co w pasku. */
.mehr { flex: none; min-width: 44px; min-height: 44px; padding: 0; border: 0;
        border-radius: var(--radius); background: transparent; box-shadow: none;
        color: var(--accent); line-height: 0; }
.anlegen { color: var(--accent); font-weight: 600; }
.fussnote { margin-top: var(--s4); text-align: center; }
.ok { color: var(--accent); }
button.gefahr { color: var(--danger); }

.toast { position: fixed; left: var(--s3); right: var(--s3);
         bottom: calc(var(--s3) + env(safe-area-inset-bottom)); z-index: 40;
         display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
         min-height: 44px; padding: var(--s2) var(--s3);
         background: var(--label); color: var(--bg); border-radius: var(--radius); }
.toast-knopf { min-height: 44px; padding: 0 var(--s2); border: 0; box-shadow: none;
               background: none; color: var(--accent); font-weight: 600; }

.lb-loeschen { min-width: 44px; min-height: 44px; padding: 0 var(--s2); border-radius: var(--radius);
               background: #ffffff26; color: #fff; box-shadow: none; font-size: 13px; }
.lb-fuss { position: absolute; left: 0; right: 0;
           bottom: calc(env(safe-area-inset-bottom) + var(--s1));
           padding: var(--s2) var(--s3); text-align: center; color: #fff; font-size: 13px;
           background: linear-gradient(transparent, #000000cc); }

/* ---------- lightbox ---------- */

body.ohne-scroll { overflow: hidden; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
  touch-action: none;
  overscroll-behavior: contain;
}
.lightbox img.gross { max-width: 100%; max-height: 100%; object-fit: contain;
                      -webkit-touch-callout: none; }
.lb-leiste {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: calc(var(--s1) + env(safe-area-inset-top)) var(--s3) var(--s1);
  background: linear-gradient(#000000cc, transparent);
}
.zaehler { color: #fff; font-size: 13px; font-variant-numeric: tabular-nums; }
.lb-zu, .lb-pfeil {
  min-width: 44px; min-height: 44px;
  padding: 0;
  border-radius: var(--radius);
  background: #ffffff26;
  box-shadow: none;
  color: #fff;
  font-size: 21px;
}
.lb-pfeil { position: absolute; top: 50%; transform: translateY(-50%); font-size: 28px; }
.lb-pfeil.links { left: var(--s1); }
.lb-pfeil.rechts { right: var(--s1); }

/* Elementy wydruku nie istnieja na ekranie. */
.druckkopf, .druckfuss, table.materialliste, .druck-abschnitt { display: none; }

/* ---------- wydruk ---------- */

@media print {
  /* Wydruk jest zawsze czarny na bialym, niezaleznie od trybu ciemnego na ekranie. */
  :root {
    --bg: #fff; --bg-elevated: #fff; --label: #000;
    --label-secondary: #000; --separator: #888; --schatten: none;
  }
  @page { size: A4 portrait; margin: 13mm; }

  body { background: #fff; color: #000; font-size: 11pt; }
  header, .lightbox { display: none !important; }
  main { max-width: none; margin: 0; padding: 0; }

  /* Na papier idzie WYLACZNIE tabela materialu - cala reszta ekranu znika. */
  /* #druckbereich jest kontenerem sekcji, sam klasy nie nosi - bez tego wyjatku
     regula chowala go razem z cala zawartoscia i z drukarki wychodzila sama stopka. */
  #app > *:not(.druck-abschnitt):not(.druckfuss):not(#druckbereich) { display: none !important; }
  #druckbereich { display: block !important; }
  .druck-abschnitt { display: block !important; }

  .druckkopf { display: block !important; margin-bottom: var(--s3); }
  .druckkopf h1 { font-size: 18pt; margin: 0 0 var(--s1); }
  .druckkopf .zeile { font-size: 10pt; }

  table.materialliste { display: table !important; width: 100%; border-collapse: collapse; }
  table.materialliste tbody { display: table-row-group; }
  table.materialliste tfoot { display: table-footer-group; }
  table.materialliste thead { display: table-header-group; }   /* naglowek na kazdej stronie */
  table.materialliste tr { page-break-inside: avoid; }
  table.materialliste th {
    text-align: left; font-size: 9pt; text-transform: uppercase; letter-spacing: .06em;
    border-bottom: 1px solid #000; padding: var(--s1) 0;
  }
  table.materialliste td { padding: var(--s1) 0; border-bottom: 1px solid #ddd; }
  table.materialliste .nr { width: 8%; color: #555; }
  table.materialliste .menge, table.materialliste .einheit { text-align: right; width: 13%; }
  table.materialliste tfoot td { border-top: 1px solid #000; border-bottom: 0; font-weight: 700; }

  .druck-abschnitt { page-break-after: always; }
  .druck-abschnitt:last-child { page-break-after: auto; }
  .druckfuss { display: block !important; margin-top: var(--s3); font-size: 9pt; color: #555; }
}

