/* ==========================================================================
   Dziennik Treningowy - System Stylów CSS (Mobile-First)
   Wspólne zmienne CSS, wysoki kontrast (WCAG AA), 4 motywy kolorystyczne
   ========================================================================== */

:root, [data-theme="embers-pastel"] {
  --bg-app: #1f2736;
  --bg-surface: #263144;
  --bg-card: #2c384d;
  --bg-card-highlight: #35435c;
  --bg-input: #1a222f;
  
  --border-subtle: #38465e;
  --border-focus: #fe9677;
  --border-card: #41436a; /* #41436A z palety Embers */

  --text-main: #fcf9f5;
  --text-muted: #b4c0d0;
  --text-dim: #7f8fa5;

  --accent-primary: #fe9677; /* #FE9677 - Pastelowa Brzoskwinia */
  --accent-primary-hover: #f78563;
  --accent-primary-dim: rgba(254, 150, 119, 0.18);
  --btn-text-on-accent: #1f2736; /* WCAG AAA kontrast 10.6:1 */

  --accent-secondary: #f64668; /* #F64668 - Koral / Ciepła Róża */
  --accent-secondary-dim: rgba(246, 70, 104, 0.18);

  --accent-berry: #984063; /* #984063 - Śliwka / Jagoda */
  --accent-indigo: #41436a; /* #41436A - Ciemny fiolet grafit */

  --status-warning: #f59e0b;
  --status-danger: #f64668;
  --status-danger-dim: rgba(246, 70, 104, 0.18);

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-button: 0 4px 10px rgba(254, 150, 119, 0.25);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

/* 2. Pastelowy Jasny (Koral & Krem) */
[data-theme="pastel-light"] {
  --bg-app: #fcf8f6;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-highlight: #f8eeea;
  --bg-input: #fdfaf9;

  --border-subtle: #ebdcd7;
  --border-focus: #f64668;
  --border-card: #e5cfc9;

  --text-main: #2b2226;
  --text-muted: #5e5055;
  --text-dim: #8b7980;

  --accent-primary: #f64668;
  --accent-primary-hover: #e03254;
  --accent-primary-dim: rgba(246, 70, 104, 0.12);
  --btn-text-on-accent: #ffffff;

  --accent-secondary: #fe9677;
  --accent-secondary-dim: rgba(254, 150, 119, 0.16);

  --status-warning: #d97706;
  --status-danger: #dc2626;
  --status-danger-dim: rgba(220, 38, 38, 0.12);

  --shadow-card: 0 2px 10px rgba(152, 64, 99, 0.08);
  --shadow-button: 0 2px 6px rgba(246, 70, 104, 0.2);
}

/* 3. Ciemny (Szmaragd) */
[data-theme="dark-default"], [data-theme="dark"] {
  --bg-app: #090d16;
  --bg-surface: #0f172a;
  --bg-card: #141e33;
  --bg-card-highlight: #1b2844;
  --bg-input: #0b1120;
  
  --border-subtle: #1e293b;
  --border-focus: #10b981;
  --border-card: #25334d;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-primary: #10b981;
  --accent-primary-hover: #059669;
  --accent-primary-dim: rgba(16, 185, 129, 0.15);
  --btn-text-on-accent: #090d16;

  --accent-secondary: #0ea5e9;
  --accent-secondary-dim: rgba(14, 165, 233, 0.15);

  --status-warning: #f59e0b;
  --status-danger: #ef4444;
  --status-danger-dim: rgba(239, 68, 68, 0.15);
}

/* 2. Grafit i Złoto - Elegancki, głęboki antracyt, szampańskie złoto, czytelny ciemny tekst na złocie */
[data-theme="graphite-gold"] {
  --bg-app: #121214;
  --bg-surface: #18181c;
  --bg-card: #1f1f25;
  --bg-card-highlight: #282832;
  --bg-input: #151518;

  --border-subtle: #2d2d3a;
  --border-focus: #d4af37;
  --border-card: #3a3a4c;

  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --accent-primary: #d4af37;
  --accent-primary-hover: #c49e2b;
  --accent-primary-dim: rgba(212, 175, 55, 0.16);
  --btn-text-on-accent: #121214; /* Ciemny tekst na złotym tle: kontrast 9.5:1 (WCAG AAA) */

  --accent-secondary: #e5c053;
  --accent-secondary-dim: rgba(229, 192, 83, 0.16);

  --status-warning: #f59e0b;
  --status-danger: #f87171;
  --status-danger-dim: rgba(248, 113, 113, 0.15);

  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-button: 0 4px 8px rgba(0, 0, 0, 0.35);
}

/* 3. Jasny Neutralny - Czysta biel/popiel, czarny tekst o kontraście 14:1, czytelny w słońcu */
[data-theme="light-neutral"], [data-theme="light"] {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-highlight: #f1f5f9;
  --bg-input: #f8fafc;

  --border-subtle: #e2e8f0;
  --border-focus: #0f172a;
  --border-card: #cbd5e1;

  --text-main: #0f172a; /* Głęboki grafit/czerń (wysoki kontrast) */
  --text-muted: #334155;
  --text-dim: #64748b;

  --accent-primary: #0f172a;
  --accent-primary-hover: #1e293b;
  --accent-primary-dim: rgba(15, 23, 42, 0.08);
  --btn-text-on-accent: #ffffff;

  --accent-secondary: #2563eb;
  --accent-secondary-dim: rgba(37, 99, 235, 0.1);

  --status-warning: #b45309;
  --status-danger: #dc2626;
  --status-danger-dim: rgba(220, 38, 38, 0.1);

  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-button: 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* 4. Ciemny Granat i Turkus - Głęboki chłodny granat z wyrazistym turkusem */
[data-theme="navy-turquoise"] {
  --bg-app: #080e1a;
  --bg-surface: #0e182e;
  --bg-card: #132240;
  --bg-card-highlight: #192d54;
  --bg-input: #0a1324;

  --border-subtle: #1c325c;
  --border-focus: #06b6d4;
  --border-card: #233e70;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-primary: #06b6d4;
  --accent-primary-hover: #0891b2;
  --accent-primary-dim: rgba(6, 182, 212, 0.16);
  --btn-text-on-accent: #080e1a;

  --accent-secondary: #38bdf8;
  --accent-secondary-dim: rgba(56, 189, 248, 0.15);

  --status-warning: #f59e0b;
  --status-danger: #f43f5e;
  --status-danger-dim: rgba(244, 63, 94, 0.15);

  --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-button: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Reset bazowy */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  /* Nie blokujemy zaznaczania tekstu na inputach i polach formularza */
}

input, textarea, select {
  font-family: inherit;
  font-size: 16px; /* Zapobiega automatycznemu powiększaniu na iOS */
  user-select: text;
  -webkit-user-select: text;
}

/* Kontener główny aplikacji */
#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 540px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg-app);
}

/* Nagłówek statusu */
.app-header {
  flex-shrink: 0;
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 20;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.brand-tag {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  background-color: var(--accent-primary-dim);
  color: var(--accent-primary);
  border: 1px solid var(--accent-primary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  user-select: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover, .btn-icon:active {
  background: var(--bg-card-highlight);
  color: var(--text-main);
}

/* Obszar zawartości (przewijany płynnie) */
.app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-bottom: 96px; /* Przestrzeń na dolny pasek nawigacyjny */
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: 80px;
}

/* Dolny pasek nawigacyjny */
.app-bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 68px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 30;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
}

.nav-tab-btn {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 500;
  transition: color 0.15s ease;
}

.nav-tab-btn .tab-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.nav-tab-btn.active {
  color: var(--accent-primary);
  font-weight: 700;
}

/* Karty i sekcje */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
}

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

.card-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Przyciski dotykowe dla kciuka (Thumb-friendly) */
.btn-primary {
  width: 100%;
  min-height: 52px;
  background: var(--accent-primary);
  color: var(--btn-text-on-accent, #ffffff);
  border: none;
  border-radius: var(--radius-lg);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-button);
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn-primary:active {
  transform: scale(0.98);
  filter: brightness(0.92);
}

.btn-secondary {
  width: 100%;
  min-height: 44px;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn-secondary:hover, .btn-secondary:active {
  background: var(--bg-card-highlight);
  border-color: var(--border-focus);
}

.btn-danger {
  background: var(--status-danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}

/* Pola numeryczne z dużymi przyciskami + i - */
.stepper-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 6px;
}

.btn-step {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-step:active {
  background: var(--accent-primary-dim);
  color: var(--accent-primary);
}

.stepper-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-main);
  text-align: center;
  min-width: 70px;
}

/* Segmenty wyboru (np. dyskomfort barku, rodzaj chwytu) */
.segmented-control {
  display: grid;
  grid-auto-flow: column;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  padding: 3px;
  border-radius: var(--radius-md);
}

.segment-btn {
  padding: 8px 4px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
}

.segment-btn.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.segment-btn.active.level-warning {
  background: rgba(245, 158, 11, 0.2);
  color: var(--status-warning);
}

.segment-btn.active.level-danger {
  background: var(--status-danger-dim);
  color: var(--status-danger);
}

/* Formularze i pola edycyjne */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-input, .input-field {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 1rem;
  transition: border-color 0.15s ease;
}

.form-input:focus, .input-field:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Lista serii */
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.set-index-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-primary-dim);
  color: var(--accent-primary);
  font-weight: 700;
  font-size: 0.75rem;
  margin-right: 8px;
}

/* Półprzezroczysty duch dla podpowiedzi */
.ghost-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-style: italic;
}

/* Powiadomienia Toast */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 90%;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.2s ease forwards;
}

.toast-error {
  border-color: var(--status-danger);
  color: #fff;
}

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

/* Okna modalne i arkusze dolne (Bottom Sheet) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

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

.modal-sheet {
  background: var(--bg-surface);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.25s ease forwards;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--text-dim);
  border-radius: 2px;
  margin: 0 auto 16px auto;
  opacity: 0.6;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* Karty wyboru motywów z podglądem kontrastu */
.theme-picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.theme-card {
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--bg-input);
}

.theme-card:hover, .theme-card.active {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.theme-preview-box {
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}
