:root {
  --primary: #C25E3E;
  --primary-hover: #A74D30;
  --primary-light: #FAF2ED;
  --secondary: #D97757;
  --bg-cream: #FAF7F2;
  --card-bg: #FFFFFF;
  --text-main: #2C2523;
  --text-muted: #78716C;
  --border-color: #E8E2D9;
  --tag-bg: #F5EFEB;
  --tag-hover: #EFE6DF;
  --tag-active: #C25E3E;
  --success: #15803D;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --shadow-sm: 0 2px 8px rgba(44, 37, 35, 0.05);
  --shadow-md: 0 10px 30px rgba(44, 37, 35, 0.07);
  --radius-btn: 8px;
  --radius-pill: 8px;
  --radius-card: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-cream);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(245, 235, 226, 0.7) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(238, 226, 214, 0.6) 0%, transparent 40%);
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
}

/* TOP BAR */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

/* RZĄD NARZĘDZI
   Kafelki narzędzi w jednej linii, przewijanej w poziomie na wąskim ekranie.
   Wcześniej zawijały się w trzy nierówne rzędy pomieszane z przyciskami akcji. */
.tool-nav {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  padding: 2px 2px 10px;
  margin-bottom: 16px;
}

/* Pasek przewijania chowamy: przy kafelkach wyglądał jak zepsuty element,
   a przewijanie działa palcem i kółkiem myszy. */
.tool-nav {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.tool-nav::-webkit-scrollbar {
  display: none;
  height: 0;
}

.tool-nav .btn-icon {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Główny przycisk sprzedażowy w nagłówku, żeby nie konkurował z kafelkami narzędzi */
.btn-pro-cta {
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-pro-cta:hover {
  filter: brightness(0.95);
}

/* Wąski ekran: nagłówek nie może się rozjeżdżać na trzy rzędy.
   Przyciski akcji idą w jednym rzędzie przewijanym w poziomie,
   a przycisk "Wersja pełna" stoi pierwszy, żeby był widoczny bez przewijania. */
@media (max-width: 820px) {
  .top-nav {
    gap: 8px;
  }

  .promo-badge {
    flex: 0 0 auto;
  }

  .nav-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
  }

  .nav-actions::-webkit-scrollbar {
    display: none;
    height: 0;
  }

  .nav-actions .btn-icon,
  .nav-actions .btn-pro-cta {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .btn-pro-cta {
    order: -1;
  }
}

.promo-badge {
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 6px;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 6px rgba(194, 94, 62, 0.35);
}

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-icon {
  background: white;
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.btn-icon:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* HEADER SECTION (Ciepły motyw rzemieślniczy) */
.hero-header {
  text-align: center;
  margin-bottom: 32px;
  position: relative;
}

.hero-pill-badge {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 6px 18px;
  border-radius: 6px;
  margin-bottom: 14px;
  box-shadow: 0 4px 12px rgba(194, 94, 62, 0.25);
}

.hero-title {
  font-family: var(--font-serif);
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 12px;
  line-height: 1.2;
}

.hero-title .accent-i {
  color: var(--primary);
  font-style: italic;
  font-family: var(--font-serif);
}

.hero-subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 620px;
  margin: 0 auto;
}

/* GŁÓWNY UKŁAD 2-KOLUMNOWY */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 28px;
  align-items: start;
}

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  .hero-title {
    font-size: 2.2rem;
  }
}

/* KARTY */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-card);
  padding: 28px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  position: relative;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* FORMULARZ */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-label span.hint {
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  background: #FCFAF8;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text-main);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(194, 94, 62, 0.15);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* PRZYCISKI GENEROWANIA */
.btn-generate {
  width: 100%;
  background: linear-gradient(135deg, var(--primary) 0%, #A74D30 100%);
  color: white;
  border: none;
  padding: 14px 20px;
  border-radius: var(--radius-btn);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(194, 94, 62, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
  margin-top: 8px;
}

.btn-generate:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(194, 94, 62, 0.45);
}

.btn-generate:active {
  transform: translateY(0);
}

/* WYNIKI - PODGLĄD TAGÓW I TYTUŁU */
.preview-card {
  border: 1.5px solid var(--border-color);
  background: white;
}

.preview-badge-header {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* TAGI PILLS (ciepły styl rzemieślniczy) */
.tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 600;
  background: var(--tag-bg);
  color: #5C2C1E;
  cursor: pointer;
  border: 1px solid #E5DCD5;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  user-select: none;
  position: relative;
}

.tag-pill:hover {
  background: var(--tag-hover);
  border-color: #D8CCC3;
  transform: translateY(-1px);
}

/* Pierwszy tag jako wyróżniony (ciepła terakota) */
.tag-pill.featured {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(194, 94, 62, 0.3);
}

.tag-pill.featured:hover {
  background: var(--primary-hover);
}

.tag-chars {
  font-size: 0.72rem;
  opacity: 0.75;
  font-weight: 500;
}

.tag-pill.copied {
  background: var(--success) !important;
  color: white !important;
}

/* SEKCJA TYTUŁU ETSY */
.title-box {
  background: #FAF7F2;
  border: 1px dashed #D97757;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}

.title-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.title-content {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.4;
  word-break: break-word;
}

.char-counter {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: #E8E2D9;
  color: var(--text-main);
}

.char-counter.limit-safe {
  background: #E8F5E9;
  color: #1B5E20;
}

.char-counter.limit-warn {
  background: #FFF3E0;
  color: #E65100;
}

/* 6 FRAZ DO TYTUŁU */
.phrases-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.phrase-pill {
  background: #FAF2ED;
  border: 1px solid #E8D5C8;
  color: #8A3B24;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.phrase-pill:hover {
  background: #F3E5DC;
  border-color: var(--primary);
}

/* PRZYCISKI AKCJI KOPIOWANIA */
.action-buttons-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
}

.btn-secondary {
  flex: 1;
  background: white;
  border: 1.5px solid var(--primary);
  color: var(--primary);
  padding: 10px 16px;
  border-radius: var(--radius-btn);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--primary);
  color: white;
}

/* DOLNE PIGUŁKI LICZNIKÓW */
.footer-stats-badges {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-pill {
  background: #FAF7F2;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 4px rgba(44, 37, 35, 0.04);
}

.stat-pill strong {
  color: var(--primary);
  font-weight: 800;
}

/* CYTAT NA DOLE */
.inspirational-quote {
  text-align: center;
  font-style: italic;
  font-size: 1.15rem;
  color: #6B5D57;
  margin: 16px 0;
  font-family: var(--font-serif);
}

/* HISTORIA I ZAPISANE OFERTY */
.history-section {
  margin-top: 36px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.history-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.history-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.history-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
}

.history-tags-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.mini-tag {
  background: #FAF2ED;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  color: #8A3B24;
}

.history-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
}

.btn-link:hover {
  text-decoration: underline;
}

.btn-link-danger {
  color: #DC2626;
}

/* Akcje w sekcji dostępu: osobne odstępy, żeby "Odłącz dostęp" nie kleiło się
   ani do przycisku sprawdzania, ani do zdania o prywatności. */
#btnDisconnectAccess {
  padding: 8px 2px;
  margin-top: 4px;
}

