/* ============================================
   PORSCHE CARRERA CUP – RACE ENGINEER APP
   Design System & Global Styles
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ── CSS Variables ─────────────────────────── */
:root {
  /* Core Colors */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a26;
  --bg-card: rgba(22, 22, 34, 0.85);
  --bg-card-hover: rgba(30, 30, 46, 0.95);
  --bg-input: rgba(18, 18, 28, 0.9);

  /* Accent Colors - Porsche Motorsport */
  --accent-red: #e2001a;
  --accent-red-glow: rgba(226, 0, 26, 0.3);
  --accent-red-dim: rgba(226, 0, 26, 0.15);
  --accent-gold: #c9a84c;
  --accent-blue: #3a7bfd;
  --accent-cyan: #00d4ff;
  --accent-green: #00d26a;
  --accent-orange: #ff8c00;
  --accent-yellow: #ffd600;
  --accent-purple: #8b5cf6;

  /* Status Colors */
  --status-ok: #00d26a;
  --status-warn: #ffd600;
  --status-danger: #e2001a;
  --status-info: #3a7bfd;

  /* Text Colors */
  --text-primary: #f0f0f5;
  --text-secondary: #8e8ea0;
  --text-tertiary: #55556a;
  --text-accent: var(--accent-red);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(226, 0, 26, 0.3);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-red-glow);

  /* Typography */
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 56px;
}

/* ── Reset & Base ──────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}

/* ── Scrollbar ─────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── App Layout ────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition-normal);
}

.sidebar__header {
  padding: var(--space-lg) var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar__logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sidebar__logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-red), #ff3344);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 900;
  color: white;
  box-shadow: 0 2px 8px var(--accent-red-glow);
}

.sidebar__title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.sidebar__subtitle {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.sidebar__nav {
  flex: 1;
  padding: var(--space-md) var(--space-sm);
  overflow-y: auto;
}

.nav-section {
  margin-bottom: var(--space-lg);
}

.nav-section__title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 0 var(--space-sm);
  margin-bottom: var(--space-xs);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 13px;
  font-weight: 500;
  position: relative;
  user-select: none;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-red-dim);
  color: var(--accent-red);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent-red);
  border-radius: 0 2px 2px 0;
}

.nav-item__icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item__badge {
  margin-left: auto;
  background: var(--accent-red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ── Main Content Area ─────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.main-header {
  height: var(--header-height);
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
}

.main-header__title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.main-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl);
  background: var(--bg-primary);
}

/* ── Cards ─────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  backdrop-filter: blur(10px);
  transition: all var(--transition-normal);
}

.card:hover {
  border-color: var(--border-medium);
  box-shadow: var(--shadow-md);
}

.card--accent {
  border-color: var(--border-accent);
  box-shadow: 0 0 20px rgba(226, 0, 26, 0.05);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.card__title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.card__subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Grid System ───────────────────────────── */
.grid {
  display: grid;
  gap: var(--space-md);
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1200px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Stat Widget ───────────────────────────── */
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat__label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.stat__value {
  font-size: 28px;
  font-weight: 800;
  font-family: var(--font-mono);
  letter-spacing: -1px;
  line-height: 1.1;
}

.stat__unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat--red .stat__value {
  color: var(--accent-red);
}

.stat--green .stat__value {
  color: var(--accent-green);
}

.stat--blue .stat__value {
  color: var(--accent-blue);
}

.stat--gold .stat__value {
  color: var(--accent-gold);
}

.stat--cyan .stat__value {
  color: var(--accent-cyan);
}

/* ── Form Elements ─────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input,
.form-select {
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  outline: none;
  transition: all var(--transition-fast);
  width: 100%;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--accent-red);
  box-shadow: 0 0 0 3px var(--accent-red-dim);
}

.form-input::placeholder {
  color: var(--text-tertiary);
}

.form-hint {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* ── Buttons ───────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
  user-select: none;
  white-space: nowrap;
}

.btn--primary {
  background: linear-gradient(135deg, var(--accent-red), #c7001a);
  color: white;
  box-shadow: 0 2px 8px var(--accent-red-glow);
}

.btn--primary:hover {
  box-shadow: 0 4px 16px var(--accent-red-glow);
  transform: translateY(-1px);
}

.btn--secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
}

.btn--secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn--ghost:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.btn--sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn--lg {
  padding: 14px 28px;
  font-size: 15px;
}

/* ── Tables ────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 13px;
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.data-table .mono {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ── Slider ────────────────────────────────── */
.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--accent-red);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--accent-red-glow);
  transition: transform var(--transition-fast);
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* ── Tabs ──────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: var(--space-lg);
}

