/* ===================================================================
   COMPONENTS — cards, buttons, tables, forms, modals
   =================================================================== */

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--t-fast) var(--ease);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; stroke: currentColor; flex-shrink: 0; }

.btn--primary {
  background: linear-gradient(135deg, var(--ets-red-bright), var(--ets-red));
  color: var(--ets-white);
  box-shadow: var(--shadow-red);
}
.btn--primary:hover { filter: brightness(1.12); transform: translateY(-1px); box-shadow: 0 10px 28px rgba(192,0,0,0.35); }
.btn--primary:active { transform: translateY(0); }

.btn--secondary {
  background: var(--bg-3);
  color: var(--text-0);
  border-color: var(--border-2);
}
.btn--secondary:hover { background: var(--bg-4); border-color: var(--text-4); }

.btn--ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border-2);
}
.btn--ghost:hover { color: var(--text-0); border-color: var(--text-3); background: var(--bg-2); }

.btn--danger {
  background: transparent;
  color: var(--ets-red-bright);
  border-color: rgba(227,0,0,0.35);
}
.btn--danger:hover { background: rgba(227,0,0,0.12); border-color: var(--ets-red-bright); }

.btn--sm { padding: 7px 13px; font-size: 12px; border-radius: 7px; }
.btn--icon { padding: 9px; width: 36px; height: 36px; }
.btn--full { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: var(--bg-2);
  color: var(--text-3);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.icon-btn svg { width: 15px; height: 15px; stroke: currentColor; }
.icon-btn:hover { color: var(--text-0); border-color: var(--text-3); }
.icon-btn--danger:hover { color: var(--ets-red-bright); border-color: var(--ets-red-bright); background: rgba(227,0,0,0.1); }

/* ---------- CARDS ---------- */
.card {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 22px;
  animation: fadeUp var(--t-slow) var(--ease) both;
}

.card--flush { padding: 0; overflow: hidden; }

.card-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-0);
  margin-bottom: 2px;
}
.card-subtitle { font-size: 12.5px; color: var(--text-3); margin-bottom: 18px; }

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  margin-bottom: 26px;
}

.kpi-card {
  position: relative;
  background: linear-gradient(160deg, var(--bg-2) 0%, var(--bg-1) 100%);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  padding: 22px 22px 20px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: fadeUp var(--t-slow) var(--ease) both;
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.kpi-card:hover {
  transform: translateY(-3px);
  border-color: rgba(192,0,0,0.4);
  box-shadow: var(--shadow-lg), var(--shadow-red);
}
.kpi-card::after {
  content: '';
  position: absolute;
  right: -30px; top: -30px;
  width: 120px; height: 120px;
  background: radial-gradient(circle, rgba(192,0,0,0.16), transparent 70%);
  pointer-events: none;
}

.kpi-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.kpi-card__icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(192,0,0,0.25), rgba(192,0,0,0.08));
  border: 1px solid rgba(192,0,0,0.3);
  color: var(--ets-red-bright);
  flex-shrink: 0;
}
.kpi-card__icon svg { width: 20px; height: 20px; stroke: currentColor; }

.kpi-card__label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

.kpi-card__value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text-0);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.kpi-card__value.animate-in { animation: countPulse 0.5s var(--ease); }

.kpi-card__delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  font-size: 12.5px;
  font-weight: 700;
}
.kpi-card__delta svg { width: 13px; height: 13px; }

.kpi-card__bar {
  margin-top: 14px;
  height: 6px;
  border-radius: var(--r-full);
  background: var(--bg-4);
  overflow: hidden;
}
.kpi-card__bar-fill {
  height: 100%;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--ets-red-dim), var(--ets-red-bright));
  width: 0%;
  transition: width 1s var(--ease);
}

/* Skeleton loading shimmer */
.skeleton {
  background: linear-gradient(90deg, var(--bg-3) 0%, var(--bg-4) 50%, var(--bg-3) 100%);
  background-size: 800px 100%;
  animation: shimmer 1.6s linear infinite;
  border-radius: var(--r-sm);
}

