/* Tokeny (`:root`) mieszkają w `tokens.css`, ładowanym przed tym plikiem.
   Font Inter dociąga `<link>` w `index.html` — `@import` był tu duplikatem
   i blokował render, bo startuje dopiero po pobraniu arkusza. */

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

body {
  background-color: var(--bg-primary);
  /* Delikatna poświata u góry — tło przestaje być płaską czernią, a karty
     odcinają się od niego wyraźniej. Przyklejona do okna, więc nie przesuwa
     się przy przewijaniu długich widoków. */
  background-image: var(--bg-glow);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-surface);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--bg-hover);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 0.5em;
  color: var(--text-primary);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
p { margin-bottom: 1rem; color: var(--text-secondary); }

/* Layout Utilities */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 10px rgb(var(--accent-primary-rgb) / 0.25);
}
.btn-primary:hover {
  background-color: var(--accent-primary-hover);
}

.btn:active, .btn-sm:active, .btn-outline:active {
  transform: scale(0.97);
}

/* Jeden wspólny pierścień fokusu dla klawiatury — dotąd miał go tylko
   `.btn-sm` i kafelki kalendarza. */
.btn:focus-visible, .btn-icon:focus-visible, .btn-outline:focus-visible,
.btn-text:focus-visible, .nav-item:focus-visible, .nav-brand:focus-visible,
.nav-logout-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background-color: var(--bg-hover);
}

.btn-danger {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--accent-danger);
}
.btn-danger:hover {
  background-color: var(--accent-danger);
  color: #fff;
}

.btn-icon {
  padding: 0.5rem;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

/* `.btn-sm` jest w praktyce samodzielnym komponentem: w 23 z 24 miejsc
   używany bez klasy `.btn`. Bez własnych reguł struktury przeglądarka
   rysowała mu natywną ramkę i zaokrąglenie — widać to było np. na
   przyciskach „Rozpocznij trening / Edytuj / Usuń” w oknie dnia. */
.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.25rem 0.75rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-sm:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Forms */
.input, .select, .textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color var(--transition);
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.input::placeholder, .textarea::placeholder {
  color: var(--text-muted);
}

.textarea {
  resize: vertical;
  min-height: 100px;
}

.checkbox {
  accent-color: var(--accent-primary);
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
}

/* Card Component */
.card {
  background-color: var(--bg-card);
  background-image: var(--card-sheen);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-strength {
  background-color: rgba(34, 197, 94, 0.15);
  color: var(--accent-strength);
}

.badge-cardio {
  background-color: rgba(249, 115, 22, 0.15);
  color: var(--accent-cardio);
}

.badge-planned {
  background-color: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
}

/* Modals */
#modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 17, 23, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

#modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

#modal-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform var(--transition);
}

#modal-overlay.active #modal-content {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
}

/* Toasts */
#toast-container {
  position: fixed;
  bottom: 5rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 2000;
  pointer-events: none;
}

/* Wygląd toastów przeniesiony do `ui.css` (.fc-toast) razem z modułem
   `ui/toast.js`. Tutaj zostaje samo pozycjonowanie kontenera. */

/* Navigation */
#main-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(26, 29, 39, 0.98), rgba(26, 29, 39, 0.92));
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  /* Dolny pasek wchodził pod wskaźnik gestu iOS — dotąd liczyła się z nim
     tylko karta treningu (`workout.css`). */
  padding: 0.35rem 0.25rem;
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
  z-index: var(--z-nav);
  gap: 2px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.35rem 0.15rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 500;
  transition: color var(--transition);
  cursor: pointer;
  background: none;
  border: none;
  flex: 1;
  min-width: 0;
  text-align: center;
}

/* Ikony SVG zamiast emoji: emoji rysowały się inaczej na każdym systemie
   i nie dało się ich pokolorować stanem aktywnym. Na telefonie aktywna
   pozycja dostaje „pigułkę" pod ikoną, jak w nawigacji systemowej. */
.nav-item .icon {
  width: 40px;
  height: 28px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  transition: background-color var(--transition), color var(--transition);
}

.nav-item:hover {
  color: var(--text-primary);
}

.nav-item.active {
  color: var(--accent-primary-soft);
  font-weight: 600;
}

.nav-item.active .icon {
  background: rgb(var(--accent-primary-rgb) / 0.18);
}

/* Logo pokazujemy tylko w górnym pasku (od 768 px) */
.nav-brand {
  display: none;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.nav-brand img {
  border-radius: var(--radius-sm);
}

/* Layout for content */
/*
   `viewport-fit=cover` w `index.html` wyłącza automatyczne wcięcie na obszar
   bezpieczny — to warunek działania `env(safe-area-inset-bottom)` w karcie
   treningu, ale w zamian treść rysuje się POD paskiem statusu iPhone'a,
   bo `apple-mobile-web-app-status-bar-style` jest `black-translucent`.
   Na 390 pt nagłówek kalendarza zaczynał się na 12 px, a pasek statusu
   zajmuje ~47–59 px: cała nazwa miesiąca ze strzałkami była niewidoczna.

   `max()` zamiast zwykłego dodawania: tam, gdzie `env()` zwraca 0
   (przeglądarka desktopowa, Android bez wcięcia), odstęp zostaje dokładnie
   taki jak dotąd — żadnej zmiany wizualnej tam, gdzie problemu nie było.
*/
#app-content {
  padding-top: max(0.75rem, env(safe-area-inset-top));
  padding-right: max(0.5rem, env(safe-area-inset-right));
  padding-bottom: 5.5rem;
  padding-left: max(0.5rem, env(safe-area-inset-left));
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* Form Layout */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-row {
  display: flex;
  gap: 1rem;
}

.flex-1 { flex: 1; }

/* Utility Classes */
.mt-4 { margin-top: 1rem; }
.text-danger { color: var(--accent-danger); }
.text-muted { color: var(--text-muted); }

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-outline:hover {
  background: var(--bg-hover);
}

.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.5rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: color var(--transition);
}

