/* ═══════════════════════════════════════════════════════════
   FormArea — Mobile CSS (Kompleksowe poprawki mobilne)
   Plik: mobile.css
   Ładowany po app.css i components.css — nadpisuje z priorytetem.
   ═══════════════════════════════════════════════════════════ */

/* ──────────────────────────────────────────────────────────
   1. GLOBALNE — FONT SCALING + BOX MODEL
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  html { font-size: 15px; }
  *, *::before, *::after { box-sizing: border-box; }

  /* Zapobiegaj OVERFLOW na całej stronie */
  body { overflow-x: hidden; }
  #app { overflow-x: hidden; }
  .main-content { overflow-x: hidden; }
  .view { overflow-x: hidden; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
}

/* ──────────────────────────────────────────────────────────
   2. SIDEBAR — TOGGLE I OVERLAY
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar chowa się poza ekran */
  .sidebar {
    transform: translateX(-100%);
    width: 280px !important;
    z-index: 1000;
    box-shadow: 4px 0 40px rgba(0,0,0,0.6);
  }
  .sidebar.open { transform: translateX(0); }

  /* Overlay gdy sidebar otwarty */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 999;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.visible { display: block; }

  /* Hamburger przycisk */
  .sidebar-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 998;
    width: 42px;
    height: 42px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
  }

  /* Przycisk zamknięcia w sidebarze */
  .sidebar-close {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-2);
    cursor: pointer;
    font-size: 1rem;
  }

  /* Główna treść rozciąga się na całą szerokość */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
  }

  /* App header na mobile: padding-left dla hamburgera */
  .app-header {
    padding: 0 var(--sp-4) 0 66px !important;
    height: 56px !important;
  }

  /* View padding: zerujemy top (header jest sticky i zajmuje miejsce) */
  .view {
    padding: 1.25rem 1rem 1.5rem !important;
  }
}

/* ──────────────────────────────────────────────────────────
   3. MEASUREMENTS VIEW — formularz pomiarów (na zdjęciu)
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Główna siatka: 1 kolumna zamiast 2 */
  .measurements-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  /* Formularz pomiarów: 1 kolumna — Data, Waga, Notatka, Zapisz — każde pole full-width */
  .meas-form-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  /* Wszystkie pola full-width */
  .meas-form-grid > div {
    grid-column: 1 / -1;
  }

  /* Przycisk Zapisz full-width */
  .meas-form-grid .btn {
    width: 100%;
  }

  /* ── Naprawka input[type=date] na iOS ── */
  /* iOS renderuje date pickery z dużym wewnętrznym paddingiem i inną wysokością */
  input[type="date"],
  input[type="date"].form-input {
    -webkit-appearance: none;
    appearance: none;
    height: 44px !important;
    line-height: 44px;
    padding: 0 0.875rem !important;
    font-size: 1rem !important;
    display: flex;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
  }

  /* Tabela historii: ukryj kolumnę "Notatka" na małym ekranie */
  .measurements-list table th:nth-child(4),
  .measurements-list table td:nth-child(4) {
    display: none;
  }

  /* Stat cards: 2 kolumny zamiast 3 */
  .stats-grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Przyciski zakresu wykresu — zawijaj */
  #meas-chart-buttons {
    flex-wrap: wrap;
    gap: 4px;
  }
  #meas-chart-buttons .btn {
    font-size: 0.75rem;
    padding: 3px 8px;
  }
}