/* ---------- GRID LAYOUTS ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.grid-main-side { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }

@media (max-width: 1200px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-main-side { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- TABLE ---------- */
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-1);
  flex-wrap: wrap;
}

.table-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 9px 14px;
  min-width: 240px;
  flex: 1;
  max-width: 340px;
}
.table-search svg { width: 15px; height: 15px; stroke: var(--text-3); flex-shrink: 0; }
.table-search input {
  background: none; border: none; outline: none;
  color: var(--text-0); font-size: 13px; width: 100%; font-family: inherit;
}
.table-search input::placeholder { color: var(--text-4); }

.select-filter {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  color: var(--text-1);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.select-filter:focus { outline: none; border-color: var(--ets-red); }

.table-wrap { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table thead th {
  text-align: left;
  padding: 13px 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border-1);
  background: var(--bg-1);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.data-table thead th:hover { color: var(--text-1); }
.data-table thead th .sort-arrow { margin-left: 4px; opacity: 0.5; font-size: 10px; }
.data-table thead th.is-sorted .sort-arrow { opacity: 1; color: var(--ets-red-bright); }

.data-table tbody tr {
  border-bottom: 1px solid var(--border-1);
  transition: background var(--t-fast) var(--ease);
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-2); }

.data-table td {
  padding: 14px 20px;
  color: var(--text-1);
  vertical-align: middle;
}

.table-athlete-cell { display: flex; align-items: center; gap: 12px; }
.table-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bg-4), var(--bg-3));
  border: 1px solid var(--border-2);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-1);
  flex-shrink: 0;
}
.table-athlete-cell strong { display: block; color: var(--text-0); font-size: 13.5px; font-weight: 700; }
.table-athlete-cell span { display: block; font-size: 12px; color: var(--text-3); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--border-1);
  flex-wrap: wrap;
  gap: 12px;
}
.table-footer__info { font-size: 12.5px; color: var(--text-3); }
.pagination { display: flex; gap: 6px; align-items: center; }
.page-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 7px;
  border: 1px solid var(--border-2);
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.page-btn:hover { border-color: var(--text-3); color: var(--text-0); }
.page-btn.is-active { background: var(--ets-red); border-color: var(--ets-red); color: var(--text-0); }
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-3);
}
.empty-state svg { width: 48px; height: 48px; stroke: var(--text-4); margin: 0 auto 16px; }
.empty-state h3 { font-size: 16px; color: var(--text-1); margin-bottom: 6px; }
.empty-state p { font-size: 13px; margin-bottom: 18px; }

/* ---------- FORMS ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.form-grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .form-grid, .form-grid--3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .form-grid, .form-grid--3 { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 7px; }
.field--span2 { grid-column: span 2; }
.field--span3 { grid-column: span 3; }
@media (max-width: 900px) { .field--span3 { grid-column: span 2; } }
@media (max-width: 600px) { .field--span2, .field--span3 { grid-column: span 1; } }

.field label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-2);
}
.field label .req { color: var(--ets-red-bright); }

.field input,
.field select,
.field textarea {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  color: var(--text-0);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: all var(--t-fast) var(--ease);
  width: 100%;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--ets-red);
  box-shadow: 0 0 0 3px rgba(192,0,0,0.15);
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-4); }
.field textarea { resize: vertical; min-height: 90px; }
.field select { cursor: pointer; }
.field small { color: var(--text-4); font-size: 11.5px; }

.form-section-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-0);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
}
.form-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-1);
}
.form-section-title--speed { color: var(--text-1); }
.form-section-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ets-red-bright); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--border-1);
}

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn var(--t-fast) var(--ease);
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  animation: popIn var(--t-med) var(--ease);
}
.modal--wide { max-width: 900px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-1);
  position: sticky;
  top: 0;
  background: var(--bg-2);
  z-index: 2;
}
.modal-header h3 { font-size: 17px; }
.modal-body { padding: 24px; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: var(--bg-3);
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.modal-close:hover { color: var(--text-0); border-color: var(--ets-red); }

/* ---------- TOAST ---------- */
.toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--ets-red-bright);
  border-radius: var(--r-sm);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  animation: fadeUp var(--t-fast) var(--ease);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
}
.toast--success { border-left-color: var(--success); }
.toast--danger { border-left-color: var(--ets-red-bright); }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast--success svg { stroke: var(--success); }
.toast--danger svg { stroke: var(--ets-red-bright); }