#accessSection .form-group {
  margin-bottom: 0;
}

#accessSection p {
  margin-top: 10px;
}

/* MODAL USTAWIEŃ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(44, 37, 35, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 14px;
  max-width: 500px;
  width: 100%;
  padding: 28px;
  box-shadow: 0 20px 40px rgba(44, 37, 35, 0.15);
  /* Okno nie może wyjść za ekran: przy długiej treści (dostęp, historia) przewija się w środku.
     Bez tego przy niskim oknie przycisk zapisu uciekał poza widok, a tytuł był ucinany. */
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Niskie okno, na przykład telefon w poziomie: mniejszy margines wewnętrzny,
   żeby treść zmieściła się bez przewijania, gdy się da. */
@media (max-height: 560px) {
  .modal-content {
    padding: 18px 20px;
    max-height: calc(100vh - 16px);
  }
  .modal-overlay {
    padding: 8px;
  }
}

/* Przycisk zamykania: był 13 na 26 pikseli, czyli mniej niż palec.
   Teraz ma 40 na 40 i widoczny obszar kliknięcia. */
.modal-content > h2 button,
#btnCloseSettings {
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: -8px -8px 0 0;
}

.modal-content > h2 button:hover,
#btnCloseSettings:hover {
  background: rgba(44, 37, 35, 0.06);
}

/* TOAST POWIADOMIENIE */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #2C2523;
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(44, 37, 35, 0.25);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.25s ease-out;
  pointer-events: none;
  z-index: 9999;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* T4: licznik przekroczonego limitu (shared/ui.js, charCounter) */
.char-counter.limit-danger {
  background: #FDE8E8;
  color: #9B1C1C;
}

