:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --bg-deep: #020617;
  --panel: rgba(17, 24, 39, 0.82);
  --panel-solid: #111827;
  --panel-2: #1f2937;
  --panel-3: #0b1220;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --text-soft: #cbd5e1;
  --compound: #38bdf8;
  --concept: #f59e0b;
  --link: rgba(148, 163, 184, 0.35);
  --accent: #22c55e;
  --danger: #f87171;
  --border: rgba(148, 163, 184, 0.18);
  --border-strong: rgba(148, 163, 184, 0.26);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);

  --left-panel-width: 300px;
  --right-panel-width: 360px;
  --panel-gap: 20px;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.25s ease;
}

/* -----------------------------
   BASE
----------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.06), transparent 22%),
    radial-gradient(circle at bottom right, rgba(245, 158, 11, 0.05), transparent 20%),
    linear-gradient(180deg, var(--bg-deep), var(--bg));
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3 {
  margin: 0;
}

p {
  margin: 0;
}

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

/* -----------------------------
   MAIN WRAP
----------------------------- */
.wrap {
  max-width: none;
  min-height: 100vh;
  margin: 0;
  padding: 24px;
  margin-left: calc(var(--left-panel-width) + var(--panel-gap));
  margin-right: calc(var(--right-panel-width) + var(--panel-gap));
  transition:
    margin-left var(--transition),
    margin-right var(--transition);
}

body.sidebar-closed .wrap {
  margin-left: var(--panel-gap);
}

body.info-panel-closed .wrap {
  margin-right: var(--panel-gap);
}

/* -----------------------------
   TYPO
----------------------------- */
h1 {
  margin-bottom: 8px;
  font-size: 2rem;
  line-height: 1.1;
}

p {
  color: var(--muted);
  margin-bottom: 16px;
}

/* -----------------------------
   MAIN ACTION
----------------------------- */
.toolbar-main {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  margin: 10px 0 8px;
}

#runBtn {
  appearance: none;
  border: 0;
  padding: 12px 18px;
  min-height: 46px;
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: #03111f;
  background: linear-gradient(135deg, #38bdf8, #22c55e);
  box-shadow:
    0 10px 24px rgba(34, 197, 94, 0.18),
    0 6px 16px rgba(56, 189, 248, 0.16);
  transition:
    transform 0.16s ease,
    filter 0.16s ease,
    box-shadow 0.16s ease,
    opacity 0.16s ease;
}

#runBtn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow:
    0 14px 28px rgba(34, 197, 94, 0.22),
    0 8px 18px rgba(56, 189, 248, 0.18);
}

#runBtn:active {
  transform: translateY(0);
  filter: brightness(0.98);
  box-shadow:
    0 8px 18px rgba(34, 197, 94, 0.16),
    0 4px 12px rgba(56, 189, 248, 0.14);
}

#runBtn:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
  box-shadow: none;
}

/* -----------------------------
   STATUS + FOOTER
----------------------------- */
.status {
  margin: 8px 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  min-height: 48px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: var(--muted);
  line-height: 1.45;
}

.status.error,
.error {
  color: var(--danger);
}

.footer-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

