/* ============================================================
   MX Results Pro - Competition Results Viewer
   Dark motorsport theme, responsive, professional
   ============================================================ */

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2236;
  --bg-card-hover: #1f2a42;
  --bg-table-row: #151d30;
  --bg-table-row-alt: #1a2439;
  --bg-table-header: #131b2e;
  --accent: #e63946;
  --accent-light: #ff4d5a;
  --accent-dark: #b02e38;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-yellow: #fbbf24;
  --border: #1e293b;
  --border-light: #334155;
  --success: #22c55e;
  --info: #3b82f6;
  --warning: #eab308;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

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

/* --- LIGHT THEME --- */
[data-theme="light"] {
  --bg-primary: #eef0f4;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f3f5f9;
  --bg-table-row: #ffffff;
  --bg-table-row-alt: #f6f7fb;
  --bg-table-header: #e2e6ee;
  --text-primary: #1a1a2e;
  --text-secondary: #4a5468;
  --text-muted: #6b7a90;
  --border: #d2d7e0;
  --border-light: #bfc6d2;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

/* Header */
[data-theme="light"] .site-header {
  background: linear-gradient(135deg, #ffffff 0%, #eef0f5 100%);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

/* Hero */
[data-theme="light"] .event-hero {
  background: linear-gradient(135deg, #ffffff 0%, #e8ecf3 100%);
  border-color: #d0d5df;
}

/* Sidebar group headers — stronger contrast */
[data-theme="light"] .sidebar-group-title {
  background: #d5dae5;
  color: #3d4659;
  border-bottom-color: #c4cad6;
}
[data-theme="light"] .sidebar-item:hover {
  background: #edf0f6;
}
[data-theme="light"] .sidebar-item.active {
  background: rgba(230,57,70,0.1);
}

/* Session header — more visible */
[data-theme="light"] .session-header {
  background: #dce1eb;
}
[data-theme="light"] .session-header:hover {
  background: #d0d6e2;
}

/* Class tabs */
[data-theme="light"] .class-tabs {
  background: #e8ecf3;
  border-color: #d0d5df;
}
[data-theme="light"] .class-tab:hover {
  background: rgba(0,0,0,0.06);
}

/* Table headers — distinct background */
[data-theme="light"] .results-table thead th {
  background: #d5dae5;
  color: #3d4659;
}
[data-theme="light"] .results-table thead .col-pos,
[data-theme="light"] .results-table thead .col-no,
[data-theme="light"] .results-table thead .col-rider {
  background: #d5dae5;
}

/* Table row hover */
[data-theme="light"] .results-table tbody tr:hover > td {
  background: #e8ecf3;
}
[data-theme="light"] .results-table tbody tr:hover > .col-pos,
[data-theme="light"] .results-table tbody tr:hover > .col-no,
[data-theme="light"] .results-table tbody tr:hover > .rider-name {
  background: #e8ecf3;
}

/* Pos badge & rider number */
[data-theme="light"] .pos-badge {
  box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
}
[data-theme="light"] .rider-number {
  background: #e2e6ee;
  border-color: #ccd2dc;
  color: var(--text-primary);
}

/* Frozen column edge shadow */
[data-theme="light"] .results-table .col-no::after,
[data-theme="light"] .results-table .rider-name::after,
[data-theme="light"] .results-table .col-rider::after {
  background: linear-gradient(to right, rgba(0,0,0,0.07), transparent);
}

/* View toggle & sidebar toggle */
[data-theme="light"] .view-toggle {
  background: #e8ecf3;
  border-color: #ccd2dc;
}

/* Weather bar */
[data-theme="light"] .weather-bar {
  background: #e8ecf3;
  border-top-color: #d0d5df;
}

/* PDF links bar */
[data-theme="light"] .pdf-links-bar {
  background: #edf0f6;
}

/* Event card */
[data-theme="light"] .event-card {
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
[data-theme="light"] .event-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

/* Championship table */
[data-theme="light"] .championship-table thead th {
  background: #d5dae5;
  color: #3d4659;
}
[data-theme="light"] .championship-table .champ-total-col {
  background: rgba(230,180,0,0.1);
}

/* Modals */
[data-theme="light"] .lt-modal-overlay {
  background: rgba(0,0,0,0.35);
}
[data-theme="light"] .lt-modal {
  box-shadow: 0 25px 60px rgba(0,0,0,0.18);
}

/* Scrollbar */
[data-theme="light"] ::-webkit-scrollbar-track {
  background: #eef0f4;
}
[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #c4cad6;
}
[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: #8892a4;
}

/* Session badges */
[data-theme="light"] .session-badge {
  border-color: #bfc6d2;
}

/* Tree view */
[data-theme="light"] .tree-folder {
  border-color: #d0d5df;
}
[data-theme="light"] .tree-folder-header {
  background: #e2e6ee;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* --- HEADER --- */
.site-header {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
  border-bottom: 2px solid var(--accent);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(0,0,0,0.5);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  flex-shrink: 0;
}

.header-logo-img { height: 32px; width: auto; }
.header-title-link {
  text-decoration: none;
  color: var(--text-primary);
  flex-shrink: 0;
}
.header-logo svg { width: 36px; height: 36px; }
.header-logo-text {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  text-transform: uppercase;
}
.header-logo-text span { color: var(--accent); }

.header-context {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--accent);
  padding: 3px 10px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
  overflow: hidden;
}
.header-breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--transition);
}
.header-breadcrumb a:hover { color: var(--accent-light); }
.header-breadcrumb .sep { color: var(--text-muted); user-select: none; }
.header-breadcrumb .current { color: var(--text-primary); font-weight: 600; }

/* --- THEME TOGGLE --- */
.theme-toggle {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

/* --- MAIN CONTENT --- */
.main-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* --- EVENT HERO BANNER --- */
.event-hero {
  background: linear-gradient(135deg, var(--bg-card) 0%, #0f1a2e 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}
.event-hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark), transparent);
}
.event-hero-title {
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.event-hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}
.event-hero-meta .meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.event-hero-meta .meta-item svg {
  width: 15px;
  height: 15px;
  color: var(--accent);
  flex-shrink: 0;
}

/* --- EVENT CARDS (Homepage) --- */
.events-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
  margin-top: 24px;
}

.event-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.event-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.event-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}
.event-card:hover::after { transform: scaleX(1); }

.event-card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.event-card-location {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.event-card-location svg,
.event-card-date svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.event-card-date {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.event-card-badge {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --- CLASS TABS --- */
.class-tabs-container {
  margin-bottom: 20px;
}
.class-tabs-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-left: 4px;
}
.class-tabs-label svg {
  width: 12px;
  height: 12px;
  opacity: 0.6;
}
.class-tabs-label span {
  color: var(--text-secondary);
}
.class-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 5px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.class-tab {
  padding: 9px 22px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.25s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: relative;
}
.class-tab:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.05);
}
.class-tab.active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(230,57,70,0.35);
}

