:root {
  --bg: #0f1115;
  --panel: #171a21;
  --text: #e6e8eb;
  --muted: #9aa2ad;
  --accent: #4fb0ff;
  --border: #2a2e37;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topnav {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  /* safe-area: tryb PWA (black-translucent) i wcięcie ekranu w iPhone */
  padding: calc(0.7rem + env(safe-area-inset-top, 0px)) max(1.5rem, env(safe-area-inset-right, 0px)) 0.7rem max(1.5rem, env(safe-area-inset-left, 0px));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
  overflow-x: auto;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topnav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.3rem 0.55rem;
  flex: 0 0 auto;
  border-radius: 6px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.topnav a:hover { color: var(--text); }

.topnav .brand {
  color: var(--text);
  font-weight: 600;
  margin-right: 0.6rem;
}

@media (min-width: 769px) {
  .topnav a.active:not(.brand) {
    color: var(--accent);
    background: rgba(79, 176, 255, 0.12);
  }
  .topnav a:not(.brand):hover { background: rgba(255, 255, 255, 0.05); }
}

.content {
  padding: 1.5rem;
  padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
  padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  max-width: 1280px;
  margin: 0 auto;
}

h1 { font-size: 1.4rem; margin-top: 0; line-height: 1.3; }
h2 { line-height: 1.3; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
}

.card .label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card .value {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 0.25rem;
}

.chart-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.range-picker { margin-bottom: 1rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.range-picker a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}
.range-picker a.active { color: var(--accent); border-color: var(--accent); }

/* ============ TABELE I KONTENERY RESPONSYWNE ============ */
.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.85rem;
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: #3a4150 #171a21;
}

.table-responsive::-webkit-scrollbar {
  height: 6px;
}
.table-responsive::-webkit-scrollbar-track {
  background: #171a21;
}
.table-responsive::-webkit-scrollbar-thumb {
  background: #3a4150;
  border-radius: 3px;
}

.table-responsive table {
  width: 100%;
  min-width: 580px;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0;
}

.table-responsive.table-wide table {
  min-width: 980px;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  margin-top: 1rem;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 0.88rem;
  white-space: nowrap;
  vertical-align: middle;
}

th {
  background: #1c212c;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

/* Pierwsza kolumna - przypięta z lewej (sticky) przy poziomym przewijaniu */
.table-responsive th:first-child,
.table-responsive td:first-child {
  position: sticky;
  left: 0;
  background: #171a21;
  z-index: 2;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.4);
}
.table-responsive th:first-child {
  background: #1f2533;
  z-index: 3;
}

.table-responsive tbody tr:nth-child(even) td {
  background-color: rgba(255, 255, 255, 0.02);
}

.table-responsive tbody tr:nth-child(even) td:first-child {
  background-color: #1a1e27;
}

.table-responsive tbody tr:hover td {
  background-color: rgba(79, 176, 255, 0.08);
}

td.col-wrap, th.col-wrap, td.notes-cell {
  white-space: normal;
  min-width: 220px;
  max-width: 340px;
  line-height: 1.45;
}

td.col-title, th.col-title {
  white-space: normal;
  min-width: 150px;
  line-height: 1.4;
}

.table-scroll-hint {
  display: none;
  font-size: 0.74rem;
  color: var(--accent);
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
  text-align: right;
  letter-spacing: 0.02em;
}

