/* ============================================
   НАСТАРТ Tracker — Swimming Progress
   Art direction: Aqua/Sport — cool blues, clean data
   ============================================ */

/* --- Design Tokens --- */
:root {
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);

  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --content-default: 960px;
  --content-wide: 1100px;
}

/* --- Light Mode (Aqua Sport) --- */
:root, [data-theme="light"] {
  --color-bg:             #f4f7fa;
  --color-surface:        #ffffff;
  --color-surface-2:      #f8fafb;
  --color-surface-offset: #eef2f6;
  --color-divider:        #dde3ea;
  --color-border:         #cdd5de;

  --color-text:           #1a2332;
  --color-text-muted:     #6b7a8d;
  --color-text-faint:     #a0acb9;
  --color-text-inverse:   #f8fafb;

  --color-primary:        #0077b6;
  --color-primary-hover:  #005f96;
  --color-primary-active: #004a78;
  --color-primary-light:  #e0f0fa;
  --color-primary-lighter:#cae8f7;

  --color-accent:         #00b4d8;
  --color-accent-light:   #def5fa;

  --color-success:        #2d9f3f;
  --color-error:          #d63a3a;
  --color-warning:        #e08a15;
  --color-gold:           #e8b517;

  --shadow-sm: 0 1px 3px rgba(26,35,50,0.06);
  --shadow-md: 0 4px 12px rgba(26,35,50,0.08);
  --shadow-lg: 0 12px 32px rgba(26,35,50,0.12);
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --color-bg:             #0f1419;
  --color-surface:        #161c24;
  --color-surface-2:      #1c2430;
  --color-surface-offset: #1a2230;
  --color-divider:        #263040;
  --color-border:         #2e3a4a;

  --color-text:           #d4dce6;
  --color-text-muted:     #7a8ca0;
  --color-text-faint:     #4a5a6e;
  --color-text-inverse:   #1a2332;

  --color-primary:        #4db8e8;
  --color-primary-hover:  #3aa0d0;
  --color-primary-active: #2888b8;
  --color-primary-light:  #162a3a;
  --color-primary-lighter:#1a3040;

  --color-accent:         #56d4f0;
  --color-accent-light:   #1a3040;

  --color-success:        #4fbf60;
  --color-error:          #f06060;
  --color-warning:        #f0a030;
  --color-gold:           #f0c830;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:             #0f1419;
    --color-surface:        #161c24;
    --color-surface-2:      #1c2430;
    --color-surface-offset: #1a2230;
    --color-divider:        #263040;
    --color-border:         #2e3a4a;
    --color-text:           #d4dce6;
    --color-text-muted:     #7a8ca0;
    --color-text-faint:     #4a5a6e;
    --color-text-inverse:   #1a2332;
    --color-primary:        #4db8e8;
    --color-primary-hover:  #3aa0d0;
    --color-primary-active: #2888b8;
    --color-primary-light:  #162a3a;
    --color-primary-lighter:#1a3040;
    --color-accent:         #56d4f0;
    --color-accent-light:   #1a3040;
    --color-success:        #4fbf60;
    --color-error:          #f06060;
    --color-warning:        #f0a030;
    --color-gold:           #f0c830;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
  }
}

/* --- Base Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
  display: flex;
  flex-direction: column;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.2; }
button { cursor: pointer; background: none; border: none; }

a, button, input {
  transition: color var(--transition-interactive),
              background var(--transition-interactive),
              border-color var(--transition-interactive),
              box-shadow var(--transition-interactive);
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

::selection {
  background: color-mix(in srgb, var(--color-primary) 25%, transparent);
  color: var(--color-text);
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-divider);
}

.header-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text);
}

.logo-link {
  display: flex;
  align-items: center;
  color: var(--color-text);
  text-decoration: none;
  transition: opacity var(--transition-interactive);
}
.logo-link:hover {
  opacity: 0.7;
}

.logo-text {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-accent {
  color: var(--color-primary);
  font-weight: 500;
}

[data-theme-toggle] {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}
[data-theme-toggle]:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

/* --- Main --- */
.main {
  flex: 1;
  max-width: var(--content-wide);
  margin: 0 auto;
  width: 100%;
  padding: var(--space-8) var(--space-6);
}

/* --- Search --- */
.search-section {
  text-align: center;
  margin-bottom: var(--space-8);
}

.search-hero h1 {
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: var(--space-2);
  letter-spacing: -0.03em;
}

.search-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
}

.search-box {
  max-width: 500px;
  margin: 0 auto;
  position: relative;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  gap: var(--space-3);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}

