:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d9dee6;
  --text: #1c2430;
  --muted: #5d6b7e;
  /* Charte RESA */
  --brand-navy: #1c3172;
  --brand-orange: #ff5300;
  --accent: var(--brand-navy);
  --accent-text: #ffffff;
  --header-line: var(--brand-navy);
  --danger: #b42318;
  --shadow: 0 6px 24px rgba(16, 24, 40, .12);
  color-scheme: light;
}
.logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151b;
    --surface: #1b212a;
    --surface-2: #242c37;
    --border: #333d4a;
    --text: #e6eaf0;
    --muted: #9aa6b6;
    --accent: #8fa6ec;
    --accent-text: #0b1220;
    --header-line: #ffffff;
    --danger: #f97066;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark { display: inline-block; }
}
/* Thème sombre choisi manuellement (bouton de l'en-tête) */
:root[data-theme="dark"] {
  --bg: #11151b;
  --surface: #1b212a;
  --surface-2: #242c37;
  --border: #333d4a;
  --text: #e6eaf0;
  --muted: #9aa6b6;
  --accent: #8fa6ec;
  --accent-text: #0b1220;
  --header-line: #ffffff;
  --danger: #f97066;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: inline-block; }

.theme-toggle { margin-left: auto; display: grid; place-items: center; width: 34px; height: 32px; padding: 0; }
.theme-toggle svg { width: 18px; height: 18px; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); padding: 10px 18px; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Barre supérieure --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--header-line);
  flex-wrap: wrap;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 16px; min-width: 0; color: var(--accent); }
.brand img { height: 26px; width: auto; flex: none; }
.brand .sep { width: 1px; height: 24px; background: var(--border); }
.splash-logo { height: 44px; width: auto; margin-bottom: 20px; }
button.primary { background: var(--brand-navy); border-color: var(--brand-navy); color: #fff; }
.splash-card { border-top: 4px solid var(--brand-orange); }
.details { border-top: 4px solid var(--brand-orange); }
.search { position: relative; flex: 1 1 260px; max-width: 460px; }
.search input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 60vh;
  overflow: auto;
  z-index: 20;
}
.search-results li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.search-results li[aria-selected="true"], .search-results li:hover { background: var(--surface-2); }
.search-results .sub { color: var(--muted); font-size: 12px; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; }
.account { display: flex; align-items: center; gap: 8px; color: var(--muted); }

/* --- Zone principale --- */
main { position: relative; flex: 1; min-height: 0; }
.chart { position: absolute; inset: 0; }
.chart svg { display: block; }

.splash { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.splash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.splash-card h1 { margin: 0 0 8px; font-size: 22px; }
.splash-card p { color: var(--muted); }
.status { min-height: 1.4em; margin: 16px 0 0; }
.status.error { color: var(--danger); text-align: left; white-space: pre-wrap; }
.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px;
  border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Bouton d'expansion des nœuds --- */
.expand-btn {
  display: flex; align-items: center; justify-content: center; gap: 2px;
  width: 40px; height: 22px; margin: auto;
  border-radius: 11px;
  background: #ffffff; color: #1c2430;
  border: 1px solid #c3cad5;
  font: 600 11px "Segoe UI", system-ui, sans-serif;
}

/* --- Panneau de détail --- */
.details {
  position: absolute;
  top: 12px; right: 12px; bottom: 12px;
  width: 340px;
  max-width: calc(100% - 24px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
  z-index: 10;
}
.details .close { position: absolute; top: 8px; right: 8px; border: none; font-size: 22px; line-height: 1; padding: 4px 10px; background: transparent; }
.details .head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; padding-right: 24px; }
.details .avatar { width: 64px; height: 64px; font-size: 22px; }
.details h2 { margin: 0; font-size: 18px; }
.details .title { color: var(--muted); }
.details dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0 0 16px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.details a { color: var(--accent); }
.details h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
.details .people { list-style: none; margin: 0; padding: 0; }
.details .people button { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; border: none; background: transparent; padding: 6px; white-space: normal; }
.details .people button:hover { background: var(--surface-2); }
.details .people .avatar { width: 32px; height: 32px; font-size: 12px; }
.details .people .sub { color: var(--muted); font-size: 12px; }
.details .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.details .actions a { text-decoration: none; border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; }

.avatar {
  flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  overflow: hidden;
  color: #fff; font-weight: 600;
  background: var(--accent);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.stats {
  position: absolute; left: 12px; bottom: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; color: var(--muted); font-size: 12px;
}

.legend {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; gap: 14px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; color: var(--text); font-size: 12px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 10px; border: 3px solid; border-radius: 3px; background: #fff; }
.details .badges { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 14px; }
.details .badge { border: 1.5px solid; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 600; }

@media (max-width: 700px) {
  .legend { bottom: 52px; left: 12px; right: auto; }
  .toolbar button[data-action="layout"], .toolbar button[data-action="compact"], .toolbar button[data-action="export"] { display: none; }
  .account span { display: none; }
  .details { top: auto; left: 12px; width: auto; max-height: 60%; }
}
