/* trafficjam.css - Enhanced version with header/footer integration */

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body.dark-mode {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --border-color: #334155;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============= Z-INDEX FIX FOR HEADER/FOOTER ============= */
#header-container,
header[data-dropdown-delay] {
  position: relative;
  z-index: 9999 !important;
}

main {
  position: relative;
  z-index: 1;
  min-height: 60vh;
}

#footer-container {
  position: relative;
  z-index: 1;
}

/* ============= CONTAINER ============= */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

/* ============= PAGE HEADER (not site header) ============= */
.page-header {
  text-align: center;
  padding: 2rem 0;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 2rem;
}

.h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.025em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

.h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ============= CARDS ============= */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

/* ============= PIXI CONTAINER ============= */
#pixiContainer {
  position: relative;
  width: 100%;
  max-width: 800px;
  margin: 0 auto 1rem;
  background: var(--bg-secondary);
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

#pixiContainer canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 0.75rem;
}

/* ============= LOADING OVERLAY ============= */
#loadingOverlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: opacity 0.3s;
  border-radius: 0.75rem;
}

/* ============= LÉGENDE ============= */
.legend {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  margin: 1rem auto;
  max-width: 800px;
}

.legend-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.legend-items {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.legend-color {
  width: 28px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

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

/* Legend color classes */
.legend-color-emergency { background: #ef4444; }
.legend-color-heavy { background: #f97316; }
.legend-color-light { background: #fbbf24; }
.legend-color-normal { background: #22c55e; }
.legend-color-accel { background: #60a5fa; }

/* ============= CONTROLS ============= */
.controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.btn {
  padding: 0.625rem 1.25rem;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--text-secondary);
}

.btn-success {
  background: var(--success);
}

.btn-warning {
  background: var(--warning);
}

/* ============= GRID ============= */
.grid {
  display: grid;
  gap: 1rem;
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* ============= METRICS ============= */
.metric {
  padding: 1rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  transition: border-color 0.2s;
}

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

.label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.value .small {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 0.25rem;
}

/* ============= INPUTS ============= */
.input {
  width: 100%;
  padding: 0.625rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Range sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  outline: none;
  padding: 0;
  transition: background 0.2s;
}

input[type="range"]:hover {
  background: var(--text-secondary);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent-color);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent-color);
  border-radius: 50%;
  cursor: pointer;
  border: none;
  transition: transform 0.2s;
}

input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.1);
}

select.input {
  cursor: pointer;
}

/* ============= TOOLTIPS ============= */
.tooltip {
  position: relative;
  display: inline-flex;
  cursor: help;
  margin-left: 0.25rem;
}

.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--text-secondary);
  color: white;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
}

.tooltip-text {
  visibility: hidden;
  position: absolute;
  z-index: 100;
  background: #1e293b;
  color: white;
  text-align: left;
  padding: 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  line-height: 1.4;
  width: 250px;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.tooltip:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

.tooltip-text::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #1e293b transparent transparent transparent;
}

body.dark-mode .tooltip-text {
  background: #334155;
}

body.dark-mode .tooltip-text::after {
  border-color: #334155 transparent transparent transparent;
}

/* ============= SCENARIO INFO BOX ============= */
.scenario-info {
  background: #eff6ff;
  border-left: 4px solid var(--accent-color);
  padding: 1rem;
  margin-bottom: 1rem;
  border-radius: 0.5rem;
  display: none;
}

.scenario-info.active {
  display: block;
}

.scenario-info-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #1e40af;
}

.scenario-info-text {
  font-size: 0.9rem;
  color: #1e40af;
  line-height: 1.6;
}

body.dark-mode .scenario-info {
  background: #1e3a5f;
  border-left-color: var(--accent-color);
}

body.dark-mode .scenario-info-title,
body.dark-mode .scenario-info-text {
  color: #93c5fd;
}

/* ============= CHARTS ============= */
.chart-container {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

.chart-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

canvas.chart {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 0.25rem;
}

/* ============= TUTORIAL OVERLAY ============= */
.tutorial-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1rem;
}

.tutorial-overlay.active {
  display: flex;
}

.tutorial-box {
  background: var(--bg-primary);
  border-radius: 1rem;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: tutorialSlideIn 0.3s ease-out;
}

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

.tutorial-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.tutorial-content {
  margin-bottom: 1.5rem;
  line-height: 1.8;
  color: var(--text-primary);
}

.tutorial-progress {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.tutorial-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ============= HELP BUTTON ============= */
.help-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 60px;
  height: 60px;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  transition: all 0.3s;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.5);
  background: var(--accent-hover);
}

.help-btn:active {
  transform: scale(1.05);
}

/* ============= FLEX UTILITIES ============= */
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

/* ============= HIDDEN ============= */
.hidden {
  display: none !important;
}

/* ============= CANVAS ============= */
canvas {
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background: var(--bg-primary);
  max-width: 100%;
  height: auto;
  display: block;
  margin-bottom: 1rem;
}

/* ============= PROGRESS BAR ============= */
.progress {
  width: 100%;
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.progress-bar {
  height: 100%;
  background: var(--accent-color);
  transition: width 0.3s ease;
  width: 0%;
  border-radius: 4px;
}

/* ============= NOTES ============= */
.note {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  font-style: italic;
  line-height: 1.5;
}

/* ============= ERROR STYLES ============= */
.error-message {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.btn-error-reload {
  margin-top: 1rem;
}

/* ============= SCREEN READER ONLY ============= */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ============= RESPONSIVE ============= */
@media (max-width: 768px) {
  .h1 {
    font-size: 1.5rem;
  }
  
  .h2 {
    font-size: 1.25rem;
  }
  
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  
  .controls {
    flex-direction: column;
  }
  
  .btn {
    width: 100%;
  }
  
  .container {
    padding: 0.75rem;
  }
  
  .card {
    padding: 1rem;
  }
  
  .page-header {
    padding: 1.5rem 0;
  }
  
  .legend-items {
    grid-template-columns: 1fr;
  }
  
  .tooltip-text {
    width: 200px;
    left: auto;
    right: 0;
    transform: none;
  }
  
  .help-btn {
    bottom: 1rem;
    right: 1rem;
    width: 50px;
    height: 50px;
    font-size: 1.25rem;
  }
  
  .tutorial-box {
    padding: 1.5rem;
    margin: 1rem;
  }
  
  .tutorial-title {
    font-size: 1.25rem;
  }
}

@media (max-width: 480px) {
  .h1 {
    font-size: 1.25rem;
  }
  
  .value {
    font-size: 1.25rem;
  }
  
  canvas {
    border-radius: 0.375rem;
  }
  
  .legend {
    padding: 0.75rem;
  }
  
  .legend-label {
    font-size: 0.75rem;
  }
  
  .tutorial-box {
    padding: 1rem;
  }
}

/* ============= PRINT STYLES ============= */
@media print {
  body {
    background: white;
    color: black;
  }
  
  #header-container,
  #footer-container,
  .btn,
  .controls,
  .help-btn,
  .tutorial-overlay {
    display: none !important;
  }
  
  .card {
    border: 1px solid #ddd;
    box-shadow: none;
    page-break-inside: avoid;
  }
  
  .legend {
    border: 1px solid #ddd;
  }
  
  .tooltip-text {
    display: none !important;
  }
}