:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e6e8ec;
  --border-strong: #d6dae0;
  --text: #0b1220;
  --text-muted: #6b7280;
  --text-faint: #9aa3af;
  --accent: #0ea5b7;
  --accent-soft: #e6f7f9;
  --accent-strong: #0891a1;
  --gold: #d4a017;
  --silver: #9ca3af;
  --bronze: #b06b3a;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 24px -8px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --container: 1100px;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(247, 248, 250, 0.85);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
}
.brand-logo {
  width: 36px; height: 36px;
  object-fit: contain;
  display: block;
}
.brand-name { font-weight: 600; letter-spacing: -0.01em; font-size: 16px; }

.top-nav { display: flex; gap: 12px; align-items: center; }
.top-nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px; font-weight: 500;
  padding: 6px 0;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.top-nav a.active { color: var(--text); border-color: var(--accent); }
.top-nav a:hover { color: var(--text); }

.nav-btn {
  border-bottom: 0 !important;
  padding: 8px 14px !important;
  background: var(--text);
  color: #fff !important;
  border-radius: 8px;
  font-weight: 600 !important;
  transition: background .15s, transform .12s;
}
.nav-btn:hover { background: #1e293b; transform: translateY(-1px); }

/* ---------- Hero ---------- */
.hero { padding: 48px 0 28px; }
.hero h1 {
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin-bottom: 10px;
}
.hero-sub {
  color: var(--text-muted);
  font-size: 16px;
  max-width: 620px;
}

/* Stats banner under the main heading */
.stats-banner {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 10px;
  padding: 7px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  max-width: 100%;
}
.stats-banner[hidden] { display: none !important; }
.stat-item {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.stat-num {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--accent-strong), #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}
.stat-lbl {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.stat-sep {
  width: 1px;
  height: 14px;
  background: var(--border);
}
@media (max-width: 480px) {
  .stats-banner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 14px;
    row-gap: 8px;
    padding: 12px 16px;
    border-radius: 14px;            /* match other card radius */
    width: 100%;
    max-width: 340px;
  }
  .stat-item {
    justify-content: flex-start;
    align-items: baseline;
  }
  .stat-num { font-size: 16px; }
  .stat-lbl { font-size: 12px; }
  .stat-sep { display: none; }      /* dividers don't fit a grid layout */
}

/* ---------- Tabs ---------- */
.tabs-wrap {
  position: relative;
  margin-bottom: 18px;
}
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  box-shadow: var(--shadow-sm);
  scroll-behavior: smooth;
}
.tabs::-webkit-scrollbar { display: none; }

/* Fade + chevron hint when there's more to scroll */
.tabs-wrap::before,
.tabs-wrap::after {
  content: '';
  position: absolute;
  top: 1px; bottom: 1px;
  width: 42px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 2;
}
.tabs-wrap::before {
  left: 1px;
  border-radius: var(--radius) 0 0 var(--radius);
  background: linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0));
}
.tabs-wrap::after {
  right: 1px;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: linear-gradient(to left, var(--surface) 30%, rgba(255,255,255,0));
}
.tabs-wrap.has-overflow-start::before { opacity: 1; }
.tabs-wrap.has-overflow-end::after { opacity: 1; }

.scroll-chevron {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 28px; height: 28px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  pointer-events: auto;
  cursor: pointer;
  z-index: 3;
  font-size: 14px;
  display: none;
  align-items: center;
  justify-content: center;
}
.scroll-chevron.left  { left: 4px; }
.scroll-chevron.right { right: 4px; }
.tabs-wrap.has-overflow-start .scroll-chevron.left  { display: flex; }
.tabs-wrap.has-overflow-end   .scroll-chevron.right { display: flex; }

