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

/* Плавный скролл: программные скроллы (возврат к началу при смене
   страницы в app.js) идут плавно, а не рывком. */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
  position: relative;
}

/* Soft ambient glow behind glass panels */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(600px 400px at 12% 8%, var(--glow-a), transparent 65%),
    radial-gradient(700px 500px at 88% 18%, var(--glow-b), transparent 65%),
    radial-gradient(800px 600px at 50% 100%, var(--glow-c), transparent 70%);
  filter: blur(60px);
  transition: background 0.3s;
}

/* B2: переходы между страницами — fade+slide контейнера #app при navigate. */
#app.page-enter {
  animation: pageEnter 0.18s ease-out;
}

#app.page-leave {
  animation: pageLeave 0.12s ease-in forwards;
}

@keyframes pageEnter {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pageLeave {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
  #app.page-enter,
  #app.page-leave {
    animation: none;
  }
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.header {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  margin: 0 auto;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
  font-style: italic;
}

.logo span {
  color: var(--text-primary);
}

/* Navigation */
.nav {
  display: flex;
  gap: 2px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar {
  display: none;
}

.nav-link {
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent);
  color: white;
}

/* Theme Toggle */
.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-primary);
  transition: all 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* Main Content */
main {
  padding: 0; /* оболочка: паддинги задаёт apex.css (сайдбар-раскладка) */
  max-width: none;
  margin: 0;
  overflow-x: hidden;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 10px;
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.2s;
  position: relative;
  overflow: visible;
  contain: layout style;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

a.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 20px var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 7fr 13fr;
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

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

@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  
  .nav {
    display: none;
  }
  
  .nav.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--nav-bg);
    padding: 10px;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
  
  .menu-toggle {
    display: block;
  }
}