/* ---------- MISC ---------- */
.divider { height: 1px; background: var(--border-1); margin: 20px 0; }

.stat-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-inline__label { font-size: 11.5px; color: var(--text-3); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-inline__value { font-size: 20px; font-weight: 800; color: var(--text-0); }

.tag {
  display: inline-flex;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-4);
  color: var(--text-1);
  border: 1px solid var(--border-2);
}

.progress-ring-wrap { position: relative; display: grid; place-items: center; }
.progress-ring-value {
  position: absolute;
  font-size: 20px;
  font-weight: 800;
  color: var(--text-0);
}

.chart-card { min-height: 340px; display: flex; flex-direction: column; }
.chart-card canvas { max-width: 100%; }
.chart-card__body { flex: 1; position: relative; }

.insight-card {
  display: flex;
  gap: 14px;
  padding: 18px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, rgba(192,0,0,0.1), rgba(192,0,0,0.02));
  border: 1px solid rgba(192,0,0,0.25);
  animation: fadeUp var(--t-slow) var(--ease) both;
}
.insight-card__icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: rgba(192,0,0,0.2);
  color: var(--ets-red-bright);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.insight-card__icon svg { width: 18px; height: 18px; }
.insight-card p { font-size: 13.5px; color: var(--text-1); line-height: 1.55; }
.insight-card strong { color: var(--ets-red-bright); }

.compare-bar-row { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.compare-bar-row:last-child { margin-bottom: 0; }
.compare-bar-row__label { width: 150px; font-size: 12.5px; font-weight: 700; color: var(--text-2); flex-shrink: 0; }
.compare-bar-track { flex: 1; height: 10px; background: var(--bg-4); border-radius: var(--r-full); overflow: hidden; display: flex; }
.compare-bar-fill { height: 100%; border-radius: var(--r-full); transition: width 1s var(--ease); }
.compare-bar-row__value { width: 56px; text-align: right; font-size: 13px; font-weight: 800; color: var(--text-0); flex-shrink: 0; }

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-1);
}
.leaderboard-item:last-child { border-bottom: none; }
.leaderboard-rank {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  background: var(--bg-4);
  color: var(--text-2);
  flex-shrink: 0;
}
.leaderboard-rank--1 { background: linear-gradient(135deg, #ffd700, #b8860b); color: #1a1a1a; }
.leaderboard-rank--2 { background: linear-gradient(135deg, #d8d8d8, #9a9a9a); color: #1a1a1a; }
.leaderboard-rank--3 { background: linear-gradient(135deg, #cd7f32, #8b5a2b); color: #fff; }
.leaderboard-item__name { flex: 1; min-width: 0; }
.leaderboard-item__name strong { display: block; font-size: 13px; color: var(--text-0); font-weight: 700; }
.leaderboard-item__name span { font-size: 11.5px; color: var(--text-3); }
.leaderboard-item__value { font-size: 14px; font-weight: 800; color: var(--ets-red-bright); flex-shrink: 0; }

.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 5px 10px;
  border-radius: var(--r-full);
  font-size: 13px;
  font-weight: 800;
}
.score-excellent { background: rgba(47,191,110,0.15); color: var(--success); border: 1px solid rgba(47,191,110,0.35); }
.score-great { background: rgba(120,190,255,0.12); color: #7ec0ff; border: 1px solid rgba(120,190,255,0.3); }
.score-average { background: rgba(217,164,65,0.15); color: var(--warning); border: 1px solid rgba(217,164,65,0.35); }
.score-needs { background: rgba(227,0,0,0.15); color: var(--ets-red-bright); border: 1px solid rgba(227,0,0,0.35); }