/* ──────────────────────────────────────────────────────────
   4. DASHBOARD — bento grid i statystyki
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .dash-bento {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .dash-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem !important;
  }

  .dash-stat-card {
    padding: 1rem !important;
    border-radius: var(--r-lg) !important;
  }

  .dash-stat-value {
    font-size: var(--text-3xl) !important;
  }
}

@media (max-width: 480px) {
  .dash-stats {
    grid-template-columns: 1fr !important;
  }
}

/* ──────────────────────────────────────────────────────────
   5. WORKOUT VIEW — sidebar dzienny + content
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .workout-layout {
    flex-direction: column !important;
    gap: 1rem !important;
  }

  /* Sidebar dzienny — pozioma lista zamiast pionowej */
  .workout-sidebar {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto;
    overflow-y: hidden;
  }

  /* Days list poziomo */
  .workout-sidebar .day-list,
  .workout-sidebar > div > div {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
    scrollbar-width: thin;
  }

  .day-item {
    min-width: 90px !important;
    flex-shrink: 0 !important;
    border-left: none !important;
    border-bottom: 3px solid transparent !important;
    padding: 0.5rem 0.75rem !important;
    text-align: center !important;
    border-radius: var(--r-md) !important;
  }

  .day-item.active {
    border-left-color: transparent !important;
    border-bottom-color: var(--accent) !important;
  }

  /* Workout content — usuwamy górny padding dla nazwy dnia */
  .workout-content {
    padding: 1.25rem !important;
  }

  /* Header: Nazwa dnia + przycisk na dwie linijki */
  .content-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  .content-header .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Week tabs — przewijalne poziomo */
  .week-tabs {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    padding: 0.5rem 0 !important;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .week-tab {
    min-width: 100px !important;
    padding: 0.6rem 1rem !important;
    flex-shrink: 0 !important;
    font-size: 0.8rem !important;
  }

  /* Workout header akcje: full width */
  .workout-header {
    flex-direction: column !important;
    gap: 0.75rem !important;
    align-items: stretch !important;
  }

  .workout-header-actions {
    flex-direction: column !important;
    width: 100% !important;
    gap: 0.5rem !important;
  }

  .workout-header-actions .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Exercise cards: usuwamy hover-translate (mobile nie ma hover) */
  .exercise-card {
    transform: none !important;
  }

  /* Panel meta infos - zawijaj */
  .day-panel-meta {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
  }

  /* ── AKTYWNY EKRAN TRENINGOWY (ACTIVE WORKOUT EXECUTION MODAL) ── */
  #active-workout-modal {
    padding-bottom: 2rem !important;
  }

  #active-workout-modal > div:first-child {
    padding: 0.75rem 1rem !important;
  }

  .workout-top-bar {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    margin-bottom: 0.25rem !important;
  }

  .btn-zapisz-mobile {
    width: auto !important;
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem !important;
  }

  .active-workout-content {
    padding: 1rem 0.75rem !important;
  }

  .exercise-tracker-card {
    padding: 1rem 0.75rem !important;
    margin-bottom: 1.25rem !important;
    border-radius: 12px !important;
  }

  .exercise-tracker-card-header {
    padding-bottom: 0.75rem !important;
    margin-bottom: 0.75rem !important;
  }

  /* Siatka serii na mobile — precyzyjnie skalkulowana dla 360px+ */
  .workout-sets-header-row,
  .workout-set-row {
    display: grid !important;
    grid-template-columns: 24px 44px 1fr 1fr 1fr 32px 36px !important;
    gap: 0.3rem !important;
    align-items: center !important;
    padding: 0.4rem 0.2rem !important;
  }

  .workout-sets-header-row {
    font-size: 0.7rem !important;
    color: var(--text-muted) !important;
    margin-bottom: 0.35rem !important;
  }

  .prev-weight-text {
    font-size: 0.75rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    text-align: center !important;
  }

  /* Pola wprowadzania ciężaru, powtórzeń i RPE */
  .workout-form-input {
    height: 40px !important;
    min-height: 40px !important;
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    padding: 0.2rem 0.1rem !important;
    text-align: center !important;
    border-radius: 8px !important;
  }

  /* Przyciski Notatki i Checkmarka */
  .workout-btn-note,
  .workout-btn-tick {
    height: 40px !important;
    min-height: 40px !important;
    width: 100% !important;
    padding: 0 !important;
    border-radius: 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.9rem !important;
  }
}