/* -----------------------------
   LEGEND
----------------------------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

/* -----------------------------
   PANEL
----------------------------- */
.panel {
  position: relative; /* important pour placer .map-hint et .map-reset-btn en overlay */
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* -----------------------------
   GRAPH
----------------------------- */
svg {
  width: 100%;
  height: 78vh;
  min-height: 620px;
  display: block;
  background:
    radial-gradient(circle at top, rgba(56, 189, 248, 0.08), transparent 30%),
    radial-gradient(circle at bottom right, rgba(245, 158, 11, 0.08), transparent 25%),
    #020617;
  will-change: transform;
}

/* -----------------------------
   TOOLTIP
----------------------------- */
.tooltip {
  position: fixed;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
  background: rgba(2, 6, 23, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.45;
  max-width: 420px;
  z-index: 1200;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}

/* -----------------------------
   LEFT SIDEBAR
----------------------------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--left-panel-width);
  height: 100vh;
  padding: 16px;
  overflow-y: auto;
  background: var(--bg);
  color: var(--text);
  border-right: 1px solid #1f2937;
  z-index: 1000;
  transition: transform var(--transition);
}

.sidebar.closed {
  transform: translateX(-100%);
}

.sidebar h2 {
  margin-bottom: 14px;
  font-size: 1.15rem;
}

/* labels */
.sidebar label {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  font-size: 0.92rem;
  color: var(--muted);
  gap: 4px;
}

.sidebar label.row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

/* inputs */
.sidebar input,
.sidebar select {
  width: 100%;
  margin-top: 2px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: var(--panel-2);
  color: var(--text);
}

.sidebar input[type="checkbox"] {
  width: auto;
  margin-top: 0;
}

/* optional buttons in sidebar */
.sidebar button:not(.panel-mini-btn) {
  margin-top: 12px;
  padding: 11px 12px;
  width: 100%;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  background: linear-gradient(135deg, #0ea5e9, #22c55e);
  color: #03111f;
}

.sidebar button:not(.panel-mini-btn):hover {
  filter: brightness(1.06);
}

/* -----------------------------
   RIGHT PANEL
----------------------------- */
.info-panel {
  position: fixed;
  inset: 0 0 0 auto;
  width: var(--right-panel-width);
  height: 100vh;
  padding: 16px;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.98);
  color: var(--text);
  border-left: 1px solid var(--border);
  z-index: 1000;
  transition: transform var(--transition);
}

.info-panel.closed {
  transform: translateX(100%);
}

.info-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.info-panel-header h2 {
  font-size: 1.15rem;
}

.info-panel-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.info-block {
  padding: 14px;
}

.info-block h3 {
  margin-bottom: 10px;
  font-size: 1rem;
  color: var(--text);
}

.info-content {
  color: var(--text-soft);
  font-size: 0.92rem;
  line-height: 1.5;
}

.info-attrs {
  margin-top: 10px;
  max-height: calc(100vh - 280px);
  overflow: auto;
}

info-attrs dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(110px, 130px) 1fr;
  column-gap: 12px;
  row-gap: 8px;
  font-size: 0.9rem;
}

.info-attrs dt {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

.info-attrs dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

/* -----------------------------
   TOGGLE BUTTONS
----------------------------- */
.sidebar-toggle,
.info-toggle,
.panel-mini-btn {
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: #1f2937;
  color: #fff;
  border-radius: 8px;
  transition:
    left var(--transition),
    right var(--transition),
    filter 0.18s ease,
    background 0.18s ease;
}

.sidebar-toggle:hover,
.info-toggle:hover,
.panel-mini-btn:hover {
  filter: brightness(1.08);
}

.sidebar-toggle {
  position: fixed;
  top: 10px;
  left: calc(var(--left-panel-width) + 10px);
  z-index: 1100;
  padding: 8px 10px;
}

body.sidebar-closed .sidebar-toggle {
  left: 10px;
}

.info-toggle {
  position: fixed;
  top: 10px;
  right: calc(var(--right-panel-width) + 10px);
  z-index: 1100;
  padding: 8px 10px;
}

body.info-panel-closed .info-toggle {
  right: 10px;
}

.panel-mini-btn {
  padding: 6px 10px;
  min-width: 38px;
  line-height: 1;
}

/* -----------------------------
   SECTIONS
----------------------------- */
.section {
  margin-bottom: 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(17, 24, 39, 0.6);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: var(--text);
  background: rgba(31, 41, 55, 0.5);
}

.section-header:hover {
  background: rgba(31, 41, 55, 0.8);
}

.section-content {
  padding: 12px;
  display: none;
  flex-direction: column;
  gap: 10px;
}

.section.open .section-content {
  display: flex;
}

.section .arrow {
  transition: transform 0.2s ease;
}

.section.open .arrow {
  transform: rotate(180deg);
}

/* -----------------------------
   LOADING OVERLAY
----------------------------- */
.loading-overlay[hidden] {
  display: none;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(3px);
}

.loading-card {
  width: min(92vw, 620px);
  padding: 18px 20px;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.loading-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.loading-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f8fafc;
}

.loading-message {
  font-size: 0.92rem;
  color: #94a3b8;
  margin-top: 2px;
}

.loading-spinner {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 3px solid rgba(148, 163, 184, 0.22);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-progress-wrap {
  margin: 10px 0 12px;
}

#loadingProgress {
  width: 100%;
  height: 12px;
  appearance: none;
}

#loadingProgress::-webkit-progress-bar {
  background: #1e293b;
  border-radius: 999px;
}

#loadingProgress::-webkit-progress-value {
  background: linear-gradient(90deg, #38bdf8, #22c55e);
  border-radius: 999px;
}

#loadingProgress::-moz-progress-bar {
  background: linear-gradient(90deg, #38bdf8, #22c55e);
  border-radius: 999px;
}

.loading-progress-meta {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  color: #cbd5e1;
}

.loading-step {
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: #e2e8f0;
}

.loading-events {
  max-height: 132px;
  overflow: auto;
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #94a3b8;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 10px;
}

.loading-events div + div {
  margin-top: 4px;
}

body.is-loading {
  overflow: hidden;
}

/* -----------------------------
   FOCUS
----------------------------- */
button:focus-visible,
input:focus-visible,
select:focus-visible,
.section-header:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.85);
  outline-offset: 2px;
}

