/* ═══════════════════════════════════════════════
   Tokens
   ═══════════════════════════════════════════════ */
:root {
  /* --split-x: calc(((100vw - 1170px) / 2) + (1170px * 0.4)); */
  --split-x: 0px;
  --split-offset: 0px; /* mis à jour par JS : window.innerHeight × tan(12°) */
  /* ── Couleurs ───────────────────────────────── */
  --color-primary:    #348BCB;
  --color-accent:     #EA5755;
  --color-orange:     #EF7C25;
  --color-text:       #303133;
  --color-bg:         #F6F6F6;
  --color-surface:    #ffffff;
  --color-border:     #E3E4E7;
  --color-muted:      #AAACB0;
  --color-hover-bg:   #EAF3FB;
  --color-asso-tint:  rgba(52, 140, 203, 0.44);

  /* ── Typographie ────────────────────────────── */
  --fs-2xs:  0.5625rem;   /*  9px */
  --fs-xs:   0.6875rem;   /* 11px */
  --fs-sm:   0.75rem;     /* 12px */
  --fs-base: 0.8125rem;   /* 13px */
  --fs-md:   0.875rem;    /* 14px */
  --fs-lg:   1rem;        /* 16px */
  --fs-2xl:  1.5rem;      /* 24px */

  --font-base: 'Helvetica Neue', Helvetica, Arial, sans-serif;

  /* ── Espacement ─────────────────────────────── */
  --sp-1: 0.25rem;    /*  4px */
  --sp-2: 0.375rem;   /*  6px */
  --sp-3: 0.5rem;     /*  8px */
  --sp-4: 0.625rem;   /* 10px */
  --sp-5: 0.875rem;   /* 14px */
  --sp-6: 1rem;       /* 16px */
  --sp-7: 1.125rem;   /* 18px */
  --sp-8: 1.75rem;    /* 28px */

  /* ── Bordures ───────────────────────────────── */
  --radius-sm:   0.25rem;
  --radius-md:   0.375rem;
  --radius-lg:   0.625rem;
  --radius-full: 9999px;

  /* ── Mise en page ───────────────────────────── */
  --sidebar-w: 18rem;
  --panel-w:   18rem;
  --globe-sz:  37.5rem;    /* 600px */
}

/* ═══════════════════════════════════════════════
   Dark mode
   ═══════════════════════════════════════════════ */
[data-theme="dark"] {
  --color-primary:   #5BAEE0;
  --color-accent:    #FF6B68;
  --color-orange:    #FF8C42;
  --color-text:      #D8ECF8;
  --color-bg:        #020818;
  --color-surface:   #071428;
  --color-border:    #112240;
  --color-muted:     #4A7A9B;
  --color-hover-bg:  #0d2540;
  --color-asso-tint: rgba(91, 174, 224, 0.35);
}

/* ═══════════════════════════════════════════════
   Reset & base (scopé au conteneur du plugin)
   ═══════════════════════════════════════════════ */
.globe-assoc-container *,
.globe-assoc-container *::before,
.globe-assoc-container *::after { margin: 0; padding: 0; box-sizing: border-box; }

.globe-assoc-container {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100vh;
  background: radial-gradient(ellipse at 50% 40%, #0a1e3d 0%, #020818 70%);
  display: flex;
  align-items: stretch;
  justify-content: center;
  font-family: var(--font-base);
  color: var(--color-text);
}


/* Permettre de cliquer "à travers" les couches de structure */
.theme-layer,
.globe-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.globe-layer { z-index: 3; pointer-events: none;}

/* Réactiver les clics uniquement sur les éléments utiles */
.asso-sidebar,
.info-panel,
.globe-wrap,
.theme-toggle,
.split-line,
.moon-globe-wrap {
  pointer-events: auto;
}

/* Appliquer le découpage sur la zone sombre (gauche) */
#layer-dark {
  clip-path: polygon(
    0 0, 
    var(--split-x) 0, 
    calc(var(--split-x) - var(--split-offset)) 100%, 
    0 100%
  );
  z-index: 2;
}

/* Appliquer le découpage sur la zone claire (droite) */
#layer-light {
  clip-path: polygon(
    var(--split-x) 0,
    100% 0,
    100% 100%,
    calc(var(--split-x) - var(--split-offset)) 100%
  );
  z-index: 1;
  background: var(--color-surface);
}

#layer-dark {
  --color-primary:   #5BAEE0;
  --color-accent:    #FF6B68;
  --color-orange:    #FF8C42;
  --color-text:      #D8ECF8;
  --color-surface:   #071428;
  --color-border:    #112240;
  --color-muted:     #4A7A9B;
  --color-hover-bg:  #0d2540;
  --color-asso-tint: rgba(91, 174, 224, 0.35);
}