/* ──────────────────────────────────────────────────────────
   6. CHAT VIEW — dymki, textarea i layout
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Chat layout: odejmuj wysokość header (56px) */
  .chat-view-container {
    height: calc(100dvh - 56px);
  }

  /* Dymki użytkownika - nie przekraczaj 80% szerokości */
  .user-msg-bubble {
    max-width: 80% !important;
    font-size: 0.9rem !important;
  }

  .ai-msg-bubble {
    max-width: 92% !important;
    font-size: 0.9rem !important;
  }

  /* Input form na dole */
  .chat-input-saas {
    padding: 0.5rem !important;
    gap: 0.5rem !important;
  }

  .chat-saas-textarea {
    font-size: 0.9rem !important;
    min-height: 40px !important;
  }

  /* Chat send button — zawsze widoczny */
  .chat-saas-send-btn {
    width: 40px !important;
    height: 40px !important;
    flex-shrink: 0 !important;
  }
}

/* ──────────────────────────────────────────────────────────
   7. PROGRESS VIEW — wykresy SVG
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* SVG wykresy mają min-width: 600px — owijamy w scroll */
  .progress-chart-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* ──────────────────────────────────────────────────────────
   8. BUILDER VIEW — layout
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .builder-layout {
    flex-direction: column !important;
    gap: 1rem !important;
  }

  .builder-sidebar {
    max-width: 100% !important;
    min-width: 100% !important;
    width: 100% !important;
  }

  .builder-content {
    min-width: 100% !important;
    width: 100% !important;
    flex: auto !important;
  }
}

@media (max-width: 480px) {
  /* Opcje ćwiczenia w builderze: pionowo */
  .builder-ex-options {
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100% !important;
  }

  .builder-ex-inputs {
    justify-content: space-between !important;
    width: 100% !important;
    flex-wrap: wrap !important;
    gap: 0.4rem !important;
  }

  .builder-input-group {
    flex: 1 !important;
    min-width: 60px !important;
  }

  .builder-ex-actions {
    width: 100% !important;
    border-left: none !important;
    padding-left: 0 !important;
    border-top: 1px solid var(--border) !important;
    padding-top: 0.75rem !important;
    justify-content: space-between !important;
  }

  .desktop-drag-handle { display: none !important; }
}

/* ──────────────────────────────────────────────────────────
   9. DIET VIEW — nagłówek i siatka
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .diet-header {
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  .diet-header .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  .shopping-list {
    grid-template-columns: 1fr !important;
  }

  /* Premium CTA: zawijaj */
  .premium-cta {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  .premium-cta .btn {
    width: 100% !important;
  }
}

