/* Module 2 : panneau graphique flottant. Préfixe gc- ; couleurs issues des variables de style.css. */

.gc-panel {
  --gc-vu: #2563eb;
  --gc-ve: #ea580c;
  --gc-thr: #b91c1c;
  /* Scénarios : tendance actuelle (gris), SSP1-2.6 (vert), SSP2-4.5 (violet), SSP5-8.5 (rose).
     Distincts du bleu (vertical) et de l'orange (horizontal) ; le motif de trait les distingue aussi. */
  --gc-scn-base: #4b5563;
  --gc-scn-126: #15803d;
  --gc-scn-245: #7c3aed;
  --gc-scn-585: #be185d;
  --gc-scn-sel: #15803d;

  position: fixed;
  z-index: 20;
  left: 0;
  top: 0;
  width: min(440px, calc(100vw - 16px));
  max-height: min(72vh, 600px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .gc-panel {
    --gc-vu: #60a5fa;
    --gc-ve: #fb923c;
    --gc-thr: #f87171;
    --gc-scn-base: #9ca3af;
    --gc-scn-126: #4ade80;
    --gc-scn-245: #a78bfa;
    --gc-scn-585: #f472b6;
    --gc-scn-sel: #4ade80;
  }
}

:root[data-theme="dark"] .gc-panel {
  --gc-vu: #60a5fa;
  --gc-ve: #fb923c;
  --gc-thr: #f87171;
  --gc-scn-base: #9ca3af;
  --gc-scn-126: #4ade80;
  --gc-scn-245: #a78bfa;
  --gc-scn-585: #f472b6;
  --gc-scn-sel: #4ade80;
}

.gc-panel[hidden] { display: none; }

/* ---------- En-tête (poignée de déplacement) ---------- */

.gc-head {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 16px 10px 8px 14px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.gc-panel.is-dragging .gc-head { cursor: grabbing; }

.gc-grip {
  position: absolute;
  top: 6px;
  left: 50%;
  width: 36px;
  height: 4px;
  margin-left: -18px;
  border-radius: 2px;
  background: var(--line);
}

.gc-titles { flex: 1 1 auto; min-width: 0; }

.gc-title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gc-sub {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.gc-sub[hidden] { display: none; }

.gc-acts { display: flex; gap: 2px; flex: 0 0 auto; }

.gc-icon {
  appearance: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.gc-icon:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--ink); }

.gc-icon:focus-visible,
.gc-btn:focus-visible,
.gc-seg button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Corps ---------- */

.gc-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 14px 12px;
  overscroll-behavior: contain;
}

.gc-body[hidden] { display: none; }

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

.gc-note {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-soft);
}

.gc-state {
  margin: 8px 0 4px;
  font-size: 13px;
  color: var(--ink-soft);
}

.gc-state[hidden],
.gc-summary[hidden],
.gc-toolbar[hidden],
.gc-chart[hidden],
.gc-key[hidden],
.gc-sim[hidden],
.gc-impact[hidden] { display: none; }

.gc-title:focus { outline: none; } /* focus posé par le code à l'ouverture (Échap), pas par l'utilisateur */

.gc-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  margin: 2px 0 8px;
}

.gc-cell {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  min-width: 0;
}