.muted { color: var(--muted); }
.ok { color: #4fd18c; }
.err { color: #ff6b6b; }

.diff-neg { color: #4fd18c; font-weight: 600; }
.diff-pos { color: #ffa726; font-weight: 600; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-heavy { background: #3d1f28; color: #ff6b8b; border: 1px solid #7a2b44; }
.badge-mod   { background: #1c2b3d; color: #4fb0ff; border: 1px solid #234c73; }
.badge-light { background: #1f3328; color: #4fd18c; border: 1px solid #2b5c40; }
.badge-rest  { background: #262a33; color: #9aa2ad; border: 1px solid #3c4250; }

.workout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.workout-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
}
.workout-card .id {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--accent);
}
.workout-card h4 {
  margin: 0.3rem 0;
  font-size: 0.95rem;
}

.plan-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.section-anchor {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.section-anchor a {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  text-decoration: none;
}
.section-anchor a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.checklist-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.9rem;
}
.checklist-item .bullet { color: var(--accent); }

/* ============ RAPORT TRENERA & ZALECENIA ============ */
.coach-banner {
  background: linear-gradient(180deg, #1b202a 0%, #151820 100%);
  border: 1px solid #333a48;
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.coach-header {
  margin-bottom: 1.1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.coach-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.coach-badge-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.coach-badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.coach-headline {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0.25rem 0 0.2rem 0;
  line-height: 1.4;
  color: #ffffff;
}

.coach-date-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

.coach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.2rem;
}

.coach-card {
  background: rgba(15, 17, 21, 0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem;
}

.coach-card.highlight {
  background: rgba(23, 34, 48, 0.45);
  border-color: rgba(79, 176, 255, 0.35);
}

.coach-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.coach-card-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #f1f3f5;
}

.coach-subheading {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-weight: 600;
  margin-top: 0.85rem;
  margin-bottom: 0.4rem;
}

.coach-list {
  list-style: none;
  padding-left: 0;
  margin: 0 0 0.6rem 0;
}

.coach-list li {
  position: relative;
  padding-left: 1.25rem;
  margin-bottom: 0.45rem;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #d2d7e0;
}

.coach-list li::before {
  content: "▸";
  position: absolute;
  left: 0.15rem;
  color: var(--accent);
  font-size: 0.9rem;
}

/* ============ PRZEWODNIKI I LEGENDY TABEL ============ */
.table-legend {
  margin-top: 1.25rem;
  background: rgba(15, 17, 21, 0.75);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 1.1rem 1.3rem;
  font-size: 0.88rem;
  line-height: 1.5;
}

.table-legend-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: #f1f3f5;
  margin-bottom: 0.85rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.table-legend-title .icon {
  font-size: 1.1rem;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.legend-col h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  border-bottom: 1px solid rgba(79, 176, 255, 0.2);
  padding-bottom: 0.3rem;
}

.legend-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.legend-col li {
  position: relative;
  padding-left: 1.1rem;
  margin-bottom: 0.5rem;
  font-size: 0.84rem;
  color: #c5cbd5;
  line-height: 1.45;
}

.legend-col li::before {
  content: "•";
  position: absolute;
  left: 0.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend-col li strong {
  color: #f1f3f5;
}

.legend-tag {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.74rem;
  font-weight: 600;
  margin-right: 0.35rem;
}

.legend-tag.ok {
  background: rgba(79, 209, 140, 0.15);
  color: #4fd18c;
  border: 1px solid rgba(79, 209, 140, 0.3);
}

.legend-tag.warn {
  background: rgba(255, 167, 38, 0.15);
  color: #ffa726;
  border: 1px solid rgba(255, 167, 38, 0.3);
}

.legend-tag.err {
  background: rgba(255, 107, 139, 0.15);
  color: #ff6b8b;
  border: 1px solid rgba(255, 107, 139, 0.3);
}

.legend-tag.info {
  background: rgba(79, 176, 255, 0.15);
  color: #4fb0ff;
  border: 1px solid rgba(79, 176, 255, 0.3);
}

/* ============ RESPONSYWNOŚĆ MOBILNA (SMARTFON) ============ */
@media (max-width: 768px) {
  .topnav {
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    overflow-x: auto;
    white-space: nowrap;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topnav::-webkit-scrollbar {
    display: none;
  }
  .topnav .brand {
    font-size: 0.9rem;
    margin-right: 0.4rem;
  }
  .topnav {
    padding-top: calc(0.6rem + env(safe-area-inset-top, 0px));
    padding-left: max(0.8rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.8rem, env(safe-area-inset-right, 0px));
    scroll-padding: 0 0.8rem;
  }
  .topnav a {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0.35rem 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
  }
  .topnav a.active {
    background: var(--accent);
    color: #0f1115;
    font-weight: 600;
    border-color: var(--accent);
  }
  .cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
  }
  .card {
    padding: 0.75rem 0.85rem;
  }
  .card .label {
    font-size: 0.72rem;
  }
  .card .value {
    font-size: 1.35rem;
  }
  .coach-banner {
    padding: 1rem;
  }
  .coach-headline {
    font-size: 1.05rem;
  }
  .coach-grid {
    grid-template-columns: 1fr;
  }
  .legend-grid {
    grid-template-columns: 1fr;
  }
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }
  .content {
    padding: 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    max-width: 100%;
  }
  h1 { font-size: 1.25rem; }
  .plan-section h2, .coach-banner h2 { font-size: 1.15rem; }
  .range-picker a {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.9rem;
    font-size: 0.9rem;
  }
  .section-anchor {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-left: -0.75rem;
    margin-right: -0.75rem;
    padding: 0 0.75rem 0.25rem;
  }
  .section-anchor::-webkit-scrollbar { display: none; }
  .section-anchor a {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.5rem 0.8rem;
  }
  .coach-card { padding: 0.85rem; }
  .table-legend { padding: 0.9rem; }
  .workout-grid { grid-template-columns: 1fr; }
  .chart-block .js-plotly-plot { max-width: 100%; }
  .plan-section {
    padding: 0.85rem;
    overflow: hidden;
    max-width: 100%;
  }
  .table-scroll-hint {
    display: block;
  }
  .table-responsive {
    margin-top: 0.6rem;
    margin-bottom: 1rem;
    border-radius: 6px;
  }
  th, td {
    padding: 0.5rem 0.65rem;
    font-size: 0.8rem;
  }
  .chart-block {
    margin-bottom: 1rem;
    border-radius: 8px;
  }
}

/* ============ EKRAN BLOKADY PIN ============ */
#pin-lock-overlay {
  position: fixed;
  inset: 0;
  background: #0f1115;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  transition: opacity 0.3s ease;
}

#pin-lock-overlay.unlocking {
  opacity: 0;
  pointer-events: none;
}

.pin-card {
  background: #171a21;
  border: 1px solid #2a2e37;
  border-radius: 16px;
  padding: 2rem 1.8rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.pin-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.pin-card h2 {
  font-size: 1.25rem;
  margin: 0.3rem 0;
  color: #f1f3f5;
}

.pin-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.2rem 0 1.25rem 0;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 0.9rem;
  margin-bottom: 0.8rem;
}

.pin-dots .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #4a5160;
  background: transparent;
  transition: all 0.2s ease;
}

.pin-dots .dot.filled {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(79, 176, 255, 0.6);
}

.pin-dots.shake {
  animation: pinShake 0.4s ease-in-out;
}

@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.pin-status {
  min-height: 1.2rem;
  font-size: 0.82rem;
  margin-bottom: 0.8rem;
}

.pin-status.err {
  color: #ff6b8b;
  font-weight: 500;
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin-bottom: 1.2rem;
}

.pin-keypad .key {
  background: #20242e;
  border: 1px solid #303644;
  border-radius: 12px;
  color: #f1f3f5;
  font-size: 1.4rem;
  font-weight: 600;
  padding: 0.75rem 0;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.pin-keypad .key:active {
  background: var(--accent);
  color: #0f1115;
  transform: scale(0.96);
}

.pin-keypad .key-clear, .pin-keypad .key-back {
  font-size: 1.1rem;
  color: var(--muted);
}

.pin-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
