/* =========================================================
   Panel – wygląd. Najpierw telefon, potem większe ekrany.
   ========================================================= */

:root {
  --tlo: #f4f1ea;
  --karta: #ffffff;
  --tusz: #17324d;
  --tekst: #1b2733;
  --tekst-slaby: #535e69;
  --linia: #ddd7cb;
  --akcent: #f2b44a;
  --akcent-ciemny: #8a5a00;
  --czerwony: #a8231b;
  --czerwony-tlo: #fbe9e7;
  --fokus: #1f6feb;
  --promien: 14px;
  --cien: 0 1px 2px rgba(23, 50, 77, 0.08), 0 2px 8px rgba(23, 50, 77, 0.06);
}

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

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

body {
  margin: 0;
  background: var(--tlo);
  color: var(--tekst);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; color: var(--tusz); }
h2 { font-size: 1.05rem; font-weight: 700; }

:focus-visible {
  outline: 3px solid var(--fokus);
  outline-offset: 2px;
  border-radius: 6px;
}

.tylko-czytnik {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Pola formularzy ---------- */
label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="date"],
select,
textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid #b9b2a4;
  border-radius: 10px;
  background: #fff;
  color: var(--tekst);
  font: inherit;
  font-size: 16px; /* 16px = iPhone nie powiększa strony przy wpisywaniu */
}

input[type="date"] { -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; min-height: 96px; }

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--fokus);
  outline-offset: 0;
}

.pole-wyboru {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}
.pole-wyboru input { width: 24px; height: 24px; margin: 0; accent-color: var(--tusz); }
.pole-wyboru label { margin: 0; }

.pomoc { margin: 0 0 4px; color: var(--tekst-slaby); }
.pomoc--mala { font-size: 0.85rem; margin-top: 4px; }

/* ---------- Przyciski ---------- */
.przycisk {
  display: block;
  width: 100%;
  min-height: 50px;
  margin-top: 20px;
  border: 0;
  border-radius: 12px;
  background: var(--tusz);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.przycisk:disabled { opacity: 0.6; cursor: wait; }

.przycisk-tekst {
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  background: none;
  color: var(--tusz);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ---------- Komunikaty ---------- */
.komunikat {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--tusz);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--cien);
}
.komunikat:empty { display: none; }
.komunikat--blad { background: var(--czerwony); }