/* OPTYMALIZACJE DLA URZĄDZEŃ MOBILNYCH (SMARTFONY / TABLETY / PWA) */
@media (max-width: 768px) {
  body {
    padding: max(12px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .main-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  /* Pasek górny i akcje.
     Zasada: znak marki w pierwszej linii, przyciski akcji w jednej linii
     przewijanej w poziomie. Wcześniej wszystko zawijało się w cztery rzędy,
     bo akcje miały flex-wrap: wrap i rosły na całą szerokość. */
  .top-nav {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
  }

  .promo-badge {
    padding: 6px 12px;
  }

  .nav-actions {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: center;
    gap: 6px;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
  }

  .nav-actions::-webkit-scrollbar {
    display: none;
    height: 0;
  }

  .nav-actions .btn-icon,
  .nav-actions .btn-pro-cta {
    flex: 0 0 auto;
    min-height: 42px;
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .btn-pro-cta {
    order: -1;
  }

  /* Kafelki narzędzi: jedna linia przewijana palcem, bez widocznego paska */
  .tool-nav {
    padding-bottom: 6px;
    margin-bottom: 12px;
  }

  /* Sekcja nagłówka */
  .hero-header {
    margin-bottom: 20px;
  }

  .hero-pill-badge {
    padding: 5px 14px;
    font-size: 0.75rem;
    margin-bottom: 10px;
  }

  .hero-title {
    font-size: 1.85rem;
    margin-bottom: 8px;
    line-height: 1.25;
  }

  .hero-subtitle {
    font-size: 0.95rem;
    line-height: 1.45;
    padding: 0 4px;
  }

  /* Karty */
  .card {
    padding: 18px 14px;
    border-radius: 14px;
  }

  .card-title {
    font-size: 1.15rem;
    margin-bottom: 14px;
  }

  /* Formularz: 16px zapobiega auto-zoomowaniu w Safari na iPhone */
  .form-input, .form-select, .form-textarea {
    font-size: 16px !important;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 8px;
  }

  .form-textarea {
    min-height: 80px;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Główny przycisk generowania */
  .btn-generate {
    min-height: 48px;
    padding: 14px 18px;
    font-size: 1.05rem;
    margin-top: 12px;
    border-radius: 8px;
  }

  /* Szybkie przykłady */
  .example-btn {
    min-height: 38px;
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  /* Przyciski kopiowania w wynikach */
  .action-buttons-group {
    flex-direction: column;
    gap: 8px;
  }

  .btn-secondary {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 0.88rem;
    flex-basis: auto !important;
  }

  /* Chmura tagów */
  .tags-cloud {
    gap: 8px;
    margin-bottom: 18px;
  }

  .tag-pill {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 0.88rem;
  }

  .phrase-pill {
    min-height: 34px;
    padding: 6px 11px;
    font-size: 0.82rem;
  }

  /* Box tytułu */
  .title-box {
    padding: 12px;
    margin-bottom: 16px;
    border-radius: 8px;
  }

  .title-content {
    font-size: 0.95rem;
    line-height: 1.4;
  }

  /* Dolne pigułki liczników */
  .footer-stats-badges {
    gap: 6px;
  }

  .stat-pill {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 0.8rem;
    flex: 1 1 auto;
    justify-content: center;
  }

  .inspirational-quote {
    font-size: 0.95rem;
    margin: 14px 0;
    line-height: 1.45;
  }

  /* Modale */
  .modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }

  .modal-content {
    max-height: 90vh;
    padding: 20px 16px;
    border-radius: 16px 16px 0 0;
    width: 100%;
  }

  /* Historia */
  .history-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Toast notification */
  .toast {
    left: 12px;
    right: 12px;
    bottom: 16px;
    width: auto;
    max-width: calc(100% - 24px);
    justify-content: center;
    text-align: center;
    font-size: 0.9rem;
    padding: 12px 16px;
    border-radius: 8px;
  }

  /* Specyficzne widoki narzędzi */
  .pinterest-cards-grid {
    grid-template-columns: 1fr !important;
  }

  .audit-action-bar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .audit-action-bar > div {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
}

@media (max-width: 420px) {
  .hero-title {
    font-size: 1.6rem;
  }

  .tag-pill {
    font-size: 0.82rem;
    padding: 7px 10px;
  }

  .card-title {
    font-size: 1.05rem;
  }
}

/* T9: style drukowania PDF i widoków audytu */
@media print {
  body {
    background: #fff !important;
    padding: 0 !important;
  }
  .top-nav,
  .hero-section,
  .tool-panel,
  .history-section,
  .toast,
  .modal-overlay,
  .no-print,
  .action-buttons-group,
  .preview-badge-header {
    display: none !important;
  }
  .preview-panel {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .audit-report-container {
    gap: 16px !important;
  }
  .audit-top5-box {
    border: 2px solid #000 !important;
    background: #fff !important;
    page-break-inside: avoid !important;
  }
  .audit-card {
    border: 1px solid #ccc !important;
    page-break-inside: avoid !important;
  }
}
