#costs-panel {
    position: fixed;
    top: 50px;
    right: 0;
    bottom: 0;
    width: 380px;
    max-width: 90vw;
    background: var(--bg-page);
    border-left: 1px solid var(--border-panel);
    box-shadow: -4px 0 16px var(--shadow-panel);
    z-index: 800;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease-out;
    transform: translateX(0);
  }
  #costs-panel.hidden {
    transform: translateX(100%);
    pointer-events: none;
  }

  #costs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-header);
    color: white;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
  }
  #costs-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
  }
  #costs-close:hover { background: rgba(255,255,255,0.15); }

  /* Conteneur scrollable qui inclut total + liste */
  #costs-panel > #costs-total-box,
  #costs-panel > #costs-legend,
  #costs-panel > #costs-list {
    flex-shrink: 0;
  }
  #costs-panel {
    overflow-y: auto;
  }

  /* Boîte de coûts (réutilisée pour total et chaque nœud) */
  .costs-box {
    background: var(--bg-panel);
    border: 1px solid var(--border-panel);
    border-radius: 6px;
    margin: 10px 12px;
    box-shadow: 0 1px 3px var(--shadow-panel);
    overflow: hidden;
  }
  .costs-box.costs-total {
    border: 2px solid var(--text-accent);
    position: sticky;
    top: 0;
    z-index: 5;
    margin-top: 12px;
  }

  .costs-box-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    background: var(--bg-modal-source);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-accent);
    border-bottom: 1px solid var(--border-modal-divider);
  }

  /* Icône $ à gauche du titre — ouvre les coûts uniques de l'entité */
  .costs-self-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg-header);
    color: white;
    font-size: 12px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 6px;
    transition: transform 0.1s, background 0.15s;
    line-height: 1;
  }
  .costs-self-icon:hover {
    background: var(--bg-header-btn-hover);
    transform: scale(1.12);
  }
  .costs-self-icon:focus { outline: 2px solid var(--bg-header-btn-hover); outline-offset: 1px; }

  /* Wrapper texte du titre (à droite de l'icône $) — pour que l'ellipsis fonctionne */
  .costs-box-title-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  /* Accordéon générique pour les sources dans le panneau coûts */
  .costs-sources-accordion {
    border-top: 1px solid var(--border-modal-divider);
  }
  .costs-sources-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 7px 12px;
    background: var(--bg-page);
    color: var(--text-muted);
    border: none;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
  }
  .costs-sources-toggle:hover { color: var(--text-default); }
  .costs-sources-toggle .arrow { font-size: 9px; transition: transform 0.15s; }
  .costs-sources-accordion.open .costs-sources-toggle .arrow { transform: rotate(180deg); }
  .costs-sources-content {
    display: none;
    padding: 6px 12px 9px 12px;
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.45;
    background: var(--bg-page);
    border-top: 1px dashed var(--border-modal-divider);
  }
  .costs-sources-accordion.open .costs-sources-content { display: block; }

  /* Note grisâtre — info contextuelle non chiffrée (case désactivée) */
  .costs-info-note {
    margin: 10px 12px;
    padding: 10px 12px;
    background: var(--bg-modal-source);
    border: 1px dashed var(--border-modal-divider);
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-muted);
    font-style: italic;
  }
  .costs-info-note strong { color: var(--text-default); font-style: normal; }
  .costs-total .costs-box-title {
    background: var(--text-accent);
    color: white;
    font-size: 13px;
  }
  .costs-count-badge {
    background: rgba(255,255,255,0.2);
    color: inherit;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
  }
  .costs-box:not(.costs-total) .costs-count-badge {
    background: var(--border-panel);
    color: var(--text-default);
  }

  .costs-box-rows {
    padding: 6px 12px;
  }
  .costs-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    padding: 4px 0;
    font-size: 12px;
    line-height: 1.3;
    border-bottom: 1px dashed transparent;
  }
  .costs-row + .costs-row {
    border-top: 1px dashed var(--border-modal-divider);
  }
  .costs-row.costs-row-total {
    border-top: 2px solid var(--text-accent);
    margin-top: 4px;
    padding-top: 7px;
    font-weight: 700;
    font-size: 13px;
  }
  .costs-row-label {
    color: var(--text-default);
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .costs-row-label .dq-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
  }
  .costs-row-label .dq-dot.dq-verified { background: #2e7d32; }
  .costs-row-label .dq-dot.dq-partial { background: #f9a825; }
  .costs-row-label .dq-dot.dq-approximate { background: #c2185b; }
  .costs-row-label .dq-dot.dq-structural { background: #999; }

  .costs-row-value {
    color: var(--text-accent);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
  }
  .costs-row-count {
    color: var(--text-muted);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    margin-left: 4px;
    font-weight: 400;
  }

  .costs-box-note {
    padding: 6px 12px 9px 12px;
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.4;
    border-top: 1px solid var(--border-modal-divider);
    background: var(--bg-page);
  }

  /* Boîte par nœud (compact, header cliquable) */
  .costs-box.costs-node .costs-box-title {
    cursor: pointer;
    user-select: none;
  }
  .costs-box.costs-node .costs-box-title:hover {
    background: var(--border-modal-divider);
  }
  /* En mode collapsed, on cache TOUT sauf le titre (avec icône $ et badge employés)
     pour condenser au maximum la liste — rangées de coûts, note, chemin et accordéon sources. */
  .costs-box.costs-node.collapsed .costs-box-rows,
  .costs-box.costs-node.collapsed .costs-box-note,
  .costs-box.costs-node.collapsed .costs-node-path,
  .costs-box.costs-node.collapsed .costs-sources-accordion {
    display: none;
  }
  .costs-box.costs-node .costs-box-title::after {
    content: "▾";
    font-size: 10px;
    margin-left: 6px;
    color: var(--text-muted);
  }
  .costs-box.costs-node.collapsed .costs-box-title::after {
    content: "▸";
  }

  .costs-node-path {
    font-size: 10px;
    color: var(--text-muted);
    padding: 0 12px 4px 12px;
    font-style: italic;
    line-height: 1.3;
  }

  /* Légende */
  #costs-legend {
    margin: 4px 12px 10px 12px;
    padding: 8px 10px;
    background: var(--bg-panel);
    border: 1px solid var(--border-panel);
    border-radius: 6px;
    font-size: 10px;
    line-height: 1.5;
  }
  .costs-legend-title {
    font-weight: 600;
    color: var(--text-accent);
    margin-bottom: 4px;
    /* Layout : titre à gauche, bouton portefeuille à droite */
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
  }

  /* Bouton portefeuille — toggle du mode "flux d'argent" */
  #money-flow-toggle {
    background: transparent;
    border: 1px solid var(--border-panel);
    border-radius: 6px;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
    line-height: 1;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
    color: var(--text-default);
  }
  #money-flow-toggle:hover {
    background: rgba(46, 125, 50, 0.10);
    border-color: #43a047;
    transform: scale(1.06);
  }
  #money-flow-toggle.active {
    background: #43a047;
    border-color: #2e7d32;
    box-shadow: 0 0 0 2px rgba(67, 160, 71, 0.35);
  }
  body.dark #money-flow-toggle:hover {
    background: rgba(102, 187, 106, 0.18);
    border-color: #66bb6a;
  }
  body.dark #money-flow-toggle.active {
    background: #2e7d32;
    border-color: #66bb6a;
    box-shadow: 0 0 0 2px rgba(102, 187, 106, 0.45);
  }
  .costs-legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-default);
  }
  .dq-pill {
    font-size: 10px;
  }
  .dq-pill.dq-verified { color: #2e7d32; }
  .dq-pill.dq-partial { color: #f9a825; }
  .dq-pill.dq-approximate { color: #c2185b; }
  .dq-pill.dq-structural { color: #999; }

  /* État vide */
  .costs-empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
  }

  /* Mobile: panneau plein écran */
  @media (max-width: 600px) {
    #costs-panel {
      width: 100%;
      max-width: 100vw;
    }
  }

  /* === PANNEAU RÉSULTATS DE RECHERCHE === */