.gc-cell dt {
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gc-cell dd {
  margin: 1px 0 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.gc-cell dd small {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-soft);
}

.gc-val-vu { color: var(--gc-vu); }
.gc-val-ve { color: var(--gc-ve); }

/* ---------- Barre d'outils ---------- */

.gc-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.gc-seg {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.gc-seg button {
  appearance: none;
  border: 0;
  padding: 5px 10px;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.gc-seg button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.gc-seg button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.gc-btn {
  appearance: none;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.gc-btn:hover { border-color: var(--accent); color: var(--accent); }
.gc-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Graphique ---------- */

.gc-chart {
  position: relative;
  width: 100%;
  margin-top: 6px;
}

.gc-svg {
  display: block;
  max-width: 100%;
  height: auto;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.gc-svg text {
  font-size: 10.5px;
  fill: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.gc-grid { stroke: var(--line); stroke-width: 1; }
.gc-axis { stroke: var(--ink-soft); stroke-width: 1; opacity: 0.6; }
.gc-zero { stroke: var(--ink-soft); stroke-width: 1; opacity: 0.45; }

.gc-s-vu { color: var(--gc-vu); }
.gc-s-ve { color: var(--gc-ve); }

.gc-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.gc-dot { fill: currentColor; }

.gc-reg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-dasharray: 5 4;
  opacity: 0.8;
}

.gc-ext {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-dasharray: 1.5 3.5;
  stroke-linecap: round;
  opacity: 0.85;
}


.gc-mk {
  fill: var(--surface);
  stroke: currentColor;
  stroke-width: 1.6;
}

.gc-mk.is-cur { fill: currentColor; }

.gc-thr {
  stroke: var(--gc-thr);
  stroke-width: 1.2;
  stroke-dasharray: 6 3;
  opacity: 0.85;
}

.gc-thr-t { fill: var(--gc-thr) !important; font-weight: 600; }

.gc-yr {
  stroke: var(--gc-thr);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  opacity: 0.8;
}

.gc-guide {
  stroke: var(--ink-soft);
  stroke-width: 1;
  stroke-dasharray: 2 2;
}

.gc-hit { fill: transparent; cursor: crosshair; }

.gc-tip {
  position: absolute;
  top: 2px;
  left: 0;
  z-index: 1;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.gc-tip[hidden] { display: none; }
.gc-tip-date { font-weight: 600; margin-bottom: 2px; }
.gc-tip-row b { font-weight: 600; }

/* ---------- Légende ---------- */

.gc-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--ink-soft);
}

.gc-kitem { display: inline-flex; align-items: center; }
.gc-unit { margin-left: auto; }

.gc-sw {
  display: inline-block;
  width: 18px;
  margin-right: 6px;
  border-top: 2px solid var(--ink-soft);
  vertical-align: middle;
}

.gc-sw-solid { border-top-style: solid; }
.gc-sw-solid.gc-s-vu { border-top-color: var(--gc-vu); }
.gc-sw-solid.gc-s-ve { border-top-color: var(--gc-ve); }
.gc-sw-dash { border-top-style: dashed; }
.gc-sw-dash.gc-s-vu { border-top-color: var(--gc-vu); }
.gc-sw-dash.gc-s-ve { border-top-color: var(--gc-ve); }
.gc-sw-dot { border-top-style: dotted; border-top-width: 3px; }

/* ---------- Mode simulation ---------- */

.gc-sim {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
}

.gc-warn {
  margin: 0 0 8px;
  padding: 6px 8px;
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  line-height: 1.4;
}

.gc-hz-cap {
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Tableau des horizons (déplacement cumulé, norme) */
.gc-tbl {
  width: 100%;
  margin: 0 0 8px;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.gc-tbl th,
.gc-tbl td {
  padding: 3px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-weight: normal;
  white-space: nowrap;
}

.gc-tbl thead th { color: var(--ink-soft); font-size: 11px; font-weight: 600; }
.gc-tbl .gc-num { text-align: right; }
.gc-tbl tr.is-current th,
.gc-tbl tr.is-current td { background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
.gc-tbl .gc-val-scn { color: var(--gc-scn-sel); }

/* Trajectoires des scénarios : couleur + motif de trait (lisible sans couleur) */
.gc-scn {
  fill: none;
  stroke: var(--gc-scn-col, currentColor);
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.75;
}

.gc-scn.is-sel { stroke-width: 2.6; opacity: 1; }
.gc-scn-grp.is-ve { opacity: 0.5; }

.gc-scn-base { --gc-scn-col: var(--gc-scn-base); }
.gc-scn-ssp126 { --gc-scn-col: var(--gc-scn-126); stroke-dasharray: 1.5 3; }
.gc-scn-ssp245 { --gc-scn-col: var(--gc-scn-245); stroke-dasharray: 7 3 1.5 3; }
.gc-scn-ssp585 { --gc-scn-col: var(--gc-scn-585); stroke-dasharray: 6 3; }

/* Légende des trajectoires : trait court du même motif */
.gc-scn-sw { border-top-style: solid; border-top-width: 2px; border-top-color: var(--gc-scn-col, var(--ink-soft)); }
.gc-scn-sw.gc-scn-base { --gc-scn-col: var(--gc-scn-base); border-top-color: var(--gc-scn-base); }
.gc-scn-sw.gc-scn-ssp126 { border-top-style: dotted; border-top-width: 3px; border-top-color: var(--gc-scn-126); }
.gc-scn-sw.gc-scn-ssp245 { border-top-style: dashed; border-top-color: var(--gc-scn-245); }
.gc-scn-sw.gc-scn-ssp585 { border-top-style: dashed; border-top-width: 3px; border-top-color: var(--gc-scn-585); }

/* Au-delà de 2100 : scénarios non définis */
.gc-beyond { fill: var(--ink-soft); opacity: 0.12; }
.gc-beyond-t { fill: var(--ink-soft) !important; font-style: italic; }
.gc-warn-scn { border-color: var(--danger); background: var(--danger-bg); color: var(--danger-ink); }

.gc-simline { margin: 0 0 4px; line-height: 1.45; }
.gc-simline b { font-variant-numeric: tabular-nums; }

.gc-cls { font-weight: 600; }
.gc-cls-3 { color: var(--danger); }
.gc-cls-2 { color: var(--warn-ink); }

/* ---------- Impact sur les voisins ---------- */

.gc-impact {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.gc-impact-title {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
}

.gc-impact-slot:empty { display: none; }

/* Identifiant H3 : replié par défaut */
.gc-h3 {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.gc-h3 summary { cursor: pointer; }

.gc-h3 code {
  display: block;
  margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

/* ---------- Petit écran : feuille basse, 55 vh maximum, croix toujours visible ---------- */

@media (max-width: 640px) {
  .gc-panel {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 55vh;
  }

  .gc-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .gc-head { padding-left: 12px; }
  .gc-body { padding: 0 12px 10px; }
  .gc-title { font-size: 14px; }
}
