/* Charte reprise de Nuclear map : fond sombre plein écran, volets flottants, accent or. */
:root {
  --bg: #0e0f11;
  --border: #3a3b3e;
  --panel: rgba(22, 23, 25, 0.94);
  --ink: #e8e8e6;
  --ink-2: #a9a9a5;
  --ink-3: #75756f;
  --row: #26272a;
  --row-sel: #2e3035;
  --gold: #d4af37;
  /* Catégories de liens (séparation daltonisme validée sur ce fond) ; le doré souligne l'important */
  --l-direction: #d4af37;
  --l-conseil: #3987e5;
  --l-controle: #199e70;
  --l-autre: #6f6f6a;
  /* Nœuds */
  --n-company: #ece8df;
  --n-closed: #8a857a;
  --n-person: #b4bec9;
  --n-masked: #3d3e42;
  /* surfaces et états */
  --btn: #242528;
  --input: #111214;
  --menu: #17181a;
  --pressed: #2b2a20;
  --code: #141517;
  --layer: rgba(255, 255, 255, 0.012);
  --dialog: rgba(18, 19, 21, 0.95);
  --backdrop: rgba(0, 0, 0, 0.35);
  --shadow: rgba(0, 0, 0, 0.55);
  --note-bg: #2a2419;
  --note-border: #5a4a22;
  --note-ink: #e6d7a8;
  --err-border: #7a3428;
  --err-ink: #e0735f;
  color-scheme: dark;
}

/* Mode clair : mêmes rôles, teintes validées sur fond clair (le doré s'assombrit pour rester lisible) */
:root[data-theme="light"] {
  --bg: #f6f5f1;
  --border: #d6d5ce;
  --panel: rgba(255, 255, 255, 0.94);
  --ink: #1d1d1b;
  --ink-2: #55554f;
  --ink-3: #8a8a83;
  --row: #ebeae5;
  --row-sel: #e2e1db;
  --gold: #a8801a;
  --l-direction: #a8801a;
  --l-conseil: #2a78d6;
  --l-controle: #138a5f;
  --l-autre: #9a9a93;
  --n-company: #3f3d38;
  --n-closed: #857f74;
  --n-person: #7b8da3;
  --n-masked: #cfcec8;
  --btn: #ffffff;
  --input: #ffffff;
  --menu: #ffffff;
  --pressed: #f5ecd2;
  --code: #ecebe6;
  --layer: rgba(0, 0, 0, 0.015);
  --dialog: rgba(252, 252, 250, 0.97);
  --backdrop: rgba(0, 0, 0, 0.2);
  --shadow: rgba(0, 0, 0, 0.18);
  --note-bg: #fbf3dc;
  --note-border: #e3cf8f;
  --note-ink: #6b5313;
  --err-border: #e3a597;
  --err-ink: #b83a26;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden; }
#cy { position: absolute; inset: 0; }
button { background: var(--btn); color: var(--ink); border: 1px solid var(--border); border-radius: 5px;
  padding: 4px 9px; font: inherit; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--ink-3); }
button:disabled { opacity: .35; cursor: default; }
button[aria-pressed="true"] { background: var(--pressed); border-color: var(--gold); color: var(--gold); }
button.link { background: none; border: none; padding: 0; color: var(--ink-2); text-decoration: underline; font-size: 11.5px; }
button.link:hover { color: var(--gold); }
a { color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--ink-3); }
a:hover { color: var(--gold); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
input[type=checkbox] { accent-color: var(--gold); margin: 0; }

.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--ink-3); font-size: 14px; pointer-events: none; text-align: center; padding: 0 24px; }

