/* ── Page layout ─────────────────────────────────── */
.km-page {
  max-width: 1400px;
  margin: 20px auto;
  background: #fff;
  padding: 28px 30px;
  border-radius: var(--km-radius-card);
  box-shadow: var(--km-shadow);
}
h1 {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 20px;
  font-size: 28px;
  font-weight: 700;
  font-family: var(--km-font-brand);
}

/* ── Event card ──────────────────────────────────── */
.km-event-card {
  position: relative;
  border-radius: var(--km-radius-card);
  overflow: hidden;
  height: 180px;
  margin-bottom: 18px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
}
.km-event-card__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.28);
}
.km-event-card__controls {
  position: relative;
  z-index: 2;
  background: rgba(255,255,255,.96);
  padding: 14px 20px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.km-select-group { display: flex; gap: 8px; align-items: center; }
.km-label { font-weight: 600; color: #333; font-size: 14px; white-space: nowrap; }
.km-select {
  padding: 7px 11px;
  border: 2px solid var(--km-primary);
  border-radius: var(--km-radius-input);
  font-size: 13px;
  color: #333;
  background: #fff;
  outline: none;
  font-family: var(--km-font-ui);
  cursor: pointer;
}
.km-select--year { min-width: 85px; }
.km-input {
  padding: 7px 12px;
  border: 2px solid var(--km-primary);
  border-radius: var(--km-radius-input);
  font-size: 13px;
  color: #333;
  background: #fff;
  outline: none;
  font-family: var(--km-font-ui);
  min-width: 200px;
}
.km-input:focus, .km-select:focus { box-shadow: 0 0 0 3px rgba(238,45,98,.12); }

/* ── Toolbar & filters ───────────────────────────── */
.km-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.km-filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.km-filter-group { display: flex; flex-direction: column; gap: 4px; }
.km-search-group { flex: 1; min-width: 200px; }
.km-search-group .km-input { width: 100%; }

/* ── Status messages ─────────────────────────────── */
.km-loading { text-align: center; padding: 20px; color: #888; font-size: 14px; }
.km-error {
  text-align: center;
  padding: 12px;
  color: #c0392b;
  font-size: 13px;
  background: #ffeaea;
  border-radius: 6px;
  margin-bottom: 12px;
}

/* ── Export PDF button ───────────────────────────── */
.km-btn-export {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  background: var(--km-primary);
  color: #fff;
  border: none;
  border-radius: var(--km-radius-btn, 50px);
  font-family: var(--km-font-ui);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(238,45,98,.3);
  align-self: flex-end;
}
.km-btn-export:hover {
  background: #d4254f;
  box-shadow: 0 4px 12px rgba(238,45,98,.4);
  transform: translateY(-1px);
}
.km-btn-export:active { transform: translateY(0); }
.km-btn-export svg { flex-shrink: 0; }

/* ── Profile button ──────────────────────────────── */
.detail-name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.km-btn-profile {
  display: inline-block;
  padding: 3px 10px;
  border: 1.5px solid var(--km-primary);
  border-radius: 12px;
  color: var(--km-primary);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.km-btn-profile:hover { background: var(--km-primary); color: #fff; }

/* ── Results table ───────────────────────────────── */
.km-table-wrap {
  border-radius: var(--km-radius-card);
  box-shadow: 0 6px 15px rgba(0,0,0,.1);
  overflow: hidden;
  margin-bottom: 20px;
  overflow-x: auto;
}
.km-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 13px;
}
.km-th {
  background: linear-gradient(to bottom, var(--km-primary), #1a1a1a);
  color: #fff;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  font-size: 11px;
  padding: 12px 10px;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.km-th--c { text-align: center; }
.km-th--l { text-align: left; padding-left: 14px; }
.km-th--sort { cursor: pointer; }
.km-th--sort:hover { background: linear-gradient(to bottom, #c0234f, #111); }
.km-tr { cursor: pointer; }
.km-tr:hover .km-td { background: #e3f2fd !important; }
.km-td {
  padding: 11px 10px;
  border-bottom: 1px solid #eaeaea;
  text-align: center;
}
.km-td--l { text-align: left; padding-left: 14px; }
.km-td--even { background: #f8f9fa; }
.km-td--odd { background: #fff; }
.km-td--exp { background: #fff5f7 !important; }
.row-active .km-td { background: #fff5f7 !important; }
.km-rank-medal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.km-rank-medal--1 { background: #FFD700; color: #7a5800; }
.km-rank-medal--2 { background: #C0C0C0; color: #444; }
.km-rank-medal--3 { background: #CD7F32; color: #5a3010; }
.km-rank-num { font-weight: 800; font-size: 14px; color: #333; }
.km-bib { color: var(--km-primary); font-weight: 700; }
.km-name-main { font-weight: 600; }
.km-name-sub { font-size: 11px; color: #bbb; margin-top: 2px; }
.km-expand-icon { font-size: 10px; color: #ccc; margin-left: 4px; transition: transform .2s; display: inline-block; }
.km-expand-icon--open { transform: rotate(180deg); }
.km-cat-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; background: #f0f0f0; color: #555; }
.km-time-gun { font-family: 'Courier New', monospace; font-weight: 600; color: var(--km-primary); letter-spacing: .5px; }
.km-time-net { font-family: 'Courier New', monospace; font-weight: 600; color: #1a73e8; letter-spacing: .5px; }

/* ── Detail panel ────────────────────────────────── */
.detail-panel-row > td {
  background: #fafafa;
  padding: 0;
  border-top: 3px solid var(--km-primary);
  border-bottom: 2px solid var(--km-primary);
}
.detail-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 20px;
  border-bottom: 1px solid #eee;
}
.detail-panel-name { font-size: 18px; font-weight: 700; color: #1a1a1a; }
.detail-panel-meta { font-size: 12px; color: #888; margin-top: 3px; }
.detail-panel-actions { display: flex; gap: 8px; align-items: center; }
.detail-panel-profile-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 50px;
  background: var(--km-primary);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--km-font-ui);
}
.detail-panel-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #bbb;
  cursor: pointer;
  padding: 0 4px;
}
.detail-panel-close:hover { color: #555; }

/* Mobile tabs */
.detail-tabs { display: flex; border-bottom: 1px solid #ddd; background: #fff; }
.detail-tab {
  flex: 1;
  padding: 10px 4px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: #888;
  font-weight: 500;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--km-font-ui);
  transition: all .15s;
}
.detail-tab.active { color: var(--km-primary); border-bottom-color: var(--km-primary); font-weight: 700; }
.detail-tab-pane { display: none; }
.detail-tab-pane.active { display: block; }

@media (min-width: 641px) {
  .detail-tabs { display: none; }
  .detail-tab-pane { display: block; }
  .detail-tab-pane + .detail-tab-pane { border-top: 1px solid #eee; }
}

/* Times 2-column grid */
.detail-times-grid { display: grid; grid-template-columns: 1fr 1fr; }
.detail-time-col { padding: 16px 20px; }
.detail-time-col--gun { border-right: 1px solid #eee; }
.detail-time-col-title { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: #aaa; font-weight: 600; margin-bottom: 10px; }
.detail-time-big { font-size: 28px; font-weight: 800; font-family: 'Courier New', monospace; margin-bottom: 12px; }
.detail-time-big--gun { color: var(--km-primary); }
.detail-time-big--net { color: #1a73e8; }
.detail-rank-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
.detail-rank-row:last-child { border-bottom: none; }
.detail-rank-label { color: #888; }
.detail-rank-val { font-weight: 700; color: #1a1a1a; }
.detail-rank-num { color: var(--km-primary); font-weight: 800; }

/* Chart + splits sections */
.detail-chart-section, .detail-splits-section { padding: 16px 20px; }
.detail-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: #aaa; font-weight: 700; margin-bottom: 12px; }
.detail-chart-canvas-wrap { height: 160px; position: relative; }

/* ── Segments tables ─────────────────────────────── */
.segment-section-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #888;
  font-weight: 700;
  padding: 10px 0 6px;
  border-bottom: 2px solid var(--km-primary);
  margin: 16px 0 0;
}
.segments-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.segments-table thead th {
  background: #f5f5f5;
  padding: 9px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #555;
  border-bottom: 2px solid var(--km-primary);
  font-weight: 700;
}
.segments-table thead th:first-child { text-align: left; }
.segments-table thead th:not(:first-child) { text-align: center; }
.segments-table tbody tr { background: #fff; border-bottom: 1px solid #efefef; }
.segments-table tbody tr:nth-child(even) { background: #fafafa; }
.segments-table tbody tr:hover { background: #e3f2fd; }
.segments-table tbody td { padding: 9px 12px; color: #222; }
.segments-table tbody td:first-child { text-align: left; font-weight: 600; color: #333; }
.segments-table tbody td:not(:first-child) { text-align: center; }
.seg-mono { font-family: 'Courier New', monospace; font-weight: 600; }
.seg-rank-badge { display: inline-block; min-width: 24px; padding: 1px 6px; border-radius: 10px; font-weight: 700; font-size: 11px; text-align: center; }
.seg-rank-badge--top { background: var(--km-primary); color: #fff; }
.seg-rank-badge--normal { background: #e0e0e0; color: #555; }
.seg-pace-bar { height: 6px; border-radius: 3px; margin-top: 3px; }
.seg-pace-bar--fast { background: #27ae60; }
.seg-pace-bar--slow { background: var(--km-primary); }

/* ── Gender & age-group badges ───────────────────── */
.gender-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.gender-male { background: #e3f2fd; color: #1565c0; }
.gender-female { background: #fce4ec; color: #c62828; }
.age-group-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: #f0f0f0;
  color: #555;
}
.page-title-event {
  text-align: center;
  font-size: 14px;
  color: #888;
  margin-bottom: 16px;
  margin-top: -12px;
}

/* ── Mobile ──────────────────────────────────────── */
@media (max-width: 640px) {
  .km-page { padding: 12px; margin: 8px; border-radius: 8px; }
  .km-event-card {
    height: 110px;
    padding: 0 12px;
    justify-content: center;
  }
  .km-event-card__controls { padding: 10px 12px; gap: 8px; width: 100%; }
  .km-toolbar { gap: 6px; }
  .km-input { min-width: 0; }
  .detail-times-grid { grid-template-columns: 1fr; }
  .detail-time-col--gun { border-right: none; border-bottom: 1px solid #eee; }
  .detail-time-big { font-size: 22px; }

  /* Fit results table in viewport so detail panel doesn't overflow */
  #resultsTable { table-layout: fixed; }
  #resultsTable .km-th:nth-child(1),
  #resultsTable .km-td:nth-child(1) { width: 38px; }
  #resultsTable .km-th:nth-child(2),
  #resultsTable .km-td:nth-child(2) { width: 34px; }
  #resultsTable .km-th:nth-child(4),
  #resultsTable .km-td:nth-child(4) { width: 76px; }
  #resultsTable .km-th:nth-child(5),
  #resultsTable .km-td:nth-child(5) { width: 76px; }
  .km-th { padding: 10px 5px; font-size: 9px; }
  .km-td { padding: 8px 5px; font-size: 12px; }
  .km-td--l { padding-left: 6px; }

  /* Segments table — card layout on mobile, all data visible */
  .detail-splits-section { overflow-x: visible; padding: 8px 10px; }
  .segments-table,
  .segments-table tbody { display: block; }
  .segments-table colgroup,
  .segments-table thead { display: none; }
  .segments-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 6px;
    background: #fff;
  }
  .segments-table tbody tr:nth-child(even) { background: #fafafa; }
  .segments-table tbody .seg-name {
    grid-column: 1 / -1;
    padding: 7px 10px;
    font-weight: 700;
    font-size: 12px;
    background: #f5f5f5;
    border-bottom: 1px solid #eee;
    text-align: left;
  }
  .segments-table tbody .seg-time,
  .segments-table tbody .seg-pace {
    padding: 5px 10px;
    font-size: 12px;
    border-bottom: 1px solid #f0f0f0;
    text-align: left;
  }
  .segments-table tbody .seg-time { grid-column: 1 / 2; border-right: 1px solid #f0f0f0; }
  .segments-table tbody .seg-pace { grid-column: 2 / 4; }
  .segments-table tbody .seg-time::before { content: "Время\A"; white-space: pre; color: #888; font-size: 9px; text-transform: uppercase; font-weight: 600; }
  .segments-table tbody .seg-pace::before { content: "Темп\A"; white-space: pre; color: #888; font-size: 9px; text-transform: uppercase; font-weight: 600; }
  .segments-table tbody .seg-rank {
    padding: 5px 4px;
    text-align: center;
    font-size: 11px;
  }
  .segments-table tbody .seg-rank:nth-child(4)::before { content: "Абс.\A"; white-space: pre; color: #888; font-size: 9px; text-transform: uppercase; font-weight: 600; display: block; }
  .segments-table tbody .seg-rank:nth-child(5)::before { content: "Пол\A"; white-space: pre; color: #888; font-size: 9px; text-transform: uppercase; font-weight: 600; display: block; }
  .segments-table tbody .seg-rank:nth-child(6)::before { content: "Кат.\A"; white-space: pre; color: #888; font-size: 9px; text-transform: uppercase; font-weight: 600; display: block; }
}