.search-input-wrap:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-primary) 12%, transparent);
}

.search-icon {
  flex-shrink: 0;
  color: var(--color-text-faint);
}

#searchInput {
  flex: 1;
  border: none;
  background: none;
  font-size: var(--text-base);
  line-height: 1.5;
  outline: none;
}

#searchInput::placeholder {
  color: var(--color-text-faint);
}

.clear-btn {
  flex-shrink: 0;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  color: var(--color-text-faint);
}
.clear-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-offset);
}

/* Suggestions Dropdown */
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}

.suggestions.active {
  display: block;
}

.suggestion-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background var(--transition-interactive);
  border-bottom: 1px solid var(--color-divider);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.active {
  background: var(--color-primary-light);
}

.suggestion-name {
  font-weight: 600;
  font-size: var(--text-sm);
}

.suggestion-name mark {
  background: color-mix(in srgb, var(--color-primary) 20%, transparent);
  color: var(--color-primary);
  border-radius: 2px;
  padding: 0 1px;
}

.suggestion-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ============================================
   HOME DASHBOARD
   ============================================ */

.home-dashboard {
  animation: fadeIn 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Stats bar */
.stats-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  flex-wrap: wrap;
  margin-bottom: var(--space-8);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.stat-value {
  font-size: var(--text-lg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-divider {
  width: 1px;
  height: 32px;
  background: var(--color-divider);
}

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
}

.dashboard-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.panel-header {
  margin-bottom: var(--space-4);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.panel-title svg {
  flex-shrink: 0;
  display: inline;
  color: var(--color-primary);
}

/* Toggle groups */
.toggle-row {
  margin-bottom: var(--space-3);
}

.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.toggle-group--sm .toggle-btn {
  font-size: 0.72rem;
  padding: var(--space-1) var(--space-2);
}

.toggle-btn {
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-interactive);
  white-space: nowrap;
}

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

.toggle-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

/* Event select */
.event-select {
  width: 100%;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-text);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%230077b6' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

[data-theme="dark"] .event-select {
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234db8e8' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.event-select:focus {
  border-color: var(--color-primary-active);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 15%, transparent);
}

/* Course toggle — make it stand out */
#leaderCourseToggle .toggle-btn {
  border: 2px solid var(--color-primary);
  font-weight: 600;
}
#leaderCourseToggle .toggle-btn:not(.active) {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

/* Leaderboard & Progress tables */
.leaderboard-table-wrap {
  overflow-y: auto;
  overflow-x: auto;
  max-height: 520px;
  -webkit-overflow-scrolling: touch;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}

.leaderboard-table thead th {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--color-divider);
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
}

.leaderboard-table tbody td {
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--color-divider);
  vertical-align: middle;
}

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

.lb-row {
  cursor: pointer;
  transition: background var(--transition-interactive);
}

.lb-row:hover {
  background: var(--color-primary-light);
}

.col-rank {
  width: 36px;
  text-align: center;
}

.col-time, .col-progress {
  text-align: right;
  white-space: nowrap;
}

.col-event {
  white-space: nowrap;
  color: var(--color-text-muted);
}

.lb-event-mobile {
  display: none;
  font-size: 0.65rem;
  color: var(--color-text-faint);
  line-height: 1.2;
}

.lb-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
}

.lb-rank--gold {
  background: linear-gradient(135deg, #ffd700, #ffb300);
  color: #5a4000;
}

.lb-rank--silver {
  background: linear-gradient(135deg, #c0c0c0, #a0a0a0);
  color: #3a3a3a;
}

.lb-rank--bronze {
  background: linear-gradient(135deg, #cd7f32, #b06820);
  color: #fff;
}

.lb-name {
  font-weight: 600;
  color: var(--color-text);
  display: block;
  line-height: 1.3;
}

.lb-year {
  font-size: 0.68rem;
  color: var(--color-text-faint);
}

.lb-time {
  font-family: var(--font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
}

.lb-empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--color-text-muted);
  font-style: italic;
}

.short-pool-mark {
  font-size: 0.7em;
  color: var(--color-warning, #f59e0b);
  margin-left: 2px;
  font-weight: 600;
  vertical-align: baseline;
}

/* Progress badge */
.progress-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--color-success);
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

/* Rating arrow in athlete meta */
.meta-tag--rating {
  font-weight: 600;
}

.rating-arrow {
  font-size: 0.65rem;
  margin: 0 2px;
  line-height: 1;
}

.rating-arrow--up {
  color: var(--color-success);
}

.rating-arrow--down {
  color: var(--color-error);
}

.rating-detail {
  font-weight: 400;
  color: var(--color-text-faint);
  margin-left: 2px;
}

/* --- Athlete Card --- */
.athlete-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.athlete-header {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.athlete-avatar {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  font-weight: 700;
  flex-shrink: 0;
}

.athlete-info h2 {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-2);
}

.athlete-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.meta-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}

.meta-tag svg {
  flex-shrink: 0;
  display: inline;
}

/* --- Club History Timeline --- */
.club-history {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-divider);
}