/* -----------------------------
   RESPONSIVE
----------------------------- */
@media (max-width: 1200px) {
  :root {
    --right-panel-width: 320px;
  }
}

@media (max-width: 1100px) {
  .wrap {
    margin-left: var(--panel-gap);
    margin-right: var(--panel-gap);
  }

  .sidebar,
  .info-panel {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  }

  .sidebar-toggle {
    left: 10px;
  }

  .info-toggle {
    right: 10px;
  }
}

@media (max-width: 820px) {
  :root {
    --left-panel-width: min(88vw, 320px);
    --right-panel-width: min(88vw, 340px);
  }

  .wrap {
    padding: 20px 14px;
  }

  h1 {
    font-size: 1.7rem;
  }

  svg {
    min-height: 460px;
    height: 68vh;
  }

  .info-attrs dl {
    grid-template-columns: 1fr;
  }

  .info-attrs dt {
    margin-top: 6px;
  }

  .info-attrs dd {
    margin-bottom: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* -----------------------------
   ANIMATION
----------------------------- */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* -----------------------------
   INFO BUTTON
----------------------------- */
.info-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.info-btn::before {
  content: "ℹ️";
  font-size: 1rem;
}

.info-btn:hover,
.info-btn:focus-visible {
  background: rgba(148, 163, 184, 0.15);
  outline: none;
}

/* -----------------------------
   INFO MODAL
----------------------------- */
.info-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.info-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(3px);
}

.info-modal-card {
  position: relative;
  max-width: 720px;
  width: 100%;
  margin: 1.5rem;
  padding: 18px 20px;
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.info-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.info-modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}

.info-modal-close {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
}

.info-modal-close:hover,
.info-modal-close:focus-visible {
  background: var(--panel-3);
}

/* modal content */
.info-modal-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.92rem;
}

.info-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.info-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex: 0 0 auto;
}

.info-row h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: var(--text);
}

.info-row p {
  margin: 0;
  color: var(--text-soft);
}

.info-modal-content a {
  color: var(--compound);
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

/* -----------------------------
   GRAPH OVERLAYS (HINT + RESET)
----------------------------- */
.map-hint {
  position: absolute;
  z-index: 5;
  top: 6px;
  left: 8px;
  padding: 2px 6px;
  max-width: 360px;
  font-size: 0.62rem;
  line-height: 1.2;
  color: var(--text-soft);
  font-style: italic;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  white-space: normal;
  overflow-wrap: break-word;
}

.map-reset-btn {
  position: absolute;
  z-index: 6;
  top: 6px;
  right: 8px;
  padding: 2px 8px;
  font-size: 0.7rem;
  line-height: 1.2;
  color: var(--text-soft);
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.map-reset-btn:hover,
.map-reset-btn:focus-visible {
  background: rgba(30, 64, 175, 0.9);
}