#layer-light {
  --color-primary:    #348BCB;
  --color-accent:     #EA5755;
  --color-orange:     #EF7C25;
  --color-text:       #303133;
  --color-surface:    #ffffff;
  --color-border:     #f0f6ff;
  --color-muted:      #AAACB0;
  --color-hover-bg:   #EAF3FB;
  --color-asso-tint:  rgba(52, 140, 203, 0.44);
}

.globe-wrap,
.info-panel {
  color: var(--color-text);
}


/* ═══════════════════════════════════════════════
   Étoiles (dark mode)
   ═══════════════════════════════════════════════ */
#stars {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 1;
  z-index: 0;
}

/* ═══════════════════════════════════════════════
   Bouton thème (mobile uniquement)
   ═══════════════════════════════════════════════ */
.theme-toggle { display: none; } /* caché sur desktop — le split remplace le toggle */

/* Icône du bouton toggle — changée via content, pas via display */
.toggle-icon::before              { content: '✦'; }
[data-theme="light"] .toggle-icon::before { content: '☀︎'; }
[data-theme="dark"]  .toggle-icon::before { content: '✦'; }

/* ═══════════════════════════════════════════════
   Scène (grille principale)
   ═══════════════════════════════════════════════ */
.scene {
  position: relative;
  margin: auto;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w) var(--panel-w);
  align-items: center;
  width: 100%;
  max-width:1170px;
  min-height: 100%;
}

/* ═══════════════════════════════════════════════
   Sidebar
   ═══════════════════════════════════════════════ */
.asso-sidebar {
  height: min(var(--globe-sz), 72vh);
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding-left: var(--sp-8);
  overflow: hidden;
}

.sidebar-title {
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-muted);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--sp-4);
  flex-shrink: 0;
}

.search-box {
  width: 100%;
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-base);
  font-family: var(--font-base);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  margin-bottom: var(--sp-4);
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.3s;
}
.search-box::placeholder { color: var(--color-muted); }
.search-box:focus         { border-color: var(--color-primary); }

.search-count {
  font-size: 0.8rem;
  opacity: 0.7;
  margin: var(--sp-1) var(--sp-4);
}

#layer-dark .search-box {
  backdrop-filter: blur(0.5rem);
}

.sidebar-scroll {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: var(--sp-1);
}
.sidebar-item:hover                { background: var(--color-hover-bg); }
.sidebar-item.active               { background: var(--color-primary); }
.sidebar-item.active .sidebar-logo { background: rgba(255,255,255,0.2); color: #fff; }
.sidebar-item.active .sidebar-name { color: #fff; }

.sidebar-logo {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-sm);
  background: var(--color-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-2xs);
  font-weight: 800;
  color: var(--color-muted);
}

.sidebar-name {
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--color-text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.sidebar-badge {
  font-size: var(--fs-xs);
  font-weight: 700;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-full);
  padding: 0.125rem var(--sp-2);
  flex-shrink: 0;
  opacity: 0.65;
}
.sidebar-item.active .sidebar-badge {
  background: rgba(255,255,255,0.3);
  opacity: 1;
}

/* ═══════════════════════════════════════════════
   Globe
   ═══════════════════════════════════════════════ */
.globe-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-8);
}

.loader-wrap {
  position: relative;
  width: min(var(--globe-sz), 100%);
  aspect-ratio: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas#globe {
  border-radius: 50%;
  display: block;
  /* width: 100%;
  height: 100%; */
  cursor: grab;
  touch-action: none;
  box-shadow:
    0 0 3.75rem rgba(91, 174, 224, 0.3),
    0 0 7.5rem rgba(91, 174, 224, 0.12),
    0 0.125rem 0.5rem rgba(0, 0, 0, 0.6);
  transition: box-shadow 0.4s;
}
canvas#globe:active { cursor: grabbing; }

/* ═══════════════════════════════════════════════
   Trait de séparation draggable
   ═══════════════════════════════════════════════ */
/* .split-line {
  position: absolute;
  top: 0;
  left: calc(var(--split-x) - 10px);
  width: 20px;
  height: 100%;
  z-index: 9000;
  cursor: col-resize;
  transform-origin: top left;
  transform: skewX(-12deg);
}

.split-line::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 0;
  width: 2px;
  height: 100%;
  background: rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.25);
  transition: background 0.2s, box-shadow 0.2s;
}

.split-line::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 36px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  transition: background 0.2s, transform 0.2s;
}

.split-line:hover::before,
.split-line.dragging::before {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
}
.split-line:hover::after,
.split-line.dragging::after {
  transform: translateY(-50%) scaleX(1.2);
  background: #ffffff;
} */

/* ═══════════════════════════════════════════════
   Légende
   ═══════════════════════════════════════════════ */
.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-2) var(--sp-5);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-xs);
  color: var(--color-muted);
  white-space: nowrap;
}