/* --- SIDEBAR + CONTENT LAYOUT --- */
.event-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 84px);
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }

.sidebar-group-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 14px 16px 6px;
  background: var(--bg-table-header);
  border-bottom: 1px solid var(--border);
}
.sidebar-group-title:first-child { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 5px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: all var(--transition);
  user-select: none;
}
.sidebar-item:hover { background: var(--bg-card-hover); }
.sidebar-item.active {
  background: rgba(230,57,70,0.1);
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}
.sidebar-item-icon {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
}
.sidebar-item-icon.quali { background: rgba(59,130,246,0.15); color: var(--info); }
.sidebar-item-icon.race { background: rgba(230,57,70,0.15); color: var(--accent); }
.sidebar-item-icon.total { background: rgba(255,215,0,0.15); color: var(--gold); }
.sidebar-item-icon.grid { background: rgba(34,197,94,0.15); color: var(--success); }
.sidebar-item-icon.document { background: rgba(148,163,184,0.15); color: var(--text-secondary); }
.sidebar-item-icon.championship { background: rgba(255,215,0,0.15); color: var(--gold); }

a.sidebar-pdf-link {
  text-decoration: none;
  color: inherit;
}
a.sidebar-pdf-link:hover { background: var(--bg-card-hover); }
a.sidebar-pdf-link .download-count {
  font-size: 9px;
  background: rgba(148,163,184,0.2);
  color: var(--text-secondary);
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: 4px;
}

.sidebar-item-text {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.sidebar-item-riders {
  font-size: 10px;
  color: var(--text-yellow);
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 0;
}
.sidebar-upload-time {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--text-yellow);
  font-size: 10px;
}
.sidebar-upload-time svg { width: 10px; height: 10px; }

.content-panel { min-width: 0; }