/* ──────────────────────────────────────────────────────────
   10. PHYSIQUE + FORMCHECK VIEW
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Grid 2-kol -> 1 kol */
  .form-check-layout {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .formcheck-left-col {
    gap: 1rem;
  }

  /* Upload zone: mniejszy padding na mobile */
  .upload-zone {
    padding: 1.25rem 0.75rem !important;
  }
  .upload-icon {
    font-size: 2rem !important;
    margin-bottom: 0.25rem !important;
  }
  .upload-title {
    font-size: 0.95rem !important;
  }
  .upload-hint {
    font-size: 0.75rem !important;
  }

  /* Archiwum techniki card — kompaktowy nagłówek i tabela */
  .archive-card-header {
    padding: 0.875rem 1rem !important;
  }
  .archive-card-header h3 {
    font-size: 1.05rem !important;
  }

  .archive-table-wrapper {
    max-height: 240px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Tabela archiwum na mobile — zwięzły layout z małymi paddingami */
  .archive-th {
    padding: 0.6rem 0.5rem !important;
    font-size: 0.7rem !important;
  }
  .archive-td {
    padding: 0.6rem 0.5rem !important;
  }

  .archive-ex-info {
    gap: 0.5rem !important;
  }
  .archive-ex-icon {
    width: 32px !important;
    height: 32px !important;
    font-size: 0.9rem !important;
  }
  .archive-ex-name {
    font-size: 0.8rem !important;
    letter-spacing: 0 !important;
  }
  .archive-ex-date {
    font-size: 0.75rem !important;
  }
  .archive-score-badge {
    padding: 0.2rem 0.5rem !important;
    font-size: 0.75rem !important;
  }

  /* Czat kolumna formcheck: stała sensowna wysokość */
  .formcheck-chat-col {
    height: 55dvh;
    min-height: 340px;
    max-height: 480px;
    display: flex;
    flex-direction: column;
  }

  /* Physique chat col */
  .physique-chat-col {
    height: 55dvh;
    min-height: 340px;
    max-height: 480px;
    display: flex;
    flex-direction: column;
  }

  /* Wiadomości w czacie — scrollowalny obszar */
  .formcheck-chat-col #form-chat-messages,
  .physique-chat-col #form-chat-messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* kluczowe dla flex scroll */
    padding: 1rem !important;
  }

  /* Input form na dole czatu */
  .formcheck-chat-col form,
  .physique-chat-col form {
    flex-shrink: 0;
    padding: 0.75rem !important;
  }

  /* Textarea w czacie analitycznym */
  .formcheck-chat-col textarea.chat-input,
  .physique-chat-col textarea.chat-input {
    min-height: 40px;
    font-size: 16px; /* zapobiega iOS zoom */
  }

  /* Stare klasy dla kompatybilności wstecznej */
  .formcheck-chat {
    height: auto;
    min-height: 300px;
  }
}

/* ──────────────────────────────────────────────────────────
   11. CARDS — globalne poprawki na mobile
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .card {
    padding: var(--sp-4) !important;
    border-radius: var(--r-lg) !important;
  }

  /* Typografia: tytuły widoków mniejsze */
  .view-title {
    font-size: var(--text-2xl) !important;
  }

  /* View header: może zawijać */
  .view-header {
    margin-bottom: var(--sp-5) !important;
  }

  /* Stat cards: mniejsze padding */
  .stat-card {
    padding: 1rem !important;
  }

  /* Flex rows: zawijaj na mobile */
  .flex-mobile-wrap {
    flex-wrap: wrap !important;
  }

  /* Ukryj hover efekty (nie ma myszy na mobile) */
  .card-hover:hover {
    transform: none !important;
    box-shadow: none !important;
  }

  .exercise-card:hover {
    transform: none !important;
  }
}

/* ──────────────────────────────────────────────────────────
   12. BUTTONS — dotykowe obszary klikania
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Minimalna wysokość dla dotykowego klikania (44px per Apple HIG) */
  .btn {
    min-height: 44px !important;
    padding: var(--sp-3) var(--sp-5) !important;
  }

  .btn-sm {
    min-height: 36px !important;
    padding: var(--sp-2) var(--sp-3) !important;
  }

  /* Nav items: łatwiejsze w klikaniu */
  .nav-item {
    min-height: 44px !important;
    padding: var(--sp-3) var(--sp-4) !important;
  }
}