/* ---------- Logowanie ---------- */
.logowanie {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.logowanie__karta {
  width: 100%;
  max-width: 400px;
  padding: 28px 22px;
  border-radius: 20px;
  background: var(--karta);
  box-shadow: var(--cien);
}
.logowanie__ikona { display: block; border-radius: 14px; margin-bottom: 12px; }
.logowanie h1 { font-size: 1.6rem; margin-bottom: 8px; }
.logowanie .przycisk-tekst { display: block; margin: 8px auto 0; }

/* ---------- Panel ---------- */
.naglowek {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 4px max(16px, env(safe-area-inset-left));
}
.naglowek__tytul { font-size: 1.5rem; letter-spacing: -0.01em; }

.panel {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) calc(100px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.panel:focus { outline: none; }

.sekcja { margin-top: 26px; }
.sekcja > h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.znaczek {
  min-width: 26px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--akcent);
  color: var(--tusz);
  font-size: 0.85rem;
  text-align: center;
}
.znaczek:empty { display: none; }

/* Licznik */
.liczniki {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 8px 0 0;
}
.licznik {
  padding: 12px 12px 10px;
  border-radius: var(--promien);
  background: var(--karta);
  box-shadow: var(--cien);
}
.licznik dt {
  color: var(--tekst-slaby);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.licznik dd {
  margin: 2px 0 0;
  color: var(--tusz);
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.licznik__procent { font-size: 0.85rem; font-weight: 600; color: var(--tekst-slaby); }
.licznik--akcent { background: var(--tusz); }
.licznik--akcent dt { color: #c9d6e3; }
.licznik--akcent dd { color: var(--akcent); }

/* Filtry statusu – przewijane palcem w poziomie */
.filtry {
  display: flex;
  gap: 8px;
  margin: 0 -16px 12px;
  padding: 2px 16px 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filtry::-webkit-scrollbar { display: none; }
.filtr {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 14px;
  border: 1.5px solid #b9b2a4;
  border-radius: 999px;
  background: var(--karta);
  color: var(--tekst);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.filtr[aria-pressed="true"] {
  border-color: var(--tusz);
  background: var(--tusz);
  color: #fff;
}
.filtr__ile { margin-left: 4px; opacity: 0.75; font-variant-numeric: tabular-nums; }

/* Lista klientów */
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.klient {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--promien);
  background: var(--karta);
  box-shadow: var(--cien);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.klient__firma { font-weight: 700; color: var(--tusz); overflow-wrap: anywhere; }
.klient__meta { grid-column: 1; color: var(--tekst-slaby); font-size: 0.88rem; }
.klient__status { grid-column: 2; grid-row: 1; justify-self: end; align-self: start; }
.klient__data { grid-column: 2; grid-row: 2; justify-self: end; font-size: 0.85rem; font-weight: 600; color: var(--tekst-slaby); white-space: nowrap; }
.klient__data--zalegle { color: var(--czerwony); }
.klient__data--dzis { color: var(--akcent-ciemny); }

.klient--zalegly { box-shadow: inset 4px 0 0 var(--czerwony), var(--cien); }

/* Etykiety statusów (ciemny tekst na jasnym tle = dobry kontrast) */
.status {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.status--list_wyslany  { background: #e6e9ee; color: #2b3a4a; }
.status--odezwal_sie   { background: #dbe9f7; color: #164272; }
.status--rozmowa       { background: #e8e0f5; color: #482c77; }
.status--umowa         { background: #fbe7c2; color: #643f00; }
.status--strona_online { background: #d6efdf; color: #1b5631; }
.status--opieka        { background: #cfeee9; color: #12544c; }
.status--odpadl        { background: #f3dede; color: #762020; }

.pusto {
  margin: 0;
  padding: 16px;
  border: 1.5px dashed var(--linia);
  border-radius: var(--promien);
  color: var(--tekst-slaby);
  text-align: center;
}

/* Przycisk „Dodaj” na dole ekranu */
.dodaj {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 40;
  transform: translateX(-50%);
  min-height: 54px;
  padding: 0 26px;
  border: 0;
  border-radius: 999px;
  background: var(--akcent);
  color: var(--tusz);
  font: inherit;
  font-weight: 800;
  box-shadow: 0 6px 18px rgba(23, 50, 77, 0.25);
  cursor: pointer;
}

/* ---------- Okno klienta (dialog) ---------- */
.okno {
  width: 100%;
  max-width: 640px;
  max-height: 94vh;
  max-height: 94dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--karta);
  color: var(--tekst);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.okno::backdrop { background: rgba(15, 30, 45, 0.5); }
.okno form { padding: 8px 18px calc(24px + env(safe-area-inset-bottom)); }
.okno__gora {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -18px;
  padding: 10px 10px 8px 18px;
  background: var(--karta);
  border-bottom: 1px solid var(--linia);
}
.okno__gora h2 { font-size: 1.2rem; }

.dwie-kolumny { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.link-dysk {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 0;
  color: var(--tusz);
  font-weight: 700;
  text-underline-offset: 3px;
}

@media (min-width: 700px) {
  .okno { margin: auto; border-radius: 20px; }
}

@media (prefers-reduced-motion: no-preference) {
  .klient, .filtr, .przycisk, .dodaj { transition: transform 0.12s ease; }
  .klient:active, .przycisk:active, .filtr:active { transform: scale(0.98); }
  .dodaj:active { transform: translateX(-50%) scale(0.97); }
}
