/* ==========================================================================
   1. GLOBAL RESET & BASE STYLES (Spectator Dark Theme)
   ========================================================================== */
* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter','Roboto', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif, -apple-system, sans-serif;
  background-color: #0b0e14;
  color: #eee;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

#app-container {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  width: 100vw;
  height: calc(100vh - 58px); /* Height minus standard header */
  margin: 0;
  background-color: #0b0e14;
  color: #f0f6fc;
  padding: 0.5rem;
}

h1 { display: none; } /* Kept hidden for maximum vertical HUD space */

/* ==========================================================================
   2. STANDARDIZED APP HEADER & PAGE SWITCHER
   ========================================================================== */
.app-header {
  background-color: #0f172a;
  border-bottom: 1px solid #1e293b;
  padding: 0.6rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  color: #f8fafc;
}

.live-dot {
  width: 10px;
  height: 10px;
  background-color: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 8px #22c55e;
  animation: pulse 2s infinite;
}

.page-switcher {
  display: inline-flex;
  background-color: #1e293b;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid #334155;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #94a3b8;
  text-decoration: none;
  border-radius: 7px;
  transition: all 0.2s ease-in-out;
  white-space: nowrap;
}

.tab-icon {
  width: 15px;
  height: 15px;
}

.nav-tab:hover {
  color: #f8fafc;
  background-color: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  color: #ffffff;
  background-color: #2563eb;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4);
}

/* ==========================================================================
   3. LEADERBOARD CHIPS & SECTION
   ========================================================================== */
#leaderboard-bar {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4em 0.8em;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  margin-bottom: 0.4rem;
  font-size: 0.75vw;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.leaderboard-section h3 {
  margin: 0 0 0.2em 0;
  font-size: 0.85em;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #58a6ff;
}

.lb-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-weight: 700;
  margin: 2px;
  font-size: 0.8em;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.lb-chip.gold { 
  background: linear-gradient(135deg, #f59e0b, #d97706); 
  color: #ffffff; 
}
.lb-chip.silver { 
  background: linear-gradient(135deg, #94a3b8, #64748b); 
  color: #ffffff; 
}
.lb-chip.bronze { 
  background: linear-gradient(135deg, #d97706, #b45309); 
  color: #ffffff; 
}

/* ==========================================================================
   4. RECORDS & LIVE STATUS BAR
   ========================================================================== */
#records-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #161b22;
  border: 1px solid #21262d;
  border-radius: 8px;
  padding: 0.3em 0.8em;
  font-size: 0.75vw;
  margin-bottom: 0.4rem;
  color: #8b949e;
  font-weight: 600;
}

#outright-record {
  color: #e6edf3;
  font-weight: 700;
}

/* ==========================================================================
   5. MAIN TIMING TABLE (Spectator Styled)
   ========================================================================== */
.table-scroll-container {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #30363d;
  border-radius: 10px;
  background-color: #161b22;
}

.timing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75vw; 
  table-layout: auto;
}

/* Header Cells */
.timing-table th {
  background-color: #1e293b;
  color: #fff;
  font-weight: 600;
  /*text-transform: uppercase;*/
  letter-spacing: 0.05em;
  border-bottom: 2px solid #30363d;
  border-right: 1px solid #21262d;
  padding: 6px 8px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Body Cells */
.timing-table td {
  border: 1px solid #21262d;
  padding: 3px 6px;
  white-space: nowrap;
  text-align: center;
  line-height: 1.2;
  font-family: 'Roboto Mono', monospace;
}

/* Driver Name & Vehicle Column Formatting */
.timing-table td:nth-child(2), .timing-table th:nth-child(2),
.timing-table td:nth-child(3), .timing-table th:nth-child(3) {
  text-align: left;
  font-family: 'Inter', sans-serif;
}

/* Driver Number Accent */
.timing-table tbody td:nth-child(1) { 
  color: #58a6ff; 
  font-weight: 800; 
  font-family: 'Inter', sans-serif;
}

/* Class Grouping Row */
tr.class-header-row td.class-header {
  background: #21262d !important;
  color: #ffd700 !important;
  font-size: 0.85vw;
  font-weight: 800;
  text-align: left;
  padding: 5px 10px;
  letter-spacing: 0.03em;
  border-top: 1px solid #30363d;
  border-bottom: 1px solid #30363d;
  font-family: 'Inter', sans-serif;
}

/* Alternating Zebra Rows */
.timing-table tbody tr:nth-child(even):not(.class-header-row) td { 
  background-color: #161b22; 
}
.timing-table tbody tr:nth-child(odd):not(.class-header-row) td { 
  background-color: #0d1117; 
}

/* Hover State for Trackside Usability */
.timing-table tbody tr:hover:not(.class-header-row) td {
  background-color: rgba(56, 139, 253, 0.1) !important;
}

/* ==========================================================================
   6. RECORD PILLS & HIGHLIGHT COLORS
   ========================================================================== */
.record-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 9999px;
  font-size: 0.65vw;
  font-weight: 800;
  margin-left: 4px;
  vertical-align: middle;
  font-family: 'Inter', sans-serif;
}

.record-pill.outright-record, 
.record-pill.class-record {
   background-color: rgba(56, 139, 253, 0.2); 
   color: #58a6ff;
   border: 1px solid rgba(56, 139, 253, 0.4);
}

.record-pill.new-record {
  background-color: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
  animation: flash 1s ease-in-out 2;
}

/* Performance Time Highlights */
.best-run { 
  color: #00ff00 !important; /* Green Personal Best */
  font-weight: 700; 
}
.best-split { 
  color: #00ff00 !important; /* Green Personal Best*/
  font-weight: 700; 
}
.best-ftd { 
  color: #c084fc !important; /* Purple FTD / Sector Best */
  font-weight: 700; 
}

/* Dynamic Live Status Pulse */
.update-icon { 
  width: 8px; 
  height: 8px; 
  border-radius: 50%; 
  display: inline-block; 
  background-color: #22c55e; 
  box-shadow: 0 0 6px #22c55e;
}
.update-text { 
  font-weight: 700; 
  color: #22c55e; 
  font-size: 0.9em; 
}
.pulse .update-icon { 
  animation: pulse 0.8s ease; 
}

@keyframes pulse { 
  0%, 100% { transform: scale(1); opacity: 1; } 
  50% { transform: scale(1.4); opacity: 0.6; } 
}

@keyframes flash { 
  0%, 100% { opacity: 1; } 
  50% { background-color: rgba(245, 158, 11, 0.5); } 
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: stretch;
  }
  .brand-logo {
    justify-content: center;
  }
  .page-switcher {
    width: 100%;
    justify-content: space-between;
  }
  .nav-tab {
    flex: 1;
    justify-content: center;
    padding: 0.4rem 0.2rem;
    font-size: 0.75rem;
  }
  .tab-icon {
    display: none;
  }
  .timing-table {
    font-size: 0.85rem;
  }
  #leaderboard-bar, #records-bar {
    font-size: 0.85rem;
  }
}