.club-history-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

.club-history-title svg {
  flex-shrink: 0;
  display: inline;
  color: var(--color-primary);
}

.club-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.club-year {
  display: flex;
  gap: var(--space-3);
  position: relative;
  min-height: 44px;
}

.club-year-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 18px;
  padding-top: 3px;
}

.club-year-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  border: 2px solid var(--color-surface);
  box-shadow: 0 0 0 2px var(--color-border);
  flex-shrink: 0;
  z-index: 1;
}

.club-year--current .club-year-dot {
  background: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary);
}

.club-year-line {
  width: 2px;
  flex: 1;
  background: var(--color-divider);
  margin-top: 2px;
  min-height: 16px;
}

.club-year-content {
  padding-bottom: var(--space-4);
  flex: 1;
  min-width: 0;
}

.club-year-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.club-year--current .club-year-label {
  color: var(--color-primary);
}

.club-year-items {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.club-year-chip {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-3);
  background: var(--color-surface-offset);
  color: var(--color-text);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-divider);
  line-height: 1.4;
}

.club-year--current .club-year-chip {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

[data-theme="dark"] .club-year--current .club-year-chip {
  color: var(--color-primary);
}

/* --- KPI Grid --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

.kpi-value {
  font-size: var(--text-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
}

/* --- Pool Toggle --- */
.pool-toggle {
  display: none;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.pool-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-interactive);
}

.pool-btn svg {
  display: inline;
  flex-shrink: 0;
}

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

.pool-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.pool-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  font-size: 0.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.2);
  padding: 0 4px;
}

.pool-btn:not(.active) .pool-count {
  background: var(--color-surface-offset);
  color: var(--color-text-faint);
}

/* --- Glory Wall (Аллея славы) --- */
.glory-wall {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.glory-wall::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #ffd700, #c0c0c0, #cd7f32);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.glory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.glory-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

.glory-summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.glory-count {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
}

.medal-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.glory-medals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
}

.medal-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-divider);
  background: var(--color-surface-2);
  transition: transform var(--transition-interactive), box-shadow var(--transition-interactive);
}

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

.medal-card--gold {
  border-color: #ffd70050;
  background: linear-gradient(135deg, rgba(255,215,0,0.06), var(--color-surface-2));
}

.medal-card--silver {
  border-color: #c0c0c050;
  background: linear-gradient(135deg, rgba(192,192,192,0.06), var(--color-surface-2));
}

.medal-card--bronze {
  border-color: #cd7f3250;
  background: linear-gradient(135deg, rgba(205,127,50,0.06), var(--color-surface-2));
}

.medal-emoji {
  font-size: 2rem;
  line-height: 1;
  flex-shrink: 0;
}

.medal-details {
  flex: 1;
  min-width: 0;
}

.medal-place {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.medal-event {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.medal-pool {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}

.medal-pool--scm {
  background: color-mix(in srgb, #f59e0b 18%, transparent);
  color: #b45309;
}

[data-theme="dark"] .medal-pool--scm {
  color: #fbbf24;
}

.medal-time {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.medal-meet {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: 2px;
}

/* Glory empty state */
.glory-empty {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-6);
  margin-bottom: var(--space-6);
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.glory-empty-icon {
  margin-bottom: var(--space-4);
}

.glory-empty-icon svg {
  margin: 0 auto;
}

.glory-empty-text {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.glory-empty-sub {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* --- Charts Grid --- */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.chart-wide {
  grid-column: 1 / -1;
}

.chart-title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-4);
  color: var(--color-text);
}

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.chart-controls button {
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-interactive);
}

.chart-controls button:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.chart-controls button.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.chart-wrap {
  position: relative;
  height: 280px;
}

.chart-wrap-square {
  height: 260px;
}

/* --- Results Table --- */
.table-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.table-filters {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}

.table-filter-select {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  padding: 6px 28px 6px 10px;
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  background: var(--color-primary-light);
  color: var(--color-text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%230077b6' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  min-width: 0;
  max-width: 200px;
  font-weight: 600;
}

.table-filter-select:focus {
  outline: none;
  border-color: var(--color-primary-active);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 15%, transparent);
}

[data-theme="dark"] .table-filter-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234db8e8' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

.table-wrap {
  overflow-x: auto;
  margin-top: var(--space-3);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-sm);
}

thead th {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 2px solid var(--color-divider);
  text-align: left;
  white-space: nowrap;
}

tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--color-primary-light);
}