/* --- SESSION SECTIONS --- */
.session-group {
  margin-bottom: 28px;
}
.session-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 12px;
  padding-left: 4px;
}

.session-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 16px;
  transition: border-color var(--transition);
}
.session-card:hover { border-color: var(--border-light); }

.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-table-header);
  transition: background var(--transition);
  gap: 12px;
}
.session-header:hover { background: var(--bg-card-hover); }

.session-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.session-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}
.session-icon.quali { background: rgba(59,130,246,0.15); color: var(--info); }
.session-icon.race { background: rgba(230,57,70,0.15); color: var(--accent); }
.session-icon.total { background: rgba(255,215,0,0.15); color: var(--gold); }
.session-icon.grid { background: rgba(34,197,94,0.15); color: var(--success); }
.session-icon.document { background: rgba(148,163,184,0.15); color: var(--text-secondary); }
.session-icon.championship { background: rgba(255,215,0,0.15); color: var(--gold); }

.session-name-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.session-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.session-header-pdfs {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.session-header-pdfs .pdf-link {
  padding: 3px 9px;
  font-size: 10px;
}

.session-badges {
  display: flex;
  gap: 6px;
}
.session-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.session-badge.type-quali { background: rgba(59,130,246,0.15); color: var(--info); }
.session-badge.type-race { background: rgba(230,57,70,0.15); color: var(--accent-light); }
.session-badge.type-total { background: rgba(255,215,0,0.15); color: var(--gold); }
.session-badge.type-grid { background: rgba(34,197,94,0.15); color: var(--success); }
.session-badge.type-document { background: rgba(148,163,184,0.15); color: var(--text-secondary); }
.session-badge.type-championship { background: rgba(255,215,0,0.15); color: var(--gold); }
.session-badge.review-badge {
  background: rgba(59,130,246,0.2);
  color: var(--accent);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  padding: 2px 8px;
  gap: 0;
}
.review-label { font-weight: 700; font-size: 9px; white-space: nowrap; }
.review-time { font-size: 8px; opacity: 0.8; white-space: nowrap; }

.session-chevron {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: transform 0.3s ease;
  flex-shrink: 0;
}
.session-card.expanded .session-chevron { transform: rotate(180deg); }

.session-body {
  display: none;
  padding: 0;
}
.session-card.expanded .session-body { display: block; }

/* --- WEATHER BAR --- */
.weather-bar {
  display: flex;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.weather-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.weather-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* --- META COMMENTS (penalties, notices) --- */
.meta-comments {
  padding: 12px 20px;
  background: rgba(234,179,8,0.06);
  border-top: 1px solid rgba(234,179,8,0.15);
}
.meta-comment-item {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 0;
  padding-left: 16px;
  position: relative;
  line-height: 1.5;
}
.meta-comment-item::before {
  content: '⚠';
  position: absolute;
  left: 0;
  font-size: 11px;
}

/* --- RESULTS TABLE --- */
.results-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.results-table thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  background: var(--bg-table-header);
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 2;
}
.results-table thead th.col-pos,
.results-table thead th.col-no { text-align: center; }

.results-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.results-table tbody tr:nth-child(odd) { background: var(--bg-table-row); }
.results-table tbody tr:nth-child(even) { background: var(--bg-table-row-alt); }
.results-table tbody tr:hover { background: var(--bg-card-hover); }

.results-table tbody td {
  padding: 8px 12px;
  vertical-align: middle;
}

.results-table .col-pos {
  text-align: center;
  font-weight: 800;
  width: 44px;
  position: sticky;
  left: 0;
  z-index: 3;
  padding: 8px 6px;
}
.results-table .col-no {
  text-align: center;
  width: 38px;
  position: sticky;
  left: 38px;
  z-index: 3;
  padding: 8px 6px;
}
.results-table .col-rider,
.results-table .rider-name {
  position: sticky;
  left: 82px;
  z-index: 3;
  min-width: 130px;
}

/* Frozen column backgrounds — must be opaque to hide scrolling content */
.results-table thead .col-pos,
.results-table thead .col-no,
.results-table thead .col-rider {
  background: var(--bg-table-header);
  z-index: 5;
}
.results-table tbody tr:nth-child(odd) > .col-pos,
.results-table tbody tr:nth-child(odd) > .col-no,
.results-table tbody tr:nth-child(odd) > .rider-name {
  background: var(--bg-table-row);
}
.results-table tbody tr:nth-child(even) > .col-pos,
.results-table tbody tr:nth-child(even) > .col-no,
.results-table tbody tr:nth-child(even) > .rider-name {
  background: var(--bg-table-row-alt);
}
.results-table tbody tr:hover > .col-pos,
.results-table tbody tr:hover > .col-no,
.results-table tbody tr:hover > .rider-name {
  background: var(--bg-card-hover);
}

/* Frozen edge shadow */
.results-table .rider-name::after,
.results-table .col-rider::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 0;
  bottom: 0;
  width: 6px;
  background: linear-gradient(to right, rgba(0,0,0,0.2), transparent);
  pointer-events: none;
}

