/**
 * Dywanowy Bazar — dopasowanie mobilne (PWA / telefon).
 * Ładować OSTATNI po app-skin, wizard/editor.css i studio-shell.css.
 */

@media (max-width: 768px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  /* Brak poziomego „wysuwania” całej strony */
  body.app-skin {
    overflow-x: clip;
  }

  body.app-skin .page {
    max-width: 100%;
    box-sizing: border-box;
    padding-left: max(14px, env(safe-area-inset-left, 14px));
    padding-right: max(14px, env(safe-area-inset-right, 14px));
    padding-top: max(10px, env(safe-area-inset-top, 10px));
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  }

  /* Nagłówki „Studio”: bez ujemnych marginesów wychodzących poza ekran */
  body.app-skin .editor-hero {
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 16px;
    padding: 16px 14px;
    border-radius: var(--studio-radius-md, 14px);
  }

  body.app-skin .page-header {
    gap: 12px;
  }

  body.app-skin .page-header h1 {
    font-size: clamp(1.25rem, 5vw, 1.5rem);
    line-height: 1.2;
  }

  /* iOS: 16px+ na polach = brak niechcianego zoom przy fokusie */
  body.app-skin input[type="text"],
  body.app-skin input[type="search"],
  body.app-skin input[type="url"],
  body.app-skin input[type="email"],
  body.app-skin input[type="number"],
  body.app-skin select,
  body.app-skin textarea {
    font-size: 16px;
    min-height: 44px;
  }

  body.app-skin textarea {
    min-height: 120px;
  }

  body.app-skin button,
  body.app-skin .filter-button,
  body.app-skin .wizard-step {
    min-height: 44px;
    touch-action: manipulation;
  }

  body.app-skin .search-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  body.app-skin .search-bar button {
    width: 100%;
  }

  /* OCR / bulk: jedna kolumna zamiast ścisku */
  body.app-skin .ocr-label-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  body.app-skin .ocr-label-row select,
  body.app-skin .ocr-label-row button,
  body.app-skin .ocr-label-actions button {
    width: 100%;
  }

  body.app-skin .ocr-label-actions {
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100%;
  }

  body.app-skin .bulk-import-panel textarea {
    font-size: 14px;
  }

  /* Filtry draftów — większe cele dotykowe */
  body.app-skin .drafts-toolbar .filter-button {
    padding: 10px 16px;
    font-size: 14px;
  }

  body.app-skin .drafts-toolbar .filter-group {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  /* === Wizard: stepper poziomo przewijany zamiast mikrotekstu w 5 kolumnach === */
  body.app-skin .wizard-stepper {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding: 4px 0 14px;
    margin: 0 -4px 12px;
    scrollbar-width: thin;
  }

  body.app-skin .wizard-stepper::-webkit-scrollbar {
    height: 4px;
  }

  body.app-skin .wizard-step {
    flex: 0 0 auto;
    min-width: 96px;
    max-width: 42vw;
    scroll-snap-align: start;
    padding: 12px 10px;
    border-radius: 12px;
  }

  body.app-skin .wizard-step .step-num {
    font-size: 11px;
  }

  body.app-skin .wizard-step .step-name {
    font-size: 13px;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  body.app-skin .wizard-page {
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  }

  /* Studio: fixed footer — rezerwa przewijania (ogólne .page ma tylko 14px na dole) */
  body.app-skin .page.studio-page {
    padding-bottom: calc(var(--studio-footer-reserve, 168px) + env(safe-area-inset-bottom, 0px));
    scroll-padding-bottom: calc(var(--studio-footer-reserve, 168px) + env(safe-area-inset-bottom, 0px));
  }

  body.app-skin .wizard-bottom-bar {
    padding: 12px max(14px, env(safe-area-inset-right, 14px));
    padding-left: max(14px, env(safe-area-inset-left, 14px));
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }

  body.app-skin .wizard-bottom-bar button {
    min-width: 108px;
    min-height: 48px;
    padding: 12px 14px;
    font-weight: 600;
  }

  body.app-skin .wizard-bottom-bar .save-status {
    font-size: 12px;
    line-height: 1.35;
    max-width: 38%;
  }

  /* Krok 5 — dużo przycisków: pełna szerokość, czytelna kolejność */
  body.app-skin .wizard-summary-actions {
    flex-direction: column;
    align-items: stretch;
  }

  body.app-skin .wizard-summary-actions button {
    width: 100%;
    min-height: 48px;
    justify-content: center;
  }

  body.app-skin .wizard-save-actions {
    flex-direction: column;
    align-items: stretch;
  }

  body.app-skin .wizard-save-actions select,
  body.app-skin .wizard-save-actions button {
    width: 100%;
    min-width: 0;
  }

  body.app-skin .wizard-preview-html-frame {
    min-height: 240px;
  }

  /* Wyniki wyszukiwania: jedna kolumna na wąskich ekranach */
  body.app-skin .search-results {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  body.app-skin .search-result-card .title {
    font-size: 14px;
    line-height: 1.35;
  }

  /* Karty draftów — większy tekst tytułu */
  body.app-skin .draft-card-title {
    font-size: 15px;
  }

  /* Dashboard: jeden rząd akcji pod nagłówkiem */
  body.app-skin:not(.editor-skin) .page-header .header-actions {
    width: 100%;
  }

  body.app-skin:not(.editor-skin) .page-header .header-actions .ghost-link,
  body.app-skin:not(.editor-skin) .page-header .header-actions button {
    width: 100%;
  }

  /* Kreator: nagłówek z powrotem + ID draftu */
  body.app-skin .wizard-header {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  body.app-skin .wizard-header .back-link {
    font-size: 15px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  body.app-skin .wizard-header .draft-id {
    font-size: 12px;
    width: 100%;
    margin-top: 4px;
    word-break: break-all;
  }

  /* Legacy edytor: przywróć skrócony opis pod H1 (editor.css ukrywał cały blok) */
  body.app-skin.editor-skin .page-header.editor-hero .subtle {
    display: -webkit-box !important;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.45;
    margin-top: 8px;
    max-height: none;
  }

  /* Edytor (/editor): sticky + ujemne marginesy łamały wejścia URL — pełna szerokość, brak „nakładki” */
  body.app-skin.editor-skin .page-header {
    position: relative;
    top: auto;
    z-index: 1;
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 16px;
  }

  /* Kolumna główna + stanowisko: jedna kolumna, pełna szerokość (bezpiecznik obok poprawki w editor.css) */
  body.app-skin.editor-skin .layout.layout-cineplex {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  body.app-skin.editor-skin .main-rail,
  body.app-skin.editor-skin .studio-expert-aside {
    max-width: 100%;
    min-width: 0;
  }

  /* Pasek „spine” — cienki separator, nie wysoki słup */
  body.app-skin.editor-skin .editor-split-spine {
    min-height: 4px;
    height: 4px;
    flex-shrink: 0;
  }

  body.app-skin.editor-skin .studio-director-tab-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  body.app-skin.editor-skin .studio-director-tab {
    min-height: 44px;
    font-size: 13px;
  }
}

/* Bardzo wąskie telefony */
@media (max-width: 380px) {
  body.app-skin .wizard-step {
    min-width: 88px;
  }
}