.time-cell {
  font-family: var(--font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Pool legend note under chart */
.chart-legend-note {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-2) 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}
.legend-marker {
  font-size: 0.85em;
  margin-right: 2px;
}
.legend-lcm {
  color: var(--color-primary);
}
.legend-scm {
  color: #f59e0b;
}

/* Course badge (25m/50m) */
.course-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 22px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.course-lcm {
  background: color-mix(in srgb, var(--color-primary) 15%, transparent);
  color: var(--color-primary);
}
.course-scm {
  background: color-mix(in srgb, #f59e0b 18%, transparent);
  color: #b45309;
}
[data-theme="dark"] .course-scm {
  color: #fbbf24;
}

.col-place {
  text-align: center;
}

.place-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.place-1 {
  background: linear-gradient(135deg, #ffd700, #ffb300);
  color: #5a4000;
}
.place-2 {
  background: linear-gradient(135deg, #c0c0c0, #a0a0a0);
  color: #3a3a3a;
}
.place-3 {
  background: linear-gradient(135deg, #cd7f32, #b06820);
  color: #fff;
}
.place-other {
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
}

.improvement {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  margin-left: var(--space-2);
}

.improvement-positive {
  color: var(--color-success);
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
}

.improvement-negative {
  color: var(--color-error);
  background: color-mix(in srgb, var(--color-error) 12%, transparent);
}

.club-cell {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Footer --- */
.footer {
  text-align: center;
  padding: var(--space-8) var(--space-6);
  border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.footer p {
  margin-bottom: var(--space-2);
  max-width: none;
}

.footer a {
  color: var(--color-primary);
  text-decoration: none;
}
.footer a:hover {
  text-decoration: underline;
}

/* --- Rank Badge (ЕВСК) --- */
.rank-showcase {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  margin-bottom: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  position: relative;
  overflow: hidden;
}

.rank-showcase::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: var(--text-base);
  letter-spacing: 0.02em;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  position: relative;
}

.rank-badge-icon {
  display: flex;
  align-items: center;
  line-height: 0;
}

.rank-badge-text {
  white-space: nowrap;
}

/* Adult ranks */
.rank-badge--adult {
  border: 2px solid;
}

/* Youth ranks */
.rank-badge--youth {
  border: 2px dashed;
}

/* МСМК / МС — gold/elite */
.rank-badge--ms {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  border-color: #f59e0b;
}
.rank-badge--ms .rank-badge-icon { color: #f59e0b; }
.rank-showcase:has(.rank-badge--ms)::before {
  background: linear-gradient(90deg, #f59e0b, #fbbf24, #f59e0b);
}

[data-theme="dark"] .rank-badge--ms {
  background: linear-gradient(135deg, #78350f, #92400e);
  color: #fde68a;
  border-color: #f59e0b;
}

/* КМС — blue/strong */
.rank-badge--kms {
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  color: #1e40af;
  border-color: #3b82f6;
}
.rank-badge--kms .rank-badge-icon { color: #3b82f6; }
.rank-showcase:has(.rank-badge--kms)::before {
  background: linear-gradient(90deg, #3b82f6, #60a5fa, #3b82f6);
}

[data-theme="dark"] .rank-badge--kms {
  background: linear-gradient(135deg, #1e3a5f, #1e40af50);
  color: #93c5fd;
  border-color: #3b82f6;
}

/* I разряд — teal */
.rank-badge--i {
  background: linear-gradient(135deg, #ccfbf1, #99f6e4);
  color: #115e59;
  border-color: #14b8a6;
}
.rank-badge--i .rank-badge-icon { color: #14b8a6; }
.rank-showcase:has(.rank-badge--i)::before {
  background: linear-gradient(90deg, #14b8a6, #2dd4bf, #14b8a6);
}

[data-theme="dark"] .rank-badge--i {
  background: linear-gradient(135deg, #134e4a, #115e5950);
  color: #5eead4;
  border-color: #14b8a6;
}

/* II разряд — green */
.rank-badge--ii {
  background: linear-gradient(135deg, #dcfce7, #bbf7d0);
  color: #166534;
  border-color: #22c55e;
}
.rank-badge--ii .rank-badge-icon { color: #22c55e; }
.rank-showcase:has(.rank-badge--ii)::before {
  background: linear-gradient(90deg, #22c55e, #4ade80, #22c55e);
}

[data-theme="dark"] .rank-badge--ii {
  background: linear-gradient(135deg, #14532d, #16653450);
  color: #86efac;
  border-color: #22c55e;
}

/* III разряд — slate/muted */
.rank-badge--iii {
  background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
  color: #475569;
  border-color: #94a3b8;
}
.rank-badge--iii .rank-badge-icon { color: #94a3b8; }
.rank-showcase:has(.rank-badge--iii)::before {
  background: linear-gradient(90deg, #94a3b8, #cbd5e1, #94a3b8);
}

[data-theme="dark"] .rank-badge--iii {
  background: linear-gradient(135deg, #334155, #47556950);
  color: #cbd5e1;
  border-color: #94a3b8;
}

.rank-details {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex-wrap: wrap;
  justify-content: center;
}

.rank-sep {
  color: var(--color-text-faint);
}

.rank-event {
  font-weight: 500;
}

.rank-time {
  font-family: var(--font-mono);
  font-weight: 500;
}

.rank-pool {
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-offset);
  font-weight: 500;
  font-size: 0.75rem;
}

/* Inline rank next to athlete name */
.rank-inline {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  margin-left: var(--space-2);
  vertical-align: middle;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.rank-inline--youth {
  border: 1.5px dashed;
}

.rank-inline--adult {
  border: 1.5px solid;
}

.rank-inline--ms {
  background: #fef3c7;
  color: #92400e;
  border-color: #f59e0b;
}

[data-theme="dark"] .rank-inline--ms {
  background: #78350f;
  color: #fde68a;
  border-color: #f59e0b;
}

.rank-inline--kms {
  background: #dbeafe;
  color: #1e40af;
  border-color: #3b82f6;
}

[data-theme="dark"] .rank-inline--kms {
  background: #1e3a5f;
  color: #93c5fd;
  border-color: #3b82f6;
}

.rank-inline--i {
  background: #ccfbf1;
  color: #115e59;
  border-color: #14b8a6;
}

[data-theme="dark"] .rank-inline--i {
  background: #134e4a;
  color: #5eead4;
  border-color: #14b8a6;
}

.rank-inline--ii {
  background: #dcfce7;
  color: #166534;
  border-color: #22c55e;
}

[data-theme="dark"] .rank-inline--ii {
  background: #14532d;
  color: #86efac;
  border-color: #22c55e;
}

.rank-inline--iii {
  background: #f1f5f9;
  color: #475569;
  border-color: #94a3b8;
}

[data-theme="dark"] .rank-inline--iii {
  background: #334155;
  color: #cbd5e1;
  border-color: #94a3b8;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.results-section {
  animation: fadeIn 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .main {
    padding: var(--space-6) var(--space-4);
  }
  
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .charts-grid {
    grid-template-columns: 1fr;
  }
  
  .chart-wide {
    grid-column: auto;
  }
  
  .athlete-header {
    flex-direction: column;
    text-align: center;
  }
  
  .athlete-meta {
    justify-content: center;
  }

  .glory-medals {
    grid-template-columns: 1fr;
  }

  .glory-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .pool-toggle {
    justify-content: center;
  }
  
  .stats-bar {
    gap: var(--space-4);
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .toggle-group {
    flex-wrap: wrap;
  }

  /* Hide event column in dashboard tables, show event inline under name */
  .col-event {
    display: none;
  }
  .leaderboard-table thead th.col-event {
    display: none;
  }
  .lb-event-mobile {
    display: block;
  }

  /* Results table: hide meet name, club, and pool on mobile */
  .col-meet {
    display: none;
  }
  .col-club, .club-cell {
    display: none;
  }
  .col-course {
    display: none;
  }

  /* Tighter padding on results table */
  #resultsTable td, #resultsTable th {
    padding: 4px 2px;
    font-size: 0.68rem;
  }
  #resultsTable {
    font-size: 0.68rem;
  }
  .course-badge {
    padding: 1px 4px;
    font-size: 0.6rem;
  }
  .place-badge {
    width: 20px;
    height: 20px;
    font-size: 0.6rem;
  }
  .improvement {
    font-size: 0.55rem;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }
  
  .kpi-card {
    padding: var(--space-3);
  }
  
  .kpi-value {
    font-size: var(--text-lg);
  }

  .toggle-group--sm .toggle-btn {
    font-size: 0.65rem;
    padding: 2px 6px;
  }
}
