@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;800&family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Color System */
  --bg-primary: hsl(230, 20%, 6%);
  --bg-secondary: hsl(230, 15%, 10%);
  --bg-card: hsla(230, 15%, 12%, 0.6);
  --bg-card-hover: hsla(230, 15%, 16%, 0.7);
  --border-color: hsla(230, 15%, 25%, 0.3);
  --border-glow: hsla(262, 83%, 58%, 0.15);

  /* Accent Colors */
  --accent-primary: hsl(262, 83%, 58%); /* Electric Purple */
  --accent-primary-glow: hsla(262, 83%, 58%, 0.3);
  --accent-secondary: hsl(188, 86%, 53%); /* Neon Teal */
  --accent-secondary-glow: hsla(188, 86%, 53%, 0.3);

  /* Status Colors */
  --color-success: hsl(142, 72%, 45%); /* Emerald Green (PB) */
  --color-success-glow: hsla(142, 72%, 45%, 0.2);
  --color-warning: hsl(38, 92%, 50%); /* Amber Yellow (Leader/Fastest) */
  --color-warning-glow: hsla(38, 92%, 50%, 0.2);
  --color-error: hsl(0, 84%, 60%); /* Coral Red */
  --color-error-glow: hsla(0, 84%, 60%, 0.2);

  /* Text Colors */
  --text-primary: hsl(0, 0%, 96%);
  --text-secondary: hsl(230, 12%, 70%);
  --text-muted: hsl(230, 10%, 50%);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px var(--accent-primary-glow);
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family:
    'Outfit',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  background-image:
    radial-gradient(at 0% 0%, hsla(262, 80%, 20%, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, hsla(188, 80%, 20%, 0.1) 0px, transparent 50%);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-secondary);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* Typography Helpers */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* Layout Utilities */
.container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  overflow: hidden;
}

/* Glassmorphic Components */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  transition:
    transform var(--transition-normal),
    border-color var(--transition-normal),
    box-shadow var(--transition-normal);
}

.card:hover {
  border-color: hsla(262, 83%, 58%, 0.3);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.7),
    0 0 24px hsla(262, 83%, 58%, 0.08);
}

.glass-panel {
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Input & Button Design */
input,
select,
button {
  font-family: inherit;
  font-size: 0.95rem;
}

input[type='text'],
input[type='number'],
select {
  background: hsla(230, 15%, 6%, 0.7);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  outline: none;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

input[type='text']:focus,
input[type='number']:focus,
select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-primary-glow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), hsl(262, 83%, 45%));
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-primary-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow:
    0 6px 16px var(--accent-primary-glow),
    0 0 12px var(--accent-primary);
}

.btn-secondary {
  background: var(--bg-secondary);
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-success {
  background: linear-gradient(135deg, var(--color-success), hsl(142, 72%, 35%));
  color: #fff;
  box-shadow: 0 4px 12px var(--color-success-glow);
}
.btn-success:hover {
  transform: translateY(-1px);
  box-shadow:
    0 6px 16px var(--color-success-glow),
    0 0 12px var(--color-success);
}

.btn-danger {
  background: linear-gradient(135deg, var(--color-error), hsl(0, 84%, 50%));
  color: #fff;
  box-shadow: 0 4px 12px var(--color-error-glow);
}
.btn-danger:hover {
  transform: translateY(-1px);
  box-shadow:
    0 6px 16px var(--color-error-glow),
    0 0 12px var(--color-error);
}

/* Connection Badges */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

.status-indicator.connected .status-dot {
  background-color: var(--color-success);
  box-shadow: 0 0 8px var(--color-success);
  animation: pulse 2s infinite;
}

.status-indicator.disconnected .status-dot {
  background-color: var(--color-error);
  box-shadow: 0 0 8px var(--color-error);
}

/* Animations */
@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.25);
    opacity: 0.5;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes pulse-fade {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
  100% {
    opacity: 1;
  }
}

/* App Header & Structure */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.5rem;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.logo-text h1 {
  font-size: 1.5rem;
  background: linear-gradient(to right, #fff, var(--text-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text span {
  font-size: 0.75rem;
  color: var(--accent-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Grid Layout */
.app-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 1.5rem;
  overflow: hidden;
}

@media (max-width: 1024px) {
  .app-grid {
    grid-template-columns: 1fr;
  }
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-tab {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

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

.nav-tab.active {
  background: linear-gradient(135deg, hsla(262, 83%, 58%, 0.15), transparent);
  border-color: var(--accent-primary);
  color: var(--text-primary);
  box-shadow: 0 0 16px var(--accent-primary-glow) inset;
}

.views-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow: hidden;
}

/* Sidebar Tree Navigation */
.nav-tree {
  display: flex;
  flex-direction: column;
}

.tree-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tree-header .chevron {
  font-size: 0.75rem;
  transition: transform var(--transition-fast);
}

.tree-header.collapsed .chevron {
  transform: rotate(-90deg);
}

.tree-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem 0 0.5rem 1.5rem;
  border-left: 1px solid var(--border-color);
  margin-left: 1rem;
}

.tree-content.collapsed {
  display: none;
}

.tree-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tree-list li {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.tree-list li:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.tree-list li.active {
  background: hsla(262, 83%, 58%, 0.1);
  color: var(--text-primary);
  font-weight: 600;
  border-left: 2px solid var(--accent-primary);
}

.nav-action-btn {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  padding: 0.4rem;
  text-align: center;
}

/* Danger Zone */
.danger-zone {
  margin-top: 2rem;
  padding: 1.5rem;
  border: 1px solid var(--color-error-glow);
  border-radius: var(--radius-md);
  background: hsla(0, 84%, 60%, 0.05);
}

.view-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
}
.view-panel.active {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Settings Form elements */
.form-group {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Leaderboard Board */
.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.session-timer {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent-secondary);
  background: hsla(188, 86%, 53%, 0.05);
  border: 1px solid hsla(188, 86%, 53%, 0.2);
  padding: 0.25rem 1rem;
  border-radius: var(--radius-sm);
}

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

.leaderboard-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 10;
}

.leaderboard-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.95rem;
  transition: background var(--transition-fast);
}

.leaderboard-row {
  transition: transform var(--transition-normal);
}
.leaderboard-row:hover td {
  background: var(--bg-card-hover);
}

.leaderboard-row.position-1 {
  background: linear-gradient(90deg, hsla(38, 92%, 50%, 0.03), transparent);
}
.leaderboard-row.position-1 td {
  border-bottom: 1px solid hsla(38, 92%, 50%, 0.15);
}

.pos-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 0.85rem;
  background: var(--bg-secondary);
}

.position-1 .pos-badge {
  background: var(--color-warning);
  color: var(--bg-primary);
  box-shadow: 0 0 10px var(--color-warning-glow);
}

/* Lap colors (green for PB, gold for overall fastest) */
.lap-time-badge {
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.lap-time-badge.driver-session-best {
  background: var(--color-success-glow);
  color: var(--color-success);
  border: 1px solid var(--color-success);
}
.lap-time-badge.overall-best {
  background: var(--color-warning-glow);
  color: var(--color-warning);
  border: 1px solid var(--color-warning);
}

/* Alert notifications for unregistered transponders */
.notification-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  z-index: 10000;
}

.notification {
  background: var(--bg-secondary);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 1rem;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.speech-toast {
  background: rgba(15, 15, 20, 0.9);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border-left: 3px solid var(--accent-secondary);
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

@keyframes slideInRight {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}