.tab {
  flex: 1;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
  border: none;
  background: none;
  font-family: var(--font-main);
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ── Badge / Chip ──────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge--ok {
  background: rgba(0, 210, 106, 0.15);
  color: var(--status-ok);
}

.badge--warn {
  background: rgba(255, 214, 0, 0.15);
  color: var(--status-warn);
}

.badge--danger {
  background: rgba(226, 0, 26, 0.15);
  color: var(--status-danger);
}

.badge--info {
  background: rgba(58, 123, 253, 0.15);
  color: var(--status-info);
}

/* ── Progress Bar ──────────────────────────── */
.progress {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  border-radius: 3px;
  transition: width var(--transition-slow);
}

.progress__bar--ok {
  background: linear-gradient(90deg, var(--status-ok), #00ff7f);
}

.progress__bar--warn {
  background: linear-gradient(90deg, var(--status-warn), #ffeb3b);
}

.progress__bar--danger {
  background: linear-gradient(90deg, var(--status-danger), #ff4444);
}

/* ── Toggle / Switch ───────────────────────── */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle input {
  display: none;
}

.toggle__slider {
  position: absolute;
  inset: 0;
  background: var(--bg-tertiary);
  border-radius: 12px;
  transition: var(--transition-fast);
}

.toggle__slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: var(--transition-fast);
}

.toggle input:checked+.toggle__slider {
  background: var(--accent-red);
}

.toggle input:checked+.toggle__slider::before {
  transform: translateX(20px);
  background: white;
}

/* ── Tooltip ───────────────────────────────── */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-md);
  z-index: 1000;
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ── Utility Classes ───────────────────────── */
.text-mono {
  font-family: var(--font-mono);
}

.text-red {
  color: var(--accent-red);
}

.text-green {
  color: var(--accent-green);
}

.text-blue {
  color: var(--accent-blue);
}

.text-gold {
  color: var(--accent-gold);
}

.text-muted {
  color: var(--text-secondary);
}

.text-dim {
  color: var(--text-tertiary);
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.text-sm {
  font-size: 12px;
}

.text-xs {
  font-size: 11px;
}

.text-lg {
  font-size: 16px;
}

.text-xl {
  font-size: 20px;
}

.fw-bold {
  font-weight: 700;
}

.fw-black {
  font-weight: 900;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-xs {
  gap: var(--space-xs);
}

.gap-sm {
  gap: var(--space-sm);
}

.gap-md {
  gap: var(--space-md);
}

.gap-lg {
  gap: var(--space-lg);
}

.mt-sm {
  margin-top: var(--space-sm);
}

.mt-md {
  margin-top: var(--space-md);
}

.mt-lg {
  margin-top: var(--space-lg);
}

.mb-sm {
  margin-bottom: var(--space-sm);
}

.mb-md {
  margin-bottom: var(--space-md);
}

.mb-lg {
  margin-bottom: var(--space-lg);
}

.hidden {
  display: none !important;
}

/* ── Module Container ──────────────────────── */
.module {
  display: none;
  animation: fadeIn 0.3s ease;
}

.module.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* ── Checkbox for Checklists ───────────────── */
.checklist-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  user-select: none;
}

.checklist-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.checklist-item input[type="checkbox"] {
  display: none;
}

.checklist-item__check {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-medium);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
  font-size: 12px;
  color: transparent;
}

.checklist-item input:checked+.checklist-item__check {
  background: var(--accent-green);
  border-color: var(--accent-green);
  color: white;
}

.checklist-item__text {
  font-size: 13px;
  transition: color var(--transition-fast);
}

.checklist-item input:checked~.checklist-item__text {
  color: var(--text-tertiary);
  text-decoration: line-through;
}

/* ── Divider ───────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-md) 0;
}

/* ── Setup Parameter Row ───────────────────── */
.param-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.param-row:last-child {
  border-bottom: none;
}

.param-row__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  flex: 1;
}

.param-row__value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 80px;
  text-align: right;
}

.param-row__unit {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: 4px;
  font-weight: 400;
}

.param-row__input {
  width: 100px;
}

/* ── Warning Box ───────────────────────────── */
.warning-box {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: rgba(226, 0, 26, 0.08);
  border: 1px solid rgba(226, 0, 26, 0.2);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-primary);
}

.warning-box--info {
  background: rgba(58, 123, 253, 0.08);
  border-color: rgba(58, 123, 253, 0.2);
}

.warning-box--ok {
  background: rgba(0, 210, 106, 0.08);
  border-color: rgba(0, 210, 106, 0.2);
}

/* ── Chart Container ───────────────────────── */
.chart-container {
  position: relative;
  width: 100%;
  height: 300px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Inline Value Display ──────────────────── */
.value-display {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.value-display__number {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 800;
}

.value-display__unit {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Setup Comparison ──────────────────────── */
.compare-cell {
  font-family: var(--font-mono);
}

.compare-cell--better {
  color: var(--accent-green);
}

.compare-cell--worse {
  color: var(--accent-red);
}

.compare-cell--same {
  color: var(--text-tertiary);
}

/* ── Print Styles ──────────────────────────── */
@media print {

  .sidebar,
  .main-header,
  .btn,
  .btn--ghost,
  .tabs,
  .warning-box--info,
  #sess-fb-category,
  #sess-fb-option,
  #sess-fb-severity,
  #sess-fb-corner,
  #fuel-history-link,
  .card__header button,
  .no-print {
    display: none !important;
  }

  body,
  .app,
  .main-content,
  .content-area {
    background: white !important;
    color: black !important;
    height: auto !important;
    overflow: visible !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .card {
    background: white !important;
    border: 1px solid #ddd !important;
    box-shadow: none !important;
    break-inside: avoid;
    margin-bottom: 20px !important;
    backdrop-filter: none !important;
    color: black !important;
  }

  .text-muted,
  .text-dim,
  .stat__label,
  .form-label {
    color: #666 !important;
  }

  .badge {
    border: 1px solid #ccc !important;
    background: transparent !important;
    color: black !important;
  }

  .badge--ok {
    border-color: var(--status-ok) !important;
    color: var(--status-ok) !important;
  }

  .badge--warn {
    border-color: var(--status-warn) !important;
    color: var(--status-warn) !important;
  }

  .badge--danger {
    border-color: var(--status-danger) !important;
    color: var(--status-danger) !important;
  }

  h1,
  h2,
  h3,
  h4,
  .card__title {
    color: black !important;
  }

  .data-table th {
    color: #333 !important;
    border-bottom: 2px solid #333 !important;
  }

  .data-table td {
    border-bottom: 1px solid #eee !important;
  }

  /* Force visibility for specific results */
  #suggestions-content,
  #rebuild-result,
  #fuel-results,
  #sess-history-list {
    display: block !important;
  }
}