/* ==========================================================================
   STYLE: WORKBENCH UNIFIÉ (SIMULATIONS 03, 04, 05, 06, 07)
   Direction Artistique: Zero-Slop Institutional Workbench (Linear / TradingView)
   Mobile-First Lock: 100% Viewport Width, Zero Horizontal Overflow, Clean Navbar
   ========================================================================== */

:root {
  --bg-primary: #070b12;
  --bg-surface: #0c121d;
  --bg-panel: #111a29;
  --bg-elevated: #182236;

  --border-subtle: #1a2538;
  --border-focus: #22c55e;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-green: #22c55e;
  --accent-green-glow: rgba(34, 197, 94, 0.25);
  --accent-pink: #f43f5e;
  --accent-blue: #38bdf8;
  --accent-jungle: #22c55e;
  --accent-lava: #ef4444;
  --accent-ice: #38bdf8;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* --- HEADER BARRE SUPÉRIEURE (DESKTOP) --- */
.workbench-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 50px;
  width: 100%;
  max-width: 100vw;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 1;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.back-link:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.sim-title {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sim-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background-color: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(34, 197, 94, 0.3);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.btn-group {
  display: inline-flex;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-panel);
  max-width: 100%;
}

.speed-btn, .biome-btn, .epoch-btn, .ai-mode-btn, .brain-btn, .gen-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.speed-btn:hover, .biome-btn:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.speed-btn.active {
  background: var(--accent-green);
  color: #052e16;
  font-weight: 700;
}

.biome-btn.active {
  background: var(--accent-ice);
  color: #031422;
  font-weight: 700;
}

.btn-action {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  color: var(--text-primary);
  white-space: nowrap;
  transition: all 0.15s ease;
}

.btn-action:hover {
  background: var(--bg-elevated);
  border-color: var(--text-muted);
}

.btn-primary {
  background: var(--accent-green);
  color: #052e16;
  border-color: var(--accent-green);
  font-weight: 600;
}

.btn-primary:hover {
  background: #16a34a;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.jump-group {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

.jump-input {
  width: 46px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 5px;
  text-align: center;
}

.jump-input:focus {
  outline: none;
  border-color: var(--accent-green);
}

/* --- MAIN WORKBENCH LAYOUT --- */
.workbench-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  height: calc(100vh - 50px);
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

/* --- COLONNE GAUCHE : VIEWPORT CANVAS --- */
.viewport-panel {
  position: relative;
  background-color: #040806;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border-subtle);
  min-width: 0;
  width: 100%;
}

.canvas-container {
  flex: 1;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#simCanvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Télémétrie HUD superposée sur le Canvas */
.hud-telemetry {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(12, 18, 29, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  padding: 5px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
}

.hud-pill .label {
  color: var(--text-muted);
}

.hud-pill .val {
  font-weight: 700;
  color: var(--accent-green);
}

/* Contrôle d'adhérence des 4 ventouses & HUD environnement */
.hud-grips, .hud-env {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  width: fit-content;
  max-width: calc(100% - 20px);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  background: rgba(12, 18, 29, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  padding: 5px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
}

.hud-env-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.hud-env-item .val {
  font-weight: 700;
  color: var(--text-primary);
}

.grip-label {
  color: var(--text-muted);
  margin-right: 2px;
}

.grip-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  transition: all 0.1s ease;
}

.grip-indicator.active {
  background: rgba(34, 197, 94, 0.2);
  border-color: var(--accent-green);
  color: var(--accent-green);
  font-weight: 700;
}

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

.grip-indicator.active .grip-dot {
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
}

/* --- COLONNE DROITE : SIDEBAR DOCKÉE --- */
.sidebar-panel {
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  border-left: 1px solid var(--border-subtle);
  min-width: 0;
  width: 100%;
}

.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.section-title {
  font-size: 11px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 8px 10px;
  min-width: 0;
}

.metric-card .metric-header {
  font-size: 9.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-card .metric-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-card.accent-green .metric-value {
  color: var(--accent-green);
}

/* Graphiques Chart.js */
.chart-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 8px;
  height: 155px;
  position: relative;
  width: 100%;
}

.chart-box.radar-box {
  height: 140px;
}

/* Chapitres Histoire */
.story-chapters {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.story-chapter-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.story-chapter-card:hover {
  background: var(--bg-elevated);
  border-color: var(--text-muted);
}

.story-chapter-card.active {
  border-color: var(--accent-green);
  background: rgba(34, 197, 94, 0.08);
}

.story-chapter-card .chapter-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.story-chapter-card .chapter-desc {
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.35;
}

/* ==========================================================================
   MOBILE & TABLET RESPONSIVE (LOCKED 100% WIDTH, CLEAN 2-ROW NAVBAR)
   ========================================================================== */
@media (max-width: 1024px) {
  .workbench-header {
    flex-wrap: wrap;
    height: auto;
    padding: 7px 10px;
    gap: 6px;
  }

  /* Ligne 1 : Bouton HUB + Titre à gauche, Saut/Action à droite */
  .header-left {
    order: 1;
    flex: 1 1 0%;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
  }

  .sim-title {
    font-size: 12.5px;
    min-width: 0;
    overflow: hidden;
  }

  .sim-title span:first-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Masquer le sous-badge long dans la navbar mobile pour éviter tout débordement */
  .workbench-header .sim-tag {
    display: none;
  }

  .header-right {
    order: 2;
    flex: 0 0 auto;
    gap: 4px;
  }

  .header-right .btn-action,
  .jump-group .btn-action {
    padding: 3px 6px;
    font-size: 10px;
  }

  .jump-group {
    font-size: 10px;
    gap: 3px;
    padding: 2px 5px;
  }

  .jump-input {
    width: 34px;
    padding: 2px 3px;
    font-size: 10px;
  }

  /* Ligne 2 : Barre de contrôle horizontale unique (100% largeur, sans retour à la ligne parasite) */
  .header-center {
    order: 3;
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
  .header-center::-webkit-scrollbar {
    display: none;
  }

  .header-center .btn-group {
    display: inline-flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    overflow: visible;
  }

  .speed-btn, .biome-btn, .epoch-btn, .ai-mode-btn, .brain-btn, .gen-btn {
    font-size: 10px;
    padding: 4px 6px;
    flex-shrink: 0;
  }

  .header-center .btn-action {
    font-size: 10px;
    padding: 4px 7px;
    flex-shrink: 0;
  }

  /* Grille principale empilée 100% largeur + Scroll vertical 100% libre */
  .workbench-main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    height: auto;
    overflow: visible;
  }

  .viewport-panel {
    height: 40vh;
    min-height: 235px;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .canvas-container,
  #simCanvas {
    touch-action: pan-y pinch-zoom !important;
  }

  /* Sidebar Mobile : Grille 2 colonnes (KPIs ultra-compacts + 2 Graphes côte à côte par ligne) */
  .sidebar-panel {
    border-left: none;
    max-height: none;
    overflow: visible;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 6px 8px;
  }

  .sidebar-section {
    padding: 5px 7px;
    border: 1px solid var(--border-subtle);
    border-radius: 5px;
    background: var(--bg-panel);
    min-width: 0;
  }

  /* Section 1 (KPIs) et Section 4 (Chapitres / Notes) prennent toute la largeur ; Sections 2 et 3 (Graphes) sont 2 par ligne */
  .sidebar-section:first-child,
  .sidebar-section:nth-child(4) {
    grid-column: 1 / -1;
  }

  .section-title {
    font-size: 8.5px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .metrics-grid {
    gap: 5px;
  }

  .metric-card {
    padding: 4px 6px;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px;
  }

  .metric-card .metric-header {
    font-size: 7.5px;
    margin-bottom: 0;
  }

  .metric-card .metric-value {
    font-size: 11.5px;
    white-space: nowrap;
  }

  .chart-box,
  .chart-box.radar-box {
    height: 92px !important;
    padding: 2px;
    border: none;
    background: transparent;
  }

  .story-chapters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .story-chapter-card {
    padding: 5px 6px;
    background: rgba(255, 255, 255, 0.02);
  }

  .story-chapter-card .chapter-title {
    font-size: 9.5px;
    margin-bottom: 0;
    gap: 4px;
  }

  .story-chapter-card .sim-tag {
    font-size: 8px;
    padding: 1px 4px;
  }

  .story-chapter-card .chapter-desc {
    display: none;
  }

  .sidebar-section:nth-child(4) p {
    font-size: 9.5px !important;
    line-height: 1.3 !important;
    margin-bottom: 3px !important;
  }

  .hud-grips, .hud-env {
    bottom: 5px;
    left: 5px;
    right: 5px;
    padding: 3px 6px;
    font-size: 8.5px;
    gap: 4px;
  }
}