.legend-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.legend-dot--asso       { background: var(--color-asso-tint); border: 1.5px solid var(--color-primary); }
.legend-dot--selected   { background: var(--color-accent); }
.legend-dot--hover-asso { background: var(--color-primary); }
.legend-dot--hover-no   { background: var(--color-orange); }

/* ═══════════════════════════════════════════════
   Panneau info
   ═══════════════════════════════════════════════ */
.info-panel {
  height: min(var(--globe-sz), 72vh);
  width: var(--panel-w);
  overflow-y: auto;
  /* background: var(--color-surface); */
  /* border: 1px solid var(--color-border); */
  /* border-radius: var(--radius-lg); */
  padding: var(--sp-7);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  margin-left: var(--sp-6);
  align-self: center;
  transition: background 0.3s, border-color 0.3s;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

/* [data-theme="dark"] .info-panel {
  background: rgba(7, 20, 40, 0.85);
  backdrop-filter: blur(0.5rem);
  -webkit-backdrop-filter: blur(0.5rem);
} */

.info-panel.empty {
  opacity: 0.5;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.panel-hint {
  font-size: var(--fs-md);
  color: var(--color-muted);
  line-height: 1.6;
}

.panel-country {
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--color-primary);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--sp-4);
}

.panel-count {
  font-size: var(--fs-base);
  color: var(--color-muted);
  margin-top: calc(-1 * var(--sp-2));
}
.panel-count strong {
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--color-primary);
  display: block;
  line-height: 1;
  margin-bottom: var(--sp-1);
}

.asso-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.asso-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.asso-logo {
  width: 1.875rem;
  height: 1.875rem;
  border-radius: var(--radius-sm);
  background: var(--color-hover-bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 800;
  color: var(--color-primary);
}

.asso-info { flex: 1; min-width: 0; }

.asso-name {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.asso-tags {
  font-size: var(--fs-base);
  color: var(--color-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-no-asso {
  font-size: var(--fs-base);
  color: var(--color-muted);
  line-height: 1.6;
}

/* ── Vue association sélectionnée ─────────────── */
.panel-asso-name {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.4;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--sp-4);
}

.panel-asso-tags {
  font-size: var(--fs-sm);
  color: var(--color-primary);
  font-weight: 500;
  margin-top: calc(-1 * var(--sp-2));
}

.panel-asso-types {
  font-size: var(--fs-base);
  color: var(--color-muted);
  line-height: 1.5;
  margin-top: calc(-1 * var(--sp-2));
}

.panel-section-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
}

/* ── Chips pays cliquables ────────────────────── */
.panel-countries-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-2);
}

.country-chip {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--color-primary);
  background: var(--color-hover-bg);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1.5;
  user-select: none;
}
.country-chip:hover,
.country-chip.active {
  background: var(--color-primary);
  color: #fff;
}

/* ── Items asso cliquables dans le panel ──────── */
.asso-clickable {
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  padding: var(--sp-1) var(--sp-2);
  margin: calc(-1 * var(--sp-1)) calc(-1 * var(--sp-2));
}
.asso-clickable:hover { background: var(--color-hover-bg); }

.asso-countries-badge {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-hover-bg);
  border-radius: var(--radius-full);
  padding: var(--sp-1) var(--sp-2);
  flex-shrink: 0;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════
   Globe lunaire décoratif
   ═══════════════════════════════════════════════ */
.moon-globe-wrap {
  position: absolute;
  top: 4.5rem;           /* sous le bouton thème */
  left: -2rem;          /* partiellement hors-écran → effet "peeking" */
  z-index: 500;
  width: 10rem;          /* 160px — doit correspondre à SIZE dans moon.js */
  height: 10rem;
  border-radius: 50%;
  overflow: hidden;
  cursor: grab;
  opacity: 0.3;
  box-shadow:
    inset -0.375rem 0 1.75rem rgba(0, 0, 0, 0.4),
    0 0.375rem 2rem rgba(0, 0, 0, 0.22);
  transition: left 0.65s cubic-bezier(0.25, 0.8, 0.25, 1),
              opacity 0.4s,
              box-shadow 0.4s;
}

/* Au survol : le globe glisse pour être entièrement visible */
.moon-globe-wrap:hover {
  /* left: 0.75rem; */
  opacity: 0.95;
}

.moon-globe-wrap:active { cursor: grabbing; }

[data-theme="dark"] .moon-globe-wrap {
  opacity: 0.8;
  box-shadow:
    inset -0.375rem 0 1.75rem rgba(0, 0, 0, 0.5),
    0 0 3.5rem rgba(180, 210, 255, 0.15),
    0 0 7rem  rgba(180, 210, 255, 0.07);
}
[data-theme="dark"] .moon-globe-wrap:hover {
  opacity: 1;
  box-shadow:
    inset -0.25rem 0 1.25rem rgba(0, 0, 0, 0.35),
    0 0 4.5rem rgba(180, 210, 255, 0.28),
    0 0 9rem  rgba(180, 210, 255, 0.13);
}