/* ──────────────────────────────────────────────────────────
   13. LANDING PAGE — mobile navbar
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .landing-nav {
    padding: 0 var(--sp-3) !important;
    height: 56px !important;
  }

  .landing-nav-right {
    gap: 0.25rem !important;
  }

  /* Ukryj ghost przycisk na małym ekranie */
  .landing-nav-right .btn-ghost {
    display: none !important;
  }

  .landing-nav-right .btn-sm {
    padding: var(--sp-2) var(--sp-3) !important;
    font-size: 0.8rem !important;
  }

  .landing-logo span {
    font-size: 1.1rem !important;
  }

  /* Hero: jedna kolumna */
  .hero {
    grid-template-columns: 1fr !important;
    padding: 80px var(--sp-4) var(--sp-8) !important;
    text-align: center !important;
    gap: var(--sp-6) !important;
  }

  .hero-visual { display: none !important; }

  .hero-stats {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: var(--sp-3) !important;
  }

  /* Features grid: 1 kolumna */
  .features-grid {
    grid-template-columns: 1fr !important;
  }

  /* Pricing: 1 kolumna */
  .pricing-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ──────────────────────────────────────────────────────────
   14. MAX CALCULATOR
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .maxcalc-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Tabela rankingów: scrollowalna poziomo */
  .maxcalc-ranks {
    overflow-x: auto !important;
    justify-content: flex-start !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* ──────────────────────────────────────────────────────────
   15. MODALS — poprawione dla małych ekranów
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .modal {
    width: calc(100vw - 2rem) !important;
    max-width: 100% !important;
    max-height: 90dvh !important;
    overflow-y: auto !important;
    margin: 1rem !important;
    border-radius: var(--r-xl) !important;
  }

  .modal-backdrop {
    padding: 1rem !important;
    align-items: flex-end !important; /* Wyskakuje od dołu ekranu */
  }

  /* Paywall: pełna szerokość na mobile */
  .paywall-container {
    max-width: calc(100vw - 2rem) !important;
    padding: 1.5rem !important;
  }

  .paywall-title {
    font-size: 1.4rem !important;
  }

  .paywall-subtitle {
    font-size: 0.95rem !important;
    margin-bottom: 1.5rem !important;
  }
}

/* ──────────────────────────────────────────────────────────
   16. TOAST NOTIFICATIONS — pozycja na mobile
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .toast {
    bottom: 80px !important;
    left: 1rem !important;
    right: 1rem !important;
    width: auto !important;
    max-width: calc(100vw - 2rem) !important;
    text-align: center !important;
    justify-content: center !important;
  }
}

/* ──────────────────────────────────────────────────────────
   17. FORMULARZE — inputy mobilne
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* iOS/Android: nie powiększaj na focus */
  input, select, textarea {
    font-size: 16px !important; /* min 16px by nie triggerować zoom */
  }

  .form-input {
    min-height: 44px !important;
  }

  /* Zapobiegaj poziomemu scrollowi wewnątrz formularzy */
  .form-grid, .form-row {
    grid-template-columns: 1fr !important;
  }
}

/* ──────────────────────────────────────────────────────────
   18. KALKULATORY — mobilny layout
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .calc-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
}

/* ──────────────────────────────────────────────────────────
   19. AUTH PAGE
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .auth-page {
    grid-template-columns: 1fr !important;
    min-height: 100dvh !important;
  }

  .auth-visual { display: none !important; }

  .auth-panel {
    padding: var(--sp-6) var(--sp-4) !important;
  }
}

/* ──────────────────────────────────────────────────────────
   20. SAFE AREA — obsługa notcha/wyspy iPhone
────────────────────────────────────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .view {
      padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)) !important;
    }

    .chat-input-saas {
      padding-bottom: calc(0.5rem + env(safe-area-inset-bottom)) !important;
    }
  }
}

/* ──────────────────────────────────────────────────────────
   21. QUICK FIXES — overflow zapobiegawczy
────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Żadna tabela nie wyjdzie poza kontener */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Żadny inline-style z width: 320px etc. nie złamie layoutu */
  [style*="width: 320px"],
  [style*="width:320px"],
  [style*="width: 300px"] {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Flex rows które mogą się przelać */
  .flex-row-mobile-wrap {
    flex-direction: column !important;
  }

  /* Wykresy w sekcji progress — scroll zamiast przepełnienia */
  svg[style*="min-width: 600px"],
  svg[style*="min-width:600px"] {
    min-width: 300px !important;
  }

  /* landing landing-nav: nie wychodź poza ekran */
  .landing-nav-pills {
    display: none !important;
  }
}
