/* PortSim SN — repères de marque SENLOGIC v1 (27/09/2026), thèmes clair/sombre,
   responsive jusqu'à 400px */

:root {
  --font-title: "IBM Plex Sans Condensed", "Arial Narrow", sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "Consolas", monospace;

  /* Couleurs de marque fixes (identiques dans les deux thèmes) */
  --brand-encre: #10182b;
  --brand-papier: #f5f6f4;
  --brand-or: #e3a83b;
  --brand-sarcelle: #1e9e93;

  --navy: var(--brand-encre);
  --navy-light: #1c2947;
  --teal: var(--brand-sarcelle);
  --teal-light: #35b6aa;
  --yellow: var(--brand-or);
  --green: #1e8e3e;
  --red: #c62828;
  /* Distinct de --navy : sert de couleur de série au graphique (file extérieure),
     où --navy (encre) manquerait de contraste sur fond sombre en thème nuit. */
  --chart-file-ext: var(--brand-encre);

  --bg: var(--brand-papier);
  --surface: #ffffff;
  --surface-2: #eaebe7;
  --text: var(--brand-encre);
  --text-muted: #5b6472;
  --border: #dde0db;

  --radius: 10px;
  --transition-fast: 150ms ease;

  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: var(--brand-encre);
    --surface: #182238;
    --surface-2: #202b45;
    --text: #ecede9;
    --text-muted: #9aa3b4;
    --border: #2a3550;
    --navy: #1c2947;
    --navy-light: #263759;
    --teal: #35b6aa;
    --teal-light: #4cc7bb;
    --yellow: var(--brand-or);
    --green: #4caf6f;
    --red: #e57373;
    --chart-file-ext: #7c8db4;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--brand-encre);
  --surface: #182238;
  --surface-2: #202b45;
  --text: #ecede9;
  --text-muted: #9aa3b4;
  --border: #2a3550;
  --navy: #1c2947;
  --navy-light: #263759;
  --chart-file-ext: #7c8db4;
  --teal: #35b6aa;
  --teal-light: #4cc7bb;
  --yellow: var(--brand-or);
  --green: #4caf6f;
  --red: #e57373;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.4;
}

h1, h2, h3 { font-family: var(--font-title); font-weight: 600; letter-spacing: 0.01em; margin: 0 0 0.6em; }
h2 { font-size: 1.05rem; text-transform: uppercase; color: var(--text-muted); }

img { max-width: 100%; }
[hidden] { display: none !important; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--teal-light);
  outline-offset: 2px;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.2rem;
  background: var(--navy);
  color: #fff;
  flex-wrap: wrap;
}

.brand-name {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.02em;
}

.brand-sub {
  display: block;
  font-size: 0.7rem;
  color: #b9cddf;
}

.scenarios {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-left: auto;
}

.scenario-btn {
  background: var(--navy-light);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.scenario-btn:hover { background: var(--teal); }

.scenario-btn.active {
  background: var(--yellow);
  color: var(--navy);
  font-weight: 600;
  border-color: var(--yellow);
}

.theme-toggle {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  width: 2.1rem;
  height: 2.1rem;
  font-size: 1rem;
}

.banner {
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: center;
  font-size: 0.75rem;
  padding: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.secours-banniere {
  background: var(--yellow);
  color: #3a2e00;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem;
}

.levers-body input:disabled,
.levers-body button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* ---------- Levers ---------- */

.levers-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  position: sticky;
  top: 0.6rem;
}

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

.levers-toggle { display: none; }

.lever {
  margin-bottom: 1.1rem;
}

.lever-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.lever label, .lever-label-static {
  font-size: 0.82rem;
  font-weight: 500;
}

.lever-unit {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.lever-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--teal);
  font-weight: 600;
}

.lever-label-flex {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid var(--text-muted);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}

.info-btn:hover,
.info-btn:focus-visible,
.info-btn.active {
  border-color: var(--teal);
  color: var(--teal);
}

.info-popover {
  position: fixed;
  z-index: 300;
  max-width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.info-popover[hidden] { display: none; }

.lever input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.lever input[type="number"] {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
}

.lever-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

input[type="checkbox"][role="switch"] {
  appearance: none;
  width: 2.4rem;
  height: 1.3rem;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  transition: background var(--transition-fast);
}
input[type="checkbox"][role="switch"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition-fast);
}
input[type="checkbox"][role="switch"]:checked {
  background: var(--teal);
}
input[type="checkbox"][role="switch"]:checked::after {
  transform: translateX(1.1rem);
}

