/* ==========================================================================
   Wyniki zawodów pływackich — style.css
   ========================================================================== */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;

  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-soft: #e0f2fe;

  --accent: #0f766e;
  --accent-hover: #115e59;

  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;

  --dz-bg: #fce7f3;
  --dz-text: #be185d;
  --ch-bg: #dbeafe;
  --ch-text: #1d4ed8;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header / Topbar */
.topbar {
  background: linear-gradient(135deg, #0c4a6e 0%, #0369a1 55%, #0284c7 100%);
  color: #ffffff;
  padding: 16px 0 14px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: rgba(255, 255, 255, 0.85);
}

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

/* Save Status Pill */
.save-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.25);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}

.save-status.status-saved .status-dot { background: #4ade80; }
.save-status.status-local .status-dot { background: #fbbf24; }
.save-status.status-saving .status-dot { background: #38bdf8; animation: pulse 1s infinite; }
.save-status.status-error .status-dot { background: #f87171; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* Progress Bar */
.progress-wrap {
  margin-top: 12px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 5px;
}

.progress-bar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4ade80, #22d3ee);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: #16a34a;
  color: #ffffff;
}
.btn-primary:hover { background: #15803d; }

.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.25); }

.btn-accent {
  background: var(--accent);
  color: #ffffff;
}
.btn-accent:hover { background: var(--accent-hover); }

.btn-danger-outline {
  background: rgba(220, 38, 38, 0.18);
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.45);
}
.btn-danger-outline:hover {
  background: #dc2626;
  color: #ffffff;
  border-color: #dc2626;
}

/* Main Content */
.main-content {
  padding-top: 20px;
  padding-bottom: 48px;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.search-box {
  flex: 1 1 240px;
}

.search-box input {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-alt);
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.class-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.class-chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.class-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.class-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* Help Banner */
.help-banner {
  background: var(--primary-soft);
  border: 1px solid #bae6fd;
  color: #0c4a6e;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.86rem;
  margin-bottom: 20px;
}

.help-banner code,
.help-banner kbd {
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #7dd3fc;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

/* Section Headers */
.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.section-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text);
}

.section-desc {
  margin: 2px 0 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.section-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* Classes Grid */
.classes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.class-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.class-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 15px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

.class-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.class-pill {
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 3px 11px;
  border-radius: 8px;
}

.class-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.class-counter {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-muted);
}

.class-counter.done {
  background: var(--success-soft);
  color: var(--success);
}

/* Class Table */
.class-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.class-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.class-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.class-table tr:last-child td {
  border-bottom: none;
}

.class-table tr.has-time {
  background-color: #fbfdff;
}

.class-table tr.flash-updated {
  animation: rowFlash 1.4s ease;
}

@keyframes rowFlash {
  0% { background-color: #bbf7d0; }
  100% { background-color: #fbfdff; }
}

.rank-cell {
  width: 54px;
  font-weight: 700;
  text-align: center;
  color: var(--text-muted);
  white-space: nowrap;
}

.rank-cell.medal-1 { color: #b45309; }
.rank-cell.medal-2 { color: #475569; }
.rank-cell.medal-3 { color: #9a3412; }

.student-name {
  font-weight: 600;
  color: var(--text);
}

.gender-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}

.gender-Dz {
  background: var(--dz-bg);
  color: var(--dz-text);
}

.gender-Ch {
  background: var(--ch-bg);
  color: var(--ch-text);
}

/* Time Input Group */
.time-cell {
  width: 175px;
}

.time-input-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.time-input {
  width: 98px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text);
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.time-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.16);
}

.time-input.filled {
  border-color: #86efac;
  background: #f0fdf4;
  color: #14532d;
}

.time-input.invalid {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.btn-mini {
  width: 28px;
  height: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.12s ease;
}

.btn-mini-ok:hover {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}

.btn-mini-clear:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-mini-clear.hidden {
  visibility: hidden;
  pointer-events: none;
}

.print-time {
  display: none;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* General Ranking Section */
.ranking-section {
  margin-top: 34px;
  scroll-margin-top: 110px;
}

.ranking-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-btn {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.ranking-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 15px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.stat-value {
  margin-top: 4px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.ranking-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.ranking-table th {
  text-align: left;
  padding: 11px 14px;
  background: var(--surface-alt);
  border-bottom: 2px solid var(--border);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.ranking-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
}

.ranking-table tbody tr:hover {
  background: #f8fafc;
}

.ranking-table tbody tr.podium-1 { background: #fefce8; }
.ranking-table tbody tr.podium-2 { background: #f8fafc; }
.ranking-table tbody tr.podium-3 { background: #fff7ed; }

.col-rank { width: 90px; }
.col-cls { width: 80px; }
.col-gender { width: 80px; }
.col-time { width: 130px; font-variant-numeric: tabular-nums; font-weight: 700; }
.col-diff { width: 145px; font-variant-numeric: tabular-nums; color: var(--text-muted); }

.leader-badge {
  display: inline-block;
  background: var(--success-soft);
  color: var(--success);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 999px;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-light);
  font-size: 0.94rem;
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 18px 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-light);
  background: var(--surface);
}

/* Toast */
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 999;
}

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

/* Responsive */
@media (max-width: 960px) {
  .classes-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    position: static;
  }
  .ranking-stats {
    grid-template-columns: 1fr;
  }
  .time-cell {
    width: 155px;
  }
  .time-input {
    width: 82px;
  }
}

/* Print / PDF */
@media print {
  body {
    background: #ffffff;
    color: #000000;
    font-size: 11pt;
  }
  .no-print {
    display: none !important;
  }
  .topbar {
    position: static;
    background: #ffffff !important;
    color: #000000 !important;
    box-shadow: none;
    border-bottom: 2px solid #000000;
    padding: 0 0 10px;
  }
  .subtitle,
  .progress-meta {
    color: #333333 !important;
  }
  .progress-bar {
    display: none;
  }
  .classes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .class-card {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #999999;
  }
  .time-input-group {
    display: none !important;
  }
  .print-time {
    display: inline !important;
  }
  .ranking-section {
    page-break-before: always;
    margin-top: 0;
  }
  .ranking-card,
  .stat-card {
    box-shadow: none;
    border: 1px solid #999999;
  }

  /* Poprawki wydruku: czasy nie mogą się ucinać w wąskich kolumnach A4 */
  .class-card,
  .ranking-card {
    overflow: visible;
  }
  .class-table {
    font-size: 9.5pt;
  }
  .class-table th,
  .class-table td {
    padding: 4px 6px;
  }
  .class-table th:first-child,
  .class-table td:first-child {
    width: 44px !important;
    white-space: nowrap;
  }
  .time-cell {
    width: auto !important;
    white-space: nowrap;
    text-align: right;
  }
  .print-time {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }
  .ranking-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
  .ranking-table {
    font-size: 9.5pt;
  }
  .ranking-table th,
  .ranking-table td {
    padding: 5px 7px;
  }
  .ranking-table thead {
    display: table-header-group; /* nagłówek tabeli na każdej stronie */
  }
  .ranking-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .ranking-table .col-time,
  .ranking-table .col-diff,
  .ranking-table .col-rank {
    white-space: nowrap;
  }
  /* Zachowaj kolory medali i podium w PDF */
  .rank-cell,
  .ranking-table tbody tr,
  .gender-badge,
  .class-pill,
  .class-counter,
  .leader-badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

@page {
  size: A4;
  margin: 12mm 10mm;
}