.btn-text:hover {
  color: var(--text-primary);
}

.workout-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
  gap: 1rem;
}

/* Utilities */
.fade-in {
  animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* User Info in Nav & Skeletons */
.nav-user-info {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.35rem;
  margin-left: 0;
  border-left: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 36px;
}

.nav-user-avatar-wrap {
  position: relative;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.nav-user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.nav-user-avatar-skeleton {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 25%, rgba(255, 255, 255, 0.12) 50%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 200% 100%;
  animation: navSkeletonShimmer 1.5s infinite ease-in-out;
}

.nav-user-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
  display: none;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-user-name-skeleton {
  display: inline-block;
  width: 64px;
  height: 13px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 25%, rgba(255, 255, 255, 0.12) 50%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 200% 100%;
  animation: navSkeletonShimmer 1.5s infinite ease-in-out;
  vertical-align: middle;
}

@keyframes navSkeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Znacznik pracy offline — pojawia się tylko wtedy, gdy dane pochodzą
   wyłącznie z pamięci lokalnej. */
.nav-sync-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: 4px;
  padding: 3px 8px;
  margin-right: 6px;
  border-radius: 999px;
  background: rgba(249, 115, 22, 0.15);
  border: 1px solid rgba(249, 115, 22, 0.35);
  color: var(--accent-cardio);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: default;
}

@media (max-width: 480px) {
  /* Na wąskim ekranie sam znak ostrzegawczy — słowo "Offline" nie mieści się
     obok sześciu zakładek. */
  .nav-sync-badge {
    font-size: 0;
    padding: 4px;
    gap: 0;
  }

  .nav-sync-badge::before {
    content: '⚠️';
    font-size: 0.8rem;
  }
}

.nav-logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  padding: 0.35rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  flex-shrink: 0;
}

.nav-logout-btn:hover {
  background: var(--bg-hover);
  color: var(--accent-danger);
}

/* Na 375 px na pozycję nawigacji zostaje ~46 px, a „Waga i Pomiary"
   potrzebuje ~78 px. Etykiety łamały się na dwie linie i pozycje miały
   różną wysokość (63 px wobec 51 px). Na wąskim ekranie pokazujemy skrót,
   pełna nazwa zostaje w `aria-label` i wraca od 768 px. */
.nav-item > span:not(.icon),
.nav-label {
  white-space: nowrap;
}

.nav-label-full { display: none; }

/* Responsive */
/* Na telefonie w dolnym pasku zostaje samo wylogowanie — awatar zabierał
   miejsce sześciu zakładkom, a nazwy użytkownika i tak tam nie było. */
@media (max-width: 767px) {
  .nav-user-avatar-wrap { display: none; }
  .nav-user-info { padding-left: 0.15rem; }
}

@media (min-width: 768px) {
  .nav-label-short { display: none; }

  .nav-brand {
    display: inline-flex;
    margin-right: auto;
    padding: 0.25rem 0.4rem;
  }

  .nav-item .icon {
    width: 20px;
    height: 20px;
    padding: 0;
    background: none !important;
  }

  .nav-item {
    border-radius: var(--radius-pill);
    transition: color var(--transition), background-color var(--transition);
  }

  .nav-item:hover {
    background: var(--bg-hover);
  }

  .nav-item.active {
    background: rgb(var(--accent-primary-rgb) / 0.14);
  }
  .nav-label-full { display: inline; }

  #main-nav {
    bottom: auto;
    top: 0;
    border-top: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    background: rgb(15 17 23 / 0.82);
    /* Tu pasek siedzi u góry, więc wcięcie systemowe idzie od góry —
       dotyczy m.in. iPada w orientacji poziomej. */
    padding: 0.65rem 0.75rem;
    padding-top: max(0.65rem, env(safe-area-inset-top));
    position: fixed;
  }
  
  .nav-item {
    flex-direction: row;
    font-size: 0.9rem;
    flex: initial;
    min-width: 0;
    gap: 0.4rem;
    padding: 0.45rem 0.7rem;
    white-space: nowrap;
  }

  .nav-user-info {
    position: static;
    transform: none;
    border-left: 1px solid var(--border);
    padding-left: 0.65rem;
    margin-left: auto;
    gap: 0.45rem;
    flex-shrink: 0;
  }

  .nav-user-name {
    display: inline-block;
    max-width: 105px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
  }

  #app-content {
    /* Od 768 px nawigacja jest przyklejona u góry, więc to ona odsuwa treść
       od krawędzi — wcięcie systemowe dokładamy do niej, nie do treści. */
    padding-top: calc(5rem + env(safe-area-inset-top));
    padding-bottom: 2rem;
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
  }

  #toast-container {
    bottom: 2rem;
  }
}

@media (min-width: 1024px) {
  #main-nav {
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
  }

  .nav-item {
    font-size: 0.94rem;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
  }

  .nav-user-info {
    padding-left: 0.85rem;
  }

  .nav-user-name {
    max-width: 130px;
  }
}

@media (min-width: 1200px) {
  #app-content {
    max-width: 1200px;
    margin: 0 auto;
  }
}

/* Użytkownik prosi system o mniej ruchu → wyłączamy wejścia widoków
   i przesunięcia przycisków (każdy widok ma własne animacje). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