.tab {
  flex: 1 1 auto;
  white-space: nowrap;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, color .15s;
  min-width: max-content;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active {
  background: var(--text);
  color: #fff;
  box-shadow: 0 2px 6px rgba(11,18,32,0.18);
}

/* ---------- Filters ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  margin-bottom: 20px;
}
.filter-group { display: inline-flex; align-items: center; }

.seg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  box-shadow: var(--shadow-sm);
}
.seg-btn {
  border: 0; background: transparent;
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  padding: 7px 14px; border-radius: 7px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--text); color: #fff;
}

.search { flex: 1 1 240px; max-width: 360px; margin-left: auto; }
.search input {
  width: 100%;
  font-family: inherit; font-size: 14px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.search input:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search input::placeholder { color: var(--text-faint); }

/* ---------- Ranking ---------- */
.ranking-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.ranking-meta .dot { color: var(--text-faint); }
#rankingTitle { color: var(--text); font-weight: 600; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.ranking-table thead th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 14px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.col-rank   { width: 44px; text-align: center; }
.col-time   { width: 64px; text-align: center; }
.col-athlete { min-width: 220px; }
/* Tight horizontal padding + center alignment so medal (28px) and plain numbers
   sit on the same horizontal axis. */
.ranking-table .col-rank,
.ranking-table .rank-cell {
  padding-left: 4px;
  padding-right: 4px;
  text-align: center;
}
.col-date   { width: 124px; }
.col-coach  { width: auto; min-width: 140px; }
.col-group  { width: auto; min-width: 150px; }
.col-city   { width: auto; }
.col-sport  { width: 100px; }
.col-short  { width: 60px; text-align: center; }
.col-water  { width: 60px; text-align: center; }
.group-cell { white-space: nowrap; }

/* On group-detail page (`/group?id=N`) — fewer columns, plenty of breathing room */
#groupTable .col-time  { width: 130px; }
#groupTable .col-date  { width: 130px; }
#groupTable .col-short { width: 80px; }
#groupTable .col-water { width: 80px; }

/* Hide 25м column on all tabs except 50м */
.ranking-table:not(.show-short) .col-short,
.ranking-table:not(.show-short) .short-cell { display: none; }
/* Hide ОВ column on all tabs except 3/5/10км */
.ranking-table:not(.show-water) .col-water,
.ranking-table:not(.show-water) .water-cell { display: none; }
.col-water svg {
  vertical-align: middle;
  margin-right: 3px;
  color: var(--sport-swim, #06b6d4);
}

.ranking-table tbody tr {
  transition: background .12s;
}
.ranking-table tbody tr:nth-child(even) { background: #f5f6f8; }
.ranking-table tbody tr:hover { background: var(--surface-2); }
.ranking-table tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ranking-table tbody tr:last-child td { border-bottom: 0; }

.rank-cell {
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.rank-medal {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 12px; font-weight: 700;
  color: #fff;
}
.rank-medal.gold   { background: var(--gold); }
.rank-medal.silver { background: var(--silver); }
.rank-medal.bronze { background: var(--bronze); }

.athlete-name { font-weight: 600; color: var(--text); }
.athlete-meta {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.time-cell {
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.time-cell .ms { color: var(--text-muted); font-weight: 500; }

.date-cell, .coach-cell, .group-cell, .city-cell, .sport-cell { color: var(--text-muted); font-size: 13px; }
.date-cell, .coach-cell { white-space: nowrap; }
.sport-cell {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.short-cell, .water-cell { text-align: center; }
.short-check {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}
.water-check {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: rgba(6,182,212,0.12);
  color: #0e7490;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}
.short-empty { color: var(--text-faint); }

.empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Clickable rows ---------- */
.ranking-table tbody tr.clickable-row { cursor: pointer; }

/* Chevron — on desktop: inline next to name; on mobile: own column at right */
/* Desktop: hide the dedicated chevron column, show inline ::after on athlete name */
.col-chev, .chev-cell { display: none; }
.ranking-table .row-link::after {
  content: '›';
  display: inline-block;
  margin-left: 8px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-faint);
  vertical-align: 1px;
  transition: color .15s, transform .15s;
}
.ranking-table tbody tr.clickable-row:hover .row-link::after {
  color: var(--accent-strong);
  transform: translateX(3px);
}
.chev {
  display: inline-block;
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
  color: var(--text-faint);
  transition: color .15s, transform .15s;
}

/* "Pulse once" — draws a viewer's eye to the top row on each render.
   3 short fades, then stops. Subtle accent-soft background. */
@keyframes rowPulse {
  0%   { background-color: transparent; }
  20%  { background-color: var(--accent-soft); }
  60%  { background-color: transparent; }
  100% { background-color: transparent; }
}
.ranking-table tbody tr.row-pulse-once {
  animation: rowPulse 1.5s ease-in-out 0s 3;
}
/* Don't pulse if user is hovering (looks weird with hover bg) */
.ranking-table tbody tr.row-pulse-once:hover { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .ranking-table tbody tr.row-pulse-once { animation: none; }
}
.row-link {
  text-decoration: none;
  color: inherit;
  display: inline-block;
}
.ranking-table tbody tr.clickable-row:hover {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.ranking-table tbody tr.clickable-row:hover .athlete-name {
  color: var(--accent-strong);
}
.athlete-name { transition: color .15s; }

/* ---------- Shared primary button ---------- */
.btn-primary {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, transform .12s, box-shadow .15s;
}
.btn-primary:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

/* ---------- Profile self-edit (auth) ---------- */
.profile-auth {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
}
.btn-claim {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, transform .12s;
}
.btn-claim:hover { background: var(--accent-strong); transform: translateY(-1px); }

.auth-badge-ok {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(22,163,74,0.08);
  color: #15803d;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
}
.auth-badge-other {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(245,158,11,0.08);
  color: #92400e;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 8px;
}
.auth-badge-other a { color: inherit; font-weight: 600; }
.btn-add-own {
  font-family: inherit;
  font-size: 13px; font-weight: 600;
  padding: 8px 14px;
  background: var(--text); color: #fff;
  border: 0; border-radius: 8px; cursor: pointer;
  transition: background .15s;
}
.btn-add-own:hover { background: #1e293b; }
.btn-ghost-sm {
  font-family: inherit; font-size: 13px;
  padding: 7px 12px; background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; transition: color .15s, border-color .15s;
}
.btn-ghost-sm:hover { color: var(--text); border-color: var(--border-strong); }

.btn-row-del, .btn-row-edit {
  width: 28px; height: 28px;
  display: inline-grid; place-items: center;
  background: transparent; color: var(--text-faint);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: 13px;
  transition: all .12s;
}
.btn-row-edit:hover {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}
.btn-row-del:hover {
  color: #b91c1c;
  background: rgba(220,38,38,0.08);
  border-color: rgba(220,38,38,0.3);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(11,18,32,0.55);
  display: grid; place-items: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none !important; }
.modal-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 26px 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 24px 48px -16px rgba(0,0,0,0.35);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-close {
  position: absolute; top: 10px; right: 12px;
  width: 32px; height: 32px;
  background: transparent; color: var(--text-muted);
  border: 0; border-radius: 8px;
  cursor: pointer; font-size: 20px; line-height: 1;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-title {
  font-size: 22px; font-weight: 700;
  letter-spacing: -0.02em; margin-bottom: 10px;
}
.modal-intro {
  color: var(--text-muted);
  font-size: 14px; line-height: 1.5;
  margin-bottom: 18px;
}
.modal-label {
  display: block;
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; font-weight: 600;
  color: var(--text-faint);
  margin: 12px 0 6px;
}
.modal-label:first-child { margin-top: 0; }
.modal-input { width: 100%; font-size: 15px; padding: 10px 12px; }
.modal-submit { width: 100%; padding: 12px; font-size: 14px; margin-top: 16px; }
.modal-hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}
.modal-link {
  color: var(--accent-strong);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  transition: border-color .15s;
}
.modal-link:hover { border-bottom-color: var(--accent); }
.auth-msg {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.auth-msg-err { background: rgba(220,38,38,0.08); color: #b91c1c; }
.auth-msg-ok  { background: rgba(22,163,74,0.08); color: #15803d; }

/* ---------- Add-result modal body ---------- */
.ar-field { margin-bottom: 14px; }
.ar-field > label {
  display: block;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600; color: var(--text-faint);
  margin-bottom: 6px;
}
.ar-field .dim { text-transform: none; color: var(--text-faint); font-weight: 400; }
.seg.ar-distance {
  display: flex; flex-wrap: wrap; gap: 4px;
  background: var(--surface-2);
  border-radius: 8px; padding: 4px;
}
.ar-distance .seg-btn { padding: 7px 12px; font-size: 13px; }
.ar-time-row { display: flex; align-items: center; gap: 5px; }
.ar-ti {
  font-size: 16px; font-weight: 600;
  padding: 10px 6px; width: 64px; text-align: center;
  border: 1px solid var(--border-strong); border-radius: 8px;
  font-variant-numeric: tabular-nums;
  background: #fff;
}
.ar-ti:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ar-ti::placeholder { font-weight: 400; color: var(--text-faint); font-size: 12px; }
.ar-time-row .ti-sep {
  color: var(--text-faint); font-weight: 700; font-size: 18px;
  padding: 0 2px; user-select: none;
}
.ar-check {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
  font-size: 13px; color: var(--text);
  background: var(--surface-2);
  padding: 8px 12px; border-radius: 8px;
  margin-bottom: 8px;
}
.ar-check[hidden] { display: none !important; }
.ar-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 20px;
}

/* Modal action buttons (Cancel / Save) — shared across pages */
.modal-card .btn-cancel,
.modal-card .btn-save {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  min-width: 110px;
}
.modal-card .btn-cancel {
  background: #fff;
  color: var(--text-muted);
  border-color: var(--border-strong);
}
.modal-card .btn-cancel:hover {
  color: var(--text);
  border-color: var(--text-muted);
  background: var(--surface-2);
}
.modal-card .btn-save {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px -4px rgba(8,145,161,0.4);
}
.modal-card .btn-save:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px -4px rgba(8,145,161,0.5);
}
.modal-card .btn-save:active {
  transform: translateY(0);
}

/* Mobile-friendly tweaks for modals */
@media (max-width: 480px) {
  .modal-overlay { padding: 12px; }
  .modal-card { padding: 22px 18px 18px; max-height: 92vh; border-radius: 14px; }
  .modal-close { top: 8px; right: 8px; }
  .modal-title { font-size: 19px; margin-bottom: 8px; }
  .modal-intro { font-size: 13px; line-height: 1.45; margin-bottom: 14px; }
  .modal-input { font-size: 16px; padding: 11px 12px; }  /* 16px avoids iOS zoom */
  .modal-submit { padding: 14px; font-size: 15px; }
  .modal-hint { font-size: 11.5px; }

  /* Add-result modal — compact + readable */
  .ar-field { margin-bottom: 12px; }
  .ar-field > label { font-size: 10.5px; margin-bottom: 5px; }
  .seg.ar-distance { gap: 3px; padding: 3px; }
  .ar-distance .seg-btn { padding: 8px 11px; font-size: 13px; flex: 1 1 auto; }
  .ar-time-row { gap: 4px; flex-wrap: wrap; }
  .ar-ti { width: 58px; padding: 10px 4px; font-size: 16px; }  /* 16px = no iOS zoom */
  .ar-time-row .ti-sep { font-size: 16px; }

  /* Stack action buttons vertically on phone; Save on top */
  .ar-actions { flex-direction: column-reverse; gap: 8px; margin-top: 18px; }
  .modal-card .btn-cancel,
  .modal-card .btn-save { width: 100%; min-width: 0; padding: 14px; font-size: 15px; }
}

/* ---------- Profile page ---------- */
.back-link {
  display: inline-block;
  margin: 24px 0 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  transition: color .15s;
}
.back-link:hover { color: var(--accent-strong); }

.profile-hero { padding: 24px 0 20px; }
.profile-hero h1 {
  font-size: clamp(28px, 4vw, 36px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin-bottom: 8px;
}
.profile-meta {
  color: var(--text-muted);
  font-size: 14px;
}

.profile-tabs { margin-bottom: 22px; }
.tab-count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  vertical-align: 1px;
}
.tab.active .tab-count { background: rgba(255,255,255,0.18); color: #fff; }

.profile-summary { margin-bottom: 22px; }
.pb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.pb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.pb-distance {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 500;
  margin-bottom: 6px;
}
.pb-time {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
}
.pb-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- Progress chart ---------- */
.progress-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 18px 20px 14px;
  margin-bottom: 18px;
}
.progress-chart[hidden] { display: none !important; }
.pc-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px; gap: 12px; flex-wrap: wrap;
}
.pc-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  letter-spacing: -0.01em;
}
.pc-trend {
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.pc-trend-up   { background: rgba(22,163,74,0.10);  color: #15803d; }
.pc-trend-down { background: rgba(220,38,38,0.10);  color: #b91c1c; }
.pc-trend-flat { background: var(--surface-2);       color: var(--text-muted); }

.pc-svg-wrap { width: 100%; }
.pc-svg {
  display: block; width: 100%; height: auto; max-height: 280px;
  overflow: visible;
}
.pc-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  vector-effect: non-scaling-stroke;
}
.pc-axis-x, .pc-axis-y {
  fill: var(--text-faint);
  font-size: 11px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.pc-area { fill: rgba(8,145,161,0.10); }
.pc-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.pc-point circle {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  transition: r .12s;
}
.pc-point:hover circle { r: 7; }
.pc-point.pc-pb circle {
  fill: var(--gold);
  stroke: #fff;
  stroke-width: 2.5;
}

@media (max-width: 720px) {
  .progress-chart { padding: 14px 14px 10px; }
  .pc-axis-x, .pc-axis-y { font-size: 10px; }
}

/* History table — shares most styles with .ranking-table */
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.history-table thead th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 14px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.history-table .col-date  { width: 140px; }
.history-table .col-time  { width: 130px; text-align: right; }
.history-table .col-short { width: 56px;  text-align: center; }
.history-table .col-water { width: 56px;  text-align: center; }
.history-table .col-comp  { width: auto; }
.history-table .col-tag   { width: 64px; text-align: right; }
.history-table.editable .col-tag { width: 140px; }
.tag-cell .tag-inner {
  display: inline-flex; justify-content: flex-end; align-items: center;
  gap: 6px; white-space: nowrap;
}

.history-table:not(.show-short) .col-short,
.history-table:not(.show-short) .short-cell { display: none; }
.history-table:not(.show-water) .col-water,
.history-table:not(.show-water) .water-cell { display: none; }
.history-table .col-water svg { vertical-align: middle; margin-right: 3px; color: var(--sport-swim, #06b6d4); }

.history-table tbody tr { transition: background .12s; }
.history-table tbody tr:nth-child(even) { background: #f5f6f8; }
.history-table tbody tr:hover { background: var(--surface-2); }
.history-table tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.history-table tbody tr:last-child td { border-bottom: 0; }
.history-table tbody .date-cell,
.history-table tbody .comp-cell { color: var(--text-muted); font-size: 13px; }
.history-table tbody .tag-cell { text-align: right; }

.row-pb { background: linear-gradient(90deg, rgba(212,160,23,0.06), transparent 80%); }
.pb-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--gold);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 6px;
}

@media (max-width: 720px) {
  .history-table thead { display: none; }
  .history-table, .history-table tbody, .history-table tr, .history-table td {
    display: block; width: 100%;
  }
  .history-table tbody tr {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "date  time"
      "meta  flags";
    column-gap: 10px;
    row-gap: 4px;
    align-items: center;
  }
  .history-table tbody td { padding: 0; border: 0; min-width: 0; }
  .history-table tbody td.date-cell { grid-area: date; font-weight: 600; color: var(--text); font-size: 13px; }
  .history-table tbody td.time-cell { grid-area: time; text-align: right; font-size: 15px; }
  .history-table tbody td.comp-cell {
    grid-area: meta; font-size: 12px; color: var(--text-faint);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  /* short and water never appear together (different distance tabs) — same area is safe */
  .history-table tbody td.short-cell,
  .history-table tbody td.water-cell { grid-area: flags; text-align: right; }
  /* PB-badge не занимает столбец — добавляется ::before к дате на PB-строке */
  .history-table tbody td.tag-cell { display: none; }
  .history-table tbody tr.row-pb td.date-cell::before {
    content: 'PB';
    display: inline-block;
    margin-right: 8px;
    padding: 1px 7px;
    background: var(--gold);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    border-radius: 5px;
    vertical-align: 2px;
  }

  /* In own-profile (editable) mode: bring tag-cell back as a delete-only column */
  .history-table.editable tbody tr {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "date  time  del"
      "meta  meta  meta";
    column-gap: 10px;
  }
  .history-table.editable tbody td.tag-cell {
    display: block;
    grid-area: del;
    align-self: center;
  }
  /* PB still shown via date::before — hide the duplicate badge inside tag-cell */
  .history-table.editable tbody td.tag-cell .pb-badge { display: none; }
  .history-table.editable tbody td.tag-cell .btn-row-edit,
  .history-table.editable tbody td.tag-cell .btn-row-del {
    width: 36px; height: 36px;     /* finger-friendly */
    font-size: 15px;
  }
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: auto;
  padding: 32px 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
main.container { padding-bottom: 80px; }
@media (max-width: 720px) {
  main.container { padding-bottom: 56px; }
}
.site-footer .container {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: var(--text-muted);
  gap: 16px;
}
.muted { color: var(--text-faint); }
.footer-right { display: inline-flex; align-items: center; gap: 18px; flex-wrap: wrap; justify-content: flex-end; }
.footer-link { text-decoration: none; transition: color .15s; }
.footer-link:hover { color: var(--accent-strong); }
.footer-sep { color: var(--border-strong); font-weight: 300; user-select: none; margin: 0 -6px; }
.footer-ig {
  display: inline-flex;
  color: var(--text-muted);
  transition: color .15s, transform .12s;
}
.footer-ig:hover { color: var(--accent-strong); transform: translateY(-1px); }
.footer-ig svg { display: block; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .container { padding: 0 16px; }
  .hero { padding: 32px 0 20px; }

  .filters { gap: 8px; }
  .search { margin-left: 0; max-width: 100%; flex-basis: 100%; order: 3; }

  /* Convert table rows to stacked cards on small screens */
  .ranking-table thead { display: none; }
  .ranking-table, .ranking-table tbody, .ranking-table tr, .ranking-table td {
    display: block; width: 100%;
  }
  .ranking-table tbody tr {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto auto;
    grid-template-areas:
      "rank athlete time chev"
      "meta meta    meta meta";
    column-gap: 10px;
    row-gap: 6px;
    align-items: center;
  }
  .ranking-table tbody tr::before {
    content: attr(data-meta);
    grid-area: meta;
    font-size: 12px;
    color: var(--text-faint);
    padding-left: 54px;
    line-height: 1.5;
    word-break: normal;
    overflow-wrap: anywhere;
  }
  .ranking-table tbody td { padding: 0 !important; border: 0; min-width: 0; }
  .ranking-table tbody td.rank-cell    {
    grid-area: rank;
    align-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .ranking-table tbody td.athlete-cell { grid-area: athlete; }
  .ranking-table tbody td.time-cell    { grid-area: time; text-align: right; }
  /* Mobile: show dedicated chevron column, hide inline ::after on name */
  .ranking-table .chev-cell {
    display: flex !important;
    grid-area: chev;
    padding-left: 6px !important;
    padding-right: 0 !important;
    align-self: center;
    align-items: center;
    justify-content: center;
  }
  .ranking-table tbody .chev {
    font-size: 22px;
    color: var(--text-faint);
    line-height: 0;
    transform: translateY(-1px);
  }
  .ranking-table .row-link::after { display: none; }
  /* Hide all non-essential cells on mobile — info goes into ::before meta line.
     25м и ОВ индикаторы скрыты полностью (есть в подробной истории спортсмена). */
  .ranking-table tbody td.date-cell,
  .ranking-table tbody td.coach-cell,
  .ranking-table tbody td.group-cell,
  .ranking-table tbody td.city-cell,
  .ranking-table tbody td.sport-cell,
  .ranking-table tbody td.short-cell,
  .ranking-table tbody td.water-cell { display: none; }
}