/* --- Volets --------------------------------------------------------------------------- */
.panel { position: absolute; top: 12px; z-index: 2; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 12px 8px; display: flex; flex-direction: column; }
#side { left: 12px; width: 300px; max-height: calc(100% - 24px); overflow-y: auto; }
h1 { font-size: 19px; letter-spacing: .01em; margin: 0 0 3px; font-weight: 600; line-height: 1.2; }
.sub { color: var(--ink-3); font-size: 12.5px; margin-bottom: 12px; }
.group-title { color: var(--ink-3); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; margin: 12px 0 4px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.search-row { display: flex; gap: 6px; align-items: flex-start; }
.search-row .search { flex: 1; min-width: 0; }
.icon-btn { flex: none; width: 33px; height: 33px; padding: 0; font-size: 16px; line-height: 1; color: var(--ink-2); }
.icon-btn:hover { color: var(--gold); border-color: var(--gold) !important; }
#graph-tools { margin-top: 8px; }
.row-2, .row-3 { display: grid; gap: 6px; }
.row-2 { grid-template-columns: 1.6fr 1fr; }
.row-analyse { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.row-analyse #btn-multi, .row-analyse .wide { grid-column: 1 / -1; }
.country-filter { margin-top: 6px; max-height: 220px; overflow-y: auto; border: 1px solid var(--row); border-radius: 7px; padding: 4px 8px; }
.country-filter .cf-head { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 0 4px; }
.country-filter .cf-head .link { font-size: 10.5px; text-transform: none; letter-spacing: 0; }
.country-filter .kind { color: var(--ink-3); font-size: 11px; min-width: 22px; }
.row-analyse button { font-size: 12px; }

/* logos d'école à côté des noms (calque au-dessus du graphe) */
.school-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
.school-layer .gico { position: absolute; border-radius: 3px; object-fit: contain; background: #fff; box-shadow: 0 0 0 1px var(--border);
  transition: opacity .15s; }
.school-layer .gico.mono { display: flex; align-items: center; justify-content: center; background: var(--row); color: var(--ink-2);
  font-weight: 700; font-family: system-ui, sans-serif; letter-spacing: -.02em; }
.row-3 { grid-template-columns: 1.6fr 1fr 1fr; }
.row-2 button, .row-3 button, .row-share button { font-size: 12px; }
.row-share { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.row-share #btn-share { grid-column: 1 / -1; }

/* blocs repliables (comme les couches de Nuclear map) */
.layer { border: 1px solid var(--row); border-radius: 7px; margin-top: 10px; background: var(--layer); }
.layer-head { display: flex; align-items: center; padding: 6px 8px; }
.layer-title { flex: 1; color: var(--ink-3); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
.disclose { background: none; border: none; color: var(--ink-3); padding: 0 4px; font-size: 13px; transform: rotate(-90deg); transition: transform .15s; }
.disclose[aria-expanded="true"] { transform: rotate(0); }
.disclose:hover { color: var(--ink); }
.layer-body { padding: 4px 8px 8px; border-top: 1px solid var(--row); }

/* commandes de vue (bas droite) */
.view-ctrl { position: absolute; right: 14px; bottom: 18px; z-index: 2; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
body.detail-open .view-ctrl { right: 366px; }
.view-ctrl button { border: none; border-radius: 0; width: 32px; height: 30px; padding: 0; font-size: 16px; background: none; }
.view-ctrl button + button { border-top: 1px solid var(--border); }
.view-ctrl button:hover { color: var(--gold); }
.cb-gap { width: 13px; flex: none; }
.groups-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 160px; overflow-y: auto; }
.groups-list li { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.groups-list li:hover { background: var(--row); }
.groups-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.groups-list .n { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.groups-list .info { color: var(--ink-3); cursor: default; }
.grp-link { color: var(--ink) !important; text-decoration: none !important; font-size: 13px !important; }
.note-small { color: var(--ink-3); font-size: 11px; line-height: 1.4; margin-top: 8px; }

.search { position: relative; }
.search input { width: 100%; background: var(--input); color: var(--ink); border: 1px solid var(--border); border-radius: 5px;
  padding: 7px 9px; font: inherit; }
.search input:focus { outline: none; border-color: var(--ink-3); }
.search-results { position: absolute; left: 0; right: 0; top: 100%; z-index: 3; margin: 2px 0 0; padding: 4px; list-style: none;
  background: var(--menu); border: 1px solid var(--border); border-radius: 5px; max-height: 380px; overflow-y: auto; }
/* Dans le volet de gauche (qui défile), la liste s'insère dans le flux au lieu de déborder :
   sinon elle serait coupée par le volet. */
#side .search-results { position: static; margin-top: 4px; max-height: min(420px, 55vh); }
.search-results li { padding: 5px 6px; border-radius: 4px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.search-results li:hover, .search-results li.active { background: var(--row); }
.search-results .kind { color: var(--ink-3); font-size: 11px; min-width: 44px; flex: none; }
.search-results .nm { flex: 1; min-width: 0; }
.search-results .li-sub { display: block; color: var(--ink-3); font-size: 11px; }
.search-results .closed .nm { color: var(--ink-2); }
.search-results .info { color: var(--ink-3); cursor: default; font-size: 12px; }
.search-results .section { cursor: default; color: var(--ink-3); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  padding: 8px 6px 3px; justify-content: space-between; }
.search-results .section:hover { background: none; }
.search-results .section .n { text-transform: none; letter-spacing: 0; }
.search-results .more { color: var(--ink-2); justify-content: center; }

/* Légende */
.legend .key, .legend label { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.legend label { cursor: pointer; }
.legend .lbl { flex: 1; }
.legend .n { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 12px; }
.line { width: 18px; height: 0; border-top: 2px solid var(--ink-2); flex: none; }
.line.dashed { border-top-style: dashed; }
.line.arrow { position: relative; }
.line.arrow::after { content: ''; position: absolute; right: -2px; top: -5px; border-left: 6px solid; border-left-color: inherit;
  border-top: 4px solid transparent; border-bottom: 4px solid transparent; }
.sq { width: 9px; height: 9px; background: var(--n-company); flex: none; margin: 0 4.5px; }
.sq.hollow { background: transparent; border: 1.5px solid var(--n-closed); }
.sq.masked { background: var(--n-masked); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--n-person); flex: none; margin: 0 4.5px; }
.ico { flex: none; vertical-align: -2px; }
.cdot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }

.panel-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding-top: 8px; border-top: 1px solid var(--row); margin-top: 12px; font-size: 11.5px; }
#inpi-tag { color: var(--ink-3); font-size: 10.5px; }
.foot-right { display: inline-flex; align-items: center; gap: 8px; }
.theme-btn { padding: 0 7px; line-height: 20px; font-size: 13px; color: var(--ink-2); }
.theme-btn:hover { color: var(--gold); }

/* --- Fiche (volet de droite, visible seulement après un clic) ------------------------- */
.detail-panel { right: 12px; width: 340px; max-height: calc(100% - 24px); overflow-y: auto; }
.detail-panel .head { display: flex; align-items: flex-start; gap: 8px; }
.detail-panel h2 { font-size: 15px; margin: 0; font-weight: 600; line-height: 1.3; }
.cc { display: inline-block; font-size: .72em; font-weight: 600; letter-spacing: .03em; color: var(--ink-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 4px; margin-right: 6px; vertical-align: .12em; }
.detail-panel .close { margin-left: auto; padding: 0 7px; line-height: 20px; flex: none; }
.detail-panel .site { color: var(--ink-2); font-size: 12px; margin: 3px 0 8px; }
.detail-panel .actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 10px; }
.detail-panel .actions button { font-size: 12px; }
.detail-panel table { border-collapse: collapse; width: 100%; }
.detail-panel td { padding: 3px 0; vertical-align: top; border-bottom: 1px solid var(--row); }
.detail-panel td.k { color: var(--ink-3); width: 36%; padding-right: 10px; }
.detail-panel .note { background: var(--note-bg); border: 1px solid var(--note-border); color: var(--note-ink); border-radius: 5px; padding: 6px 8px;
  font-size: 12px; margin: 6px 0 8px; }
.detail-panel .hint { color: var(--ink-3); font-size: 12px; margin: 6px 0; }
.units { list-style: none; margin: 2px 0 0; padding: 0; }
.units li { display: flex; align-items: flex-start; gap: 8px; padding: 4px; border-radius: 4px; }
.units li[data-goto] { cursor: pointer; }
.units li[data-goto]:hover { background: var(--row); }
.units li .ico { flex: none; vertical-align: -2px; }
.cdot { margin-top: 5px; }
.units .nm { flex: 1; min-width: 0; }
.units .li-sub { display: block; color: var(--ink-3); font-size: 11px; }
.conf { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }
.conf.partielle { color: var(--gold); }
.detail-panel details { margin: 8px 0 0; }
.detail-panel details > summary { cursor: pointer; font-size: 12px; color: var(--ink-2); padding: 2px 0; }
.detail-panel details > summary:hover { color: var(--ink); }
.schools { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-bottom: 2px; }
.school { display: inline-flex; align-items: center; gap: 5px; padding: 2px 7px 2px 3px; border: 1px solid var(--border); border-radius: 12px;
  color: var(--ink) !important; text-decoration: none !important; font-size: 12px; max-width: 100%; }
.school:hover { border-color: var(--gold); }
.school span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.school-logo { width: 18px; height: 18px; border-radius: 4px; object-fit: contain; background: #fff; flex: none; }
.school-logo.crop-top, .school-layer .gico.crop-top { object-fit: cover; object-position: 50% 0%; }
.school-logo.crop-left, .school-layer .gico.crop-left { object-fit: cover; object-position: 0% 50%; }
.school-logo.mono { display: inline-flex; align-items: center; justify-content: center; background: var(--row); color: var(--ink-2);
  font-size: 8px; font-weight: 700; letter-spacing: -.02em; }
.src-notes { margin-top: 10px; padding-top: 6px; border-top: 1px solid var(--row); color: var(--ink-3); font-size: 11px; line-height: 1.5; }
code { background: var(--code); padding: 0 4px; border-radius: 3px; font-size: 12px; }

.edge-tip { position: absolute; z-index: 3; pointer-events: none; width: max-content; max-width: 300px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 9px; font-size: 12px; color: var(--ink); }
.edge-tip .tip-cat { display: flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: 11px; margin-bottom: 2px; }
.edge-tip b { font-weight: 600; }
.graph-search { margin-bottom: 2px; }

/* Chemin entre deux nœuds : boîte en haut, entre les deux volets */
.path-box { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3; width: min(520px, calc(100% - 700px));
  min-width: 300px; background: var(--panel); border: 1px solid var(--gold); border-radius: 8px; padding: 10px 12px; }
.pb-head { font-weight: 600; }
.pb-sub { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.pb-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 6px; font-size: 12px; }
.pb-node { color: var(--ink) !important; font-size: 12px !important; font-weight: 600; text-decoration: none !important; }
.pb-node:hover { color: var(--gold) !important; }
.pb-edge { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-3); }
.pb-edge .line { width: 12px; }
.pb-search { margin-top: 6px; }
.pb-actions { display: flex; gap: 6px; margin-top: 8px; }
.pb-actions button { font-size: 12px; }
@media (max-width: 760px) { .path-box { width: calc(100% - 24px); min-width: 0; top: auto; bottom: calc(46vh + 24px); } }
.status { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 4; background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; font-size: 12px; color: var(--ink-2); max-width: 80%; }
.status.error { border-color: var(--err-border); color: var(--err-ink); }

/* --- Fenêtre Sources et méthode ------------------------------------------------------- */
.sources-dialog { width: min(860px, calc(100vw - 120px)); max-height: calc(100vh - 80px); padding: 0;
  background: var(--dialog); color: var(--ink); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 20px 60px var(--shadow); backdrop-filter: blur(3px); }
.sources-dialog::backdrop { background: var(--backdrop); }
.sources-dialog[open] { display: flex; flex-direction: column; }
.dialog-head { display: flex; align-items: center; padding: 14px 20px 10px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-head .close { margin-left: auto; font-size: 16px; padding: 2px 10px; }
.dialog-body { overflow-y: auto; padding: 12px 20px 22px; }
.sources-content h3 { font-size: 14px; margin: 20px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.sources-content .lead, .sources-content p { color: var(--ink-2); margin: 4px 0 10px; line-height: 1.55; }
.sources-content ul { color: var(--ink-2); line-height: 1.55; padding-left: 20px; }
.sources-content b { color: var(--ink); font-weight: 600; }
.src-card { border: 1px solid var(--row); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--layer); }
.src-card .top { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.src-card .name { font-weight: 600; }
.src-card .role { color: var(--ink-2); margin: 3px 0 4px; }
.src-card dl { display: grid; grid-template-columns: 130px 1fr; gap: 2px 10px; margin: 0; font-size: 12px; }
.src-card dt { color: var(--ink-3); }
.src-card dd { margin: 0; color: var(--ink-2); }
.sources-content .kind { display: inline-block; font-size: 10.5px; border-radius: 4px; padding: 0 6px; border: 1px solid var(--border); color: var(--ink-2); }
.sources-content .kind.primaire { border-color: var(--gold); color: var(--gold); }
.sources-content table.countries { border-collapse: collapse; width: 100%; font-size: 12.5px; margin: 6px 0 8px; }
.countries th { text-align: left; color: var(--ink-3); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.countries th, .countries td { padding: 5px 8px 5px 0; border-bottom: 1px solid var(--row); vertical-align: top; color: var(--ink-2); }
.countries td b { color: var(--ink); }
.countries .muted { color: var(--ink-3); }
.sources-content ul.notes { font-size: 12px; }
.defs { display: grid; grid-template-columns: 170px 1fr; gap: 6px 16px; margin: 6px 0; font-size: 12.5px; }
.defs dt { color: var(--ink); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.defs dd { margin: 0; color: var(--ink-2); line-height: 1.45; }

@media (max-width: 760px) {
  body.detail-open .view-ctrl { right: 14px; }
  #side { right: 12px; width: auto; max-height: 46vh; }
  .detail-panel { top: auto; bottom: 12px; left: 12px; right: 12px; width: auto; max-height: 46vh; }
  .empty { padding-left: 0; padding-top: 40vh; }
  .sources-dialog { width: calc(100vw - 24px); }
  .defs { grid-template-columns: 1fr; }
}