/* Stat Box */
.stat-box {
  text-align: center;
  padding: 20px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Tables */
/* Table scroll performance */
.table-wrapper {
  overflow-x: hidden;
  max-height: 615px;
  overflow-y: auto;
  will-change: scroll-position;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}

.table-wrapper table {
  background: transparent;
}

.table-wrapper thead th {
  background: rgba(51, 50, 69, 0.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.position {
  font-weight: 700;
  width: 64px;
  min-width: 64px;
  text-align: center;
  white-space: nowrap;
}

.position-1 { color: #ffd700; }
.position-2 { color: #c0c0c0; }
.position-3 { color: #cd7f32; }

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

.driver-name a:hover {
  opacity: 0.7;
  text-decoration: underline;
}

td a:hover {
  opacity: 0.7;
  text-decoration: underline;
}

.team-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.points {
  font-weight: 600;
  color: var(--text-primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

/* Select */
.select {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}

.select:focus {
  outline: none;
  border-color: var(--accent);
}

.select option {
  background: #333246;
  color: var(--text-primary);
}

/* F1 Skeleton Loading */
.skeleton-box {
  min-height: 100px;
  position: relative;
  overflow: hidden;
  background: var(--bg-secondary);
  border-radius: 8px;
}

/* F1 Start Lights */
.f1-lights-inline {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  padding: 20px 0 12px;
}
.f1-light-inline {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1a0a0a;
  border: 2px solid #333;
}
.f1-light-inline.on {
  background: #e10600;
  box-shadow: 0 0 12px #e10600, 0 0 24px rgba(225,6,0,0.4);
  border-color: #ff3333;
}

/* F1 Mini Track */
.f1-track-inline {
  width: 60%;
  max-width: 260px;
  height: 28px;
  margin: 8px auto;
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  background: linear-gradient(180deg, #111 0%, #1a1a1a 40%, #222 100%);
  border: 1px solid #333;
}
.f1-track-inline::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: repeating-linear-gradient(90deg, #444 0px, #444 10px, transparent 10px, transparent 16px);
  transform: translateY(-50%);
  opacity: 0.4;
}
.f1-car-inline {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: -30px;
  animation: f1-car-drive 1.8s ease-in-out infinite;
  will-change: left;
}
.f1-car-inline svg {
  width: 28px;
  height: 13px;
  filter: drop-shadow(0 0 4px rgba(225,6,0,0.5));
}
@keyframes f1-car-drive {
  0% { left: -30px; }
  50% { left: calc(100% + 30px); }
  50.01% { left: -30px; }
  100% { left: calc(100% + 30px); }
}

/* F1 Loading Text Inline */
.f1-loading-inline {
  text-align: center;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 600;
  padding-bottom: 16px;
}

/* Skeleton Loading (legacy) */
.skeleton {
  background: var(--skeleton);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 16px;
  margin-bottom: 8px;
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: 12px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 20px;
  box-shadow: 0 4px 20px var(--shadow);
  animation: slideIn 0.3s ease;
  max-width: 300px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.toast.error {
  border-color: var(--accent);
}

.toast.success {
  border-color: #00c853;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Driver Card */
.driver-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.driver-number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  opacity: 0.5;
}

.driver-info {
  flex: 1;
}

.driver-info h3 {
  font-size: 1.1rem;
  margin-bottom: 2px;
}

.driver-info p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Race Card */
.race-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.race-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  border-color: #e10600 !important;
}

.race-date {
  text-align: center;
  min-width: 60px;
}

.race-date .day {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.race-date .month {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.race-info {
  flex: 1;
}

.race-info h3 {
  font-size: 1rem;
  margin-bottom: 2px;
}

.race-info p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.race-status {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.race-status.completed {
  background: rgba(0, 200, 83, 0.2);
  color: #00c853;
}

.race-status.upcoming {
  background: rgba(225, 6, 0, 0.2);
  color: var(--accent);
}

.race-status.cancelled {
  background: rgba(128, 128, 128, 0.2);
  color: #888;
}

/* Chart Container */
.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Hero Section */
.hero {
  text-align: center;
  padding: 40px 0;
  margin-bottom: 30px;
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.hero h1 span {
  color: var(--accent);
}

.hero p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
}

/* Footer */
.footer {
  text-align: center;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 0;
}

/* Page Header */
.page-header {
  margin-bottom: 30px;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.page-header p {
  color: var(--text-secondary);
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--text-primary);
}

/* B4: информативные пустые состояния — иконка, причина, действие. */
.empty-state .empty-icon {
  display: inline-block;
  opacity: 0.45;
  margin-bottom: 10px;
}

.empty-state .empty-hint {
  font-size: 0.85rem;
  opacity: 0.75;
  max-width: 420px;
  margin: 4px auto 14px;
  line-height: 1.5;
}

.empty-state .empty-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.empty-state .empty-action:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px var(--shadow);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Menu Toggle (mobile) */
.menu-toggle {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-primary);
}

@media (max-width: 600px) {
  .menu-toggle {
    display: block;
  }
}

[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: fixed;
  left: var(--tx, 50%);
  top: var(--ty, 0);
  transform: translateX(-50%) translateY(-100%);
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #f1f5f9;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.2);
  z-index: 10000;
  letter-spacing: 0.3px;
}

[data-tooltip]:hover::after {
  opacity: 1;
}

[data-tooltip]::before {
  content: '';
  position: fixed;
  left: var(--tx, 50%);
  top: var(--ty, 0);
  transform: translateX(-50%) translateY(-100%);
  border: 5px solid transparent;
  border-bottom-color: #0f172a;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10000;
}

[data-tooltip]:hover::before {
  opacity: 1;
}

[data-tooltip]:hover::after {
  opacity: 1;
}

.sprint-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: #3671C6;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
}

.text-right { text-align: right; }
.text-center { text-align: center; }

.status-badge {
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: default;
  transition: filter 0.15s ease, box-shadow 0.15s ease;
}
.status-badge:hover {
  filter: brightness(0.8);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.status-badge.dnf { background: rgba(239,68,68,0.2); color: #ef4444; }
.status-badge.dns { background: rgba(245,158,11,0.2); color: #f59e0b; }
.status-badge.dsq { background: rgba(168,85,247,0.2); color: #a855f7; }

.pill-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 12px 7px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#results-page .pill-select {
  background: transparent;
  border: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  position: relative;
  z-index: 10;
}

#results-page .custom-select-trigger {
  border: none;
  background: transparent;
  height: auto;
  padding: 2px 10px;
}

.session-tab {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  background: transparent;
  color: var(--text-secondary);
}
.session-tab:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}
.session-tab.active {
  background: var(--accent);
  color: #fff;
}
.session-tab.active:hover {
  background: var(--accent-hover);
}
.pill-select select {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-right: 4px;
}
.custom-select-trigger {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  transition: border-color 0.2s;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.race-status.live {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.bg-fastest {
  background: rgba(255, 200, 0, 0.18);
  box-shadow: inset 0 0 14px rgba(255, 215, 0, 0.3), 0 0 10px rgba(255, 215, 0, 0.2);
  transition: background 0.2s, box-shadow 0.2s;
}
.bg-fastest:hover {
  background: rgba(255, 215, 0, 0.3);
  box-shadow: inset 0 0 20px rgba(255, 215, 0, 0.5), 0 0 18px rgba(255, 215, 0, 0.4);
}

.sortable-col {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
  white-space: nowrap;
}
.sortable-col:hover {
  color: var(--accent);
}

#cal-dots-grid .cal-dot img {
  filter: brightness(1.8) saturate(1.3) contrast(1.1);
}

[data-tip] {
  position: relative;
  cursor: help;
}
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: rgba(15, 15, 30, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 10000;
}
[data-tip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
[data-tip-pos="right"]::after {
  bottom: auto;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
}
[data-tip-pos="right"]:hover::after {
  transform: translateY(-50%) translateX(0);
}

/* Многострочный вариант data-tip: attr() даёт простой текст, поэтому
   переносы строк из i18n (\n) рендерим через pre-line, а не <br>. */
[data-tip-multiline]::after {
  white-space: pre-line;
  width: max-content;
  max-width: 280px;
  line-height: 1.5;
  text-align: left;
}