.pos-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font-weight: 800;
  font-size: 12px;
}
.pos-1 { background: linear-gradient(135deg, #ffd700, #e6ac00); color: #1a1a00; }
.pos-2 { background: linear-gradient(135deg, #c0c0c0, #a0a0a0); color: #1a1a1a; }
.pos-3 { background: linear-gradient(135deg, #cd7f32, #a66828); color: #1a1000; }

.rider-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  font-weight: 700;
  font-size: 11px;
  color: var(--text-primary);
}

.rider-name { font-weight: 600; }

.flag-icon {
  display: inline-block;
  width: 20px;
  height: 14px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 6px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1);
}
.flag-text {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.col-time { font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace; font-size: 12px; }
.col-diff { font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace; font-size: 12px; color: var(--text-secondary); }
.col-points { font-weight: 700; color: var(--gold); text-align: center; }
.col-speed { color: var(--text-secondary); }
.col-laps { text-align: center; }
.col-bike { color: var(--text-secondary); font-size: 12px; }

.best-time-highlight { color: #a78bfa; font-weight: 600; }

/* Status indicators */
.status-dnf { color: #fff; font-weight: 700; background: var(--accent); padding: 2px 7px; border-radius: 3px; font-size: 9px; text-transform: uppercase; vertical-align: middle; margin-left: 4px; }
.status-dns { color: #fff; font-weight: 600; background: var(--accent-dark); padding: 2px 7px; border-radius: 3px; font-size: 9px; text-transform: uppercase; vertical-align: middle; margin-left: 4px; }
.status-dsq { color: #fff; font-weight: 700; background: #7c2d12; padding: 2px 7px; border-radius: 3px; font-size: 9px; text-transform: uppercase; vertical-align: middle; margin-left: 4px; }
.status-irm { color: #fff; font-weight: 600; background: var(--accent); padding: 2px 7px; border-radius: 3px; font-size: 9px; text-transform: uppercase; vertical-align: middle; margin-left: 4px; }
.status-tag { display: inline-block; }
.col-points-muted { font-weight: 600; color: var(--text-muted); text-align: center; }

/* Warning icon for penalized riders */
.warning-icon { color: var(--warning); font-size: 14px; vertical-align: middle; margin-left: 2px; cursor: help; }

/* Championship standings table */
.championship-table .champ-event-header {
  text-align: center;
  font-size: 9px;
  background: rgba(255,215,0,0.08);
  border-left: 2px solid var(--border-light);
  white-space: nowrap;
  min-width: 70px;
}
.championship-table .champ-race-label {
  text-align: center;
  font-size: 8px;
  font-weight: 600;
  padding: 4px 6px;
  background: rgba(255,215,0,0.05);
  border-left: 1px solid var(--border);
  color: var(--text-muted);
}
.championship-table .champ-event-cell {
  text-align: center;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  border-left: 1px solid var(--border);
  padding: 6px 4px;
  white-space: nowrap;
}
.champ-pos { color: var(--text-muted); font-size: 10px; }
.champ-pts { color: var(--gold); font-weight: 700; }

/* Progression badges */
.col-prog { text-align: center; width: 40px; }
.prog {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.prog-up { color: var(--success); }
.prog-down { color: var(--accent); }
.prog-same { color: var(--text-muted); }
.prog-new {
  color: var(--info);
  font-size: 9px;
  letter-spacing: 0.5px;
}

/* --- PDF LINKS --- */
.pdf-links-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}
.pdf-links-bar.in-header {
  border-top: none;
  background: none;
  padding: 0;
  gap: 5px;
}

.pdf-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent-light);
  border-radius: 5px;
  text-decoration: none;
  transition: all var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.pdf-link:hover {
  background: var(--accent-light);
  border-color: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(230,57,70,0.3);
}
.pdf-link svg { width: 13px; height: 13px; flex-shrink: 0; }
.download-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  font-size: 9px;
  font-weight: 700;
  background: rgba(255,255,255,0.25);
  color: #fff;
  border-radius: 9px;
  padding: 0 5px;
  margin-left: 4px;
}

/* --- LOADING & EMPTY STATES --- */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  gap: 16px;
}
.spinner-ring {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }

/* --- FOOTER --- */
.site-footer {
  text-align: center;
  padding: 20px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.site-footer a { color: var(--accent-light); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* --- MOBILE SIDEBAR TOGGLE --- */
.sidebar-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.sidebar-toggle svg { width: 16px; height: 16px; }

/* --- RESPONSIVE --- */
@media (max-width: 960px) {
  .event-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    display: none;
  }
  .sidebar.mobile-open { display: block; }
  .sidebar-toggle { display: flex; }
  .event-toolbar { justify-content: space-between; }
}

@media (max-width: 768px) {
  .header-inner { padding: 10px 14px; }
  .header-logo-text { font-size: 15px; }
  .header-breadcrumb { font-size: 11px; }

  .main-container { padding: 16px 12px 40px; }

  .event-hero { padding: 18px 16px; }
  .event-hero-title { font-size: 16px; }
  .event-hero-meta { gap: 12px; font-size: 12px; }

  .events-grid { grid-template-columns: 1fr; gap: 12px; }
  .event-card { padding: 16px; }

  .class-tabs { padding: 3px; gap: 3px; }
  .class-tab { padding: 7px 14px; font-size: 12px; }
  .class-tabs-label { font-size: 9px; margin-bottom: 6px; }

  .session-header { padding: 10px 14px; flex-wrap: wrap; }
  .session-name { font-size: 13px; }
  .session-icon { width: 28px; height: 28px; font-size: 12px; }

  .results-table { font-size: 12px; }
  .results-table thead th { padding: 8px 6px; font-size: 9px; }
  .results-table tbody td { padding: 6px 6px; }

  /* Compact frozen columns on mobile — only pos + no are frozen */
  .results-table .col-pos { width: 36px; left: 0; padding: 6px 4px; }
  .results-table .col-no { width: 40px; left: 30px; padding: 6px 4px; }
  .results-table .col-rider,
  .results-table .rider-name {
    position: static;
    left: auto;
    min-width: auto;
  }
  /* Shadow on col-no edge instead of rider-name */
  .results-table .rider-name::after,
  .results-table .col-rider::after { display: none; }
  .results-table .col-no::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 0;
    bottom: 0;
    width: 6px;
    background: linear-gradient(to right, rgba(0,0,0,0.2), transparent);
    pointer-events: none;
  }
  .results-table thead .col-rider {  z-index: auto; }
  .results-table tbody tr:nth-child(odd) > .rider-name,
  .results-table tbody tr:nth-child(even) > .rider-name,
  .results-table tbody tr:hover > .rider-name { background: transparent; }
  .pos-badge { width: 22px; height: 22px; font-size: 10px; border-radius: 5px; }
  .rider-number { min-width: 28px; height: 20px; font-size: 10px; }

  .pdf-links-bar { padding: 10px 14px; gap: 6px; }
  .pdf-link { padding: 4px 10px; font-size: 10px; }
  .session-header-pdfs { display: none; }

  .weather-bar { padding: 8px 14px; font-size: 11px; gap: 10px; }

  /* Show bottom PDF bar on mobile since header pdfs are hidden */
  .pdf-links-bar { display: flex !important; }
}

@media (max-width: 480px) {
  .header-logo-text { display: none; }
  .session-badges { display: none; }
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Smooth open/close animations */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- EVENT TOOLBAR --- */
.event-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 12px;
  gap: 8px;
}

/* --- VIEW TOGGLE --- */
.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 3px;
}
.view-toggle-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.view-toggle-btn svg { width: 14px; height: 14px; }
.view-toggle-btn:hover { color: var(--text-primary); }
.view-toggle-btn.active {
  background: var(--accent);
  color: white;
}

/* --- TREE VIEW (FILE BROWSER) --- */
.tree-view {
  max-width: 900px;
  margin: 0 auto;
}
.tree-folder {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
}
.tree-folder-name {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
}
.tree-folder-name svg { width: 14px; height: 14px; transform: rotate(-90deg); }
.tree-folder-files {
  display: flex;
  flex-direction: column;
}
.tree-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 28px;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 12px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}
.tree-file:last-child { border-bottom: none; }
.tree-file:hover { background: var(--bg-card-hover); }
.tree-file svg { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
.tree-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-file .download-count {
  font-size: 10px;
  background: rgba(230,57,70,0.15);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 8px;
  font-weight: 600;
  flex-shrink: 0;
}

/* --- LAPTIMES ICON (in results table) --- */
.laptimes-icon {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-left: 4px;
  cursor: pointer;
  color: var(--info);
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
}
.laptimes-icon:hover { opacity: 1; color: var(--success); }
.laptimes-icon svg { width: 14px; height: 14px; }

/* --- LAPTIMES MODAL --- */
.lt-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.lt-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 820px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 60px rgba(0,0,0,0.6);
}
.lt-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.lt-modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}
.lt-modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}
.lt-modal-close:hover { color: var(--accent); }
.lt-modal-body {
  overflow-y: auto;
  padding: 16px 20px 20px;
  flex: 1;
}

/* Compare bar */
.lt-compare-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.lt-compare-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.lt-compare-select {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 12px;
  padding: 6px 10px;
  max-width: 300px;
}
.lt-compare-select:focus {
  outline: none;
  border-color: var(--info);
}

/* Session block */
.lt-session {
  margin-bottom: 20px;
}
.lt-session-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.lt-session-stats {
  display: flex;
  gap: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.lt-session-stats strong { color: var(--text-primary); }
.lt-best { color: var(--success) !important; font-weight: 700; }

/* Session legend */
.lt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.lt-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.lt-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.lt-legend-compare {
  opacity: 0.7;
  font-style: italic;
}

/* Session cell in unified table */
.lt-session-cell {
  vertical-align: top;
  padding: 8px 10px !important;
  background: rgba(255,255,255,0.02);
}
.lt-session-tag {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 4px;
}
.lt-session-best {
  display: block;
  font-size: 10px;
  color: var(--success);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
}

/* Global best */
.lt-global-best {
  color: var(--success) !important;
  font-weight: 700;
  text-shadow: 0 0 6px rgba(34,197,94,0.4);
}

/* Lap table */
.lt-table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
}
.lt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.lt-table th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
}
.lt-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.lt-table tbody tr:nth-child(odd) { background: rgba(255,255,255,0.02); }
.lt-table tbody tr:hover { background: rgba(59,130,246,0.06); }
.lt-row-best { background: rgba(34,197,94,0.08) !important; }
.lt-row-best:hover { background: rgba(34,197,94,0.14) !important; }
.lt-lap-num {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--text-muted);
  width: 40px;
}
.lt-lap-time {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
}
.lt-lap-diff {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}
.lt-gap-faster { color: var(--success) !important; font-weight: 600; }
.lt-gap-slower { color: var(--accent) !important; }

/* Lap chart */
.lt-chart-wrap {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  margin-top: 8px;
}
.lt-chart-wrap canvas {
  display: block;
  width: 100%;
  border-radius: 4px;
}

.lt-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Mobile */
@media (max-width: 600px) {
  .lt-modal {
    max-height: 92vh;
    border-radius: 12px 12px 0 0;
    margin-top: auto;
  }
  .lt-modal-overlay { padding: 0; align-items: flex-end; }
  .lt-modal-title { font-size: 13px; }
  .lt-modal-body { padding: 10px 10px 16px; }
  .lt-compare-bar { flex-direction: column; align-items: stretch; gap: 6px; }
  .lt-compare-select { max-width: 100%; }
  .lt-legend { gap: 6px 10px; padding: 8px 10px; }
  .lt-legend-item { font-size: 11px; }
  .lt-legend-dot { width: 8px; height: 8px; }
  .lt-table { font-size: 11px; }
  .lt-table th, .lt-table td { padding: 4px 5px; }
  .lt-hide-mobile { display: none; }
  .lt-session-cell { padding: 6px 5px !important; }
  .lt-session-tag { font-size: 10px; }
  .lt-session-best { font-size: 9px; }
  .lt-session-stats { flex-direction: column; gap: 4px; }
  .laptimes-icon svg { width: 12px; height: 12px; }
  .lt-chart-wrap { padding: 4px; }
}