.toggle2 {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 0.35rem;
}
.toggle2 button {
  flex: 1;
  border: none;
  background: var(--surface);
  color: var(--text);
  padding: 0.4rem 0.3rem;
  font-size: 0.78rem;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.toggle2 button.active {
  background: var(--teal);
  color: #fff;
  font-weight: 600;
}

/* ---------- Tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.7rem;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  transition: opacity var(--transition-fast);
}

.tile.calculating { opacity: 0.5; }

.tiles-contextuelles {
  margin-top: -0.3rem;
}

.tile-contextuelle {
  border-style: dashed;
  background: var(--surface-2);
}

.tile-contextuelle .tile-value { color: var(--teal); }

.tile-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tile-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 0.15rem;
}

.tile-delta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  margin-top: 0.2rem;
}

.tile-delta.better { color: var(--green); }
.tile-delta.worse { color: var(--red); }

/* ---------- Port view ---------- */

.port-view-section, .chart-section, .economics {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.port-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.port-expand-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.port-expand-btn:hover { background: var(--teal); color: #fff; border-color: var(--teal); }

.port-canvas-wrap {
  background: var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
}

#port-canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* Vue du port agrandie : plein écran natif (:fullscreen) ou repli en overlay CSS
   quand l'API Fullscreen n'est pas disponible (ex. certains contextes intégrés). */
.port-view-section:fullscreen,
.port-view-section.expanded {
  position: fixed;
  inset: 0;
  z-index: 100;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem calc(1rem + env(safe-area-inset-right, 0px)) calc(1rem + env(safe-area-inset-bottom, 0px)) calc(1rem + env(safe-area-inset-left, 0px));
  padding-top: calc(1rem + env(safe-area-inset-top, 0px));
  background: var(--surface);
  overflow-y: auto;
}

.port-view-section:fullscreen .port-canvas-wrap,
.port-view-section.expanded .port-canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* La taille exacte du canevas (width/height inline) est pilotée par port-view.js,
   qui mesure l'espace disponible dans .port-canvas-wrap à chaque redimensionnement. */

body.port-view-lock {
  overflow: hidden;
}

.port-controls {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-top: 0.7rem;
}

.play-pause {
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-weight: 600;
}

.speed-group { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.speed-btn { border: none; background: var(--surface); color: var(--text); padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.speed-btn.active { background: var(--navy); color: #fff; }

.clock {
  font-family: var(--font-mono);
  font-weight: 600;
  margin-left: auto;
}

.time-slider {
  width: 100%;
  margin-top: 0.6rem;
  accent-color: var(--teal);
}

/* ---------- Chart ---------- */

.chart-wrap { position: relative; height: 260px; }

/* ---------- Economics ---------- */

.economics {
  text-align: center;
}

.economics .gain-jour {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--green);
}

.economics .gain-an {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  color: var(--text-muted);
}

.economics .gain-hypothese {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.economics .gain-jour.negatif { color: var(--red); }

/* ---------- Footer ---------- */

.site-footer {
  padding: 1rem 1.2rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.hypotheses summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--teal);
}

.hypotheses-content {
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 70ch;
}

.hypotheses-content ul { padding-left: 1.2rem; }

.senlogic {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

.senlogic-mark {
  flex-shrink: 0;
  display: block;
}

.senlogic-wordmark {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.senlogic-wordmark .sen { color: var(--text); }
.senlogic-wordmark .logic { color: var(--brand-or); }

.senlogic-baseline { color: var(--text-muted); }

.contact {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.contact a { color: var(--text-muted); }
.contact a:hover, .contact a:focus-visible { color: var(--teal); }

/* ---------- Error toast ---------- */

.error-toast {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 50;
}

/* ---------- Guide d'utilisation ---------- */

.guide-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
}

.guide-modal[hidden] { display: none; }

.guide-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 26, 0.55);
}

.guide-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  max-height: min(85vh, 800px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.guide-header h2 {
  margin: 0;
  font-size: 1rem;
  text-transform: none;
  color: var(--text);
}

.guide-close {
  flex-shrink: 0;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
}

.guide-close:hover,
.guide-close:focus-visible {
  border-color: var(--teal);
  color: var(--teal);
}

.guide-content {
  padding: 0.9rem 1.1rem 1.4rem;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
}

.guide-content h3 {
  font-size: 0.92rem;
  margin: 1.3rem 0 0.4rem;
  color: var(--teal);
}

.guide-content h3:first-child { margin-top: 0; }

.guide-content p { margin: 0.4rem 0; }

.guide-content ul {
  margin: 0.4rem 0;
  padding-left: 1.2rem;
}

.guide-content li { margin-bottom: 0.3rem; }

.guide-content strong { color: var(--text); }

@media (max-width: 480px) {
  .guide-modal { padding: 0; }
  .guide-panel {
    max-width: none;
    max-height: 100vh;
    height: 100%;
    border-radius: 0;
  }
}

/* ---------- Responsive ---------- */

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

  .levers-panel {
    position: static;
    order: 6;
  }

  .levers-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.8rem;
    font-size: 0.8rem;
    color: var(--text);
  }

  .levers-header h2 { display: none; }

  .levers-body.collapsed { display: none; }
}

@media (max-width: 400px) {
  .topbar { padding: 0.6rem 0.7rem; }
  .layout { padding: 0.6rem; }
  .tile-value { font-size: 1.25rem; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