#moon-globe { display: block; }

/* ═══════════════════════════════════════════════
   Responsive — Tablette  (< 56.25rem / 900px)
   ═══════════════════════════════════════════════ */
@media (max-width: 56.25rem) {
  /* Lune : plus enfoncée sur tablette (écran moins large) */
  .moon-globe-wrap {
    z-index: 0;
    left: -1.5rem;
    opacity: 0.4;
  }
  .moon-globe-wrap:hover {
    left: -1.3rem;
    opacity: 0.5;
  }

  :root {
    --sidebar-w: 8.75rem;  /* 140px */
    --panel-w:   9.375rem; /* 150px */
    --globe-sz:  28rem;    /* 448px */
  }

  .scene {
    padding: var(--sp-8) var(--sp-3);
  }

  .asso-sidebar {
    padding-left: var(--sp-3);
  }

  /* Réduire les gaps dans la sidebar */
  .sidebar-item {
    gap: var(--sp-2);
    padding: var(--sp-2);
  }

  /* Cacher le badge sur tablette pour gagner de la place */
  .sidebar-badge { display: none; }

  .info-panel {
    margin-left: var(--sp-3);
    padding: var(--sp-5);
  }
}

/* ═══════════════════════════════════════════════
   Responsive — Mobile  (< 40rem / 640px)
   ═══════════════════════════════════════════════ */
@media (max-width: 40rem) {

  /* ── Container : hauteur auto, flux colonne ── */
  .globe-assoc-container {
    height: auto;
    min-height: 10vh;
    min-height: 100svh;
    overflow: visible;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
  }

  /* ── Light layer masqué par défaut (mode dark par défaut sur mobile) ── */
  #layer-light { display: none; }

  /* ── Bouton toggle dark/light ── */
  .theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    order: 0;
    align-self: flex-end;
    flex-shrink: 0;
    margin: 5rem var(--sp-4) 0;
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 2rem;
    line-height: 1;
    transition: background 0.2s, border-color 0.2s;
    z-index: 10;
  }

  [data-theme="dark"] .theme-toggle { color: #fdd346; }
  [data-theme="light"] .theme-toggle { color: #333; }

  /* ── Light mode actif : swap vers le layer light ── */
  [data-theme="light"] #layer-dark  { display: none; }
  [data-theme="light"] #layer-light {
    display: block;
    position: relative;
    inset: auto;
    clip-path: none;
    order: 2;
    background: var(--color-surface);
  }

  /* ── Light mode : fond clair sur la zone globe, étoiles masquées ── */
  [data-theme="light"] .globe-layer { background: var(--color-surface); }
  [data-theme="light"] .globe-assoc-container { background: var(--color-surface); }
  [data-theme="light"] #stars { display: none; }

  /* ── Layers sortis du flux absolu ── */
  .globe-layer {
    position: relative;
    inset: auto;
    order: 1;
    flex-shrink: 0;
  }

  #layer-dark {
    position: relative;
    inset: auto;
    clip-path: none;
    order: 2;
  }

  /* ── Placeholders inutiles en layout colonne ── */
  .globe-placeholder,
  .sidebar-placeholder,
  .panel-placeholder { display: none; }

  :root {
    --globe-sz:  min(88vw, 22rem);
    --panel-w:   100%;
    --sidebar-w: 100%;
  }

  .scene {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    align-items: start;
    padding: var(--sp-5) var(--sp-4);
    gap: var(--sp-5);
    min-height: unset;
    padding-bottom: var(--sp-8);
  }

  /* Globe : centré, largeur fluide */
  .loader-wrap {
    width: min(88vw, 22rem);
    margin: 0 auto;
  }

  /* Légende : compacte */
  .legend { gap: var(--sp-2) var(--sp-3); }
  .legend-item { font-size: 0.625rem; }

  /* Panel : pleine largeur, hauteur auto */
  .info-panel {
    width: 100%;
    height: auto;
    max-height: 32rem;
    margin-left: 0;
    align-self: stretch;
  }

  /* Sidebar : pleine largeur */
  .asso-sidebar {
    width: 100%;
    height: auto;
    max-height: 20rem;
    padding-left: 0;
    padding-top: var(--sp-5);
    border-top: 1px solid var(--color-border);
    overflow: hidden;
  }

  .sidebar-scroll { display: block; }

  /* Chips pays : taille réduite */
  .country-chip {
    font-size: var(--fs-xs);
    padding: 0.125rem var(--sp-2);
  }

  /* Canvas background par thème — fallback avant init JS */
  canvas#globe                         { background: #040f24; }
  [data-theme="light"] canvas#globe    { background: #f0f6ff; }
}
