/* ==========================================================================
   POLYGON 2027 — Design System
   Minimalisme Suisse Épuré : Axes Diamétraux Bipolaires & Neutre au Centre
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --bg-base: #ffffff;
  --bg-surface: #f8fafc;
  --bg-glass: rgba(255, 255, 255, 0.96);
  
  --border-light: #e2e8f0;
  --border-subtle: #cbd5e1;
  --border-strong: #94a3b8;

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  
  --cand-blue: #2563eb;
  --cand-green: #059669;
  --cand-purple: #7c3aed;
  --cand-amber: #d97706;

  --header-height: 56px;
  --sidebar-width: 230px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-display: 'Space Grotesk', sans-serif;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   HEADER : TOUJOURS VISIBLE ET CLAIR
   ========================================================================== */
.header {
  position: relative;
  z-index: 100;
  height: var(--header-height);
  border-bottom: 2px solid var(--border-light);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-icon {
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-primary);
  display: grid;
  place-items: center;
  transform: rotate(45deg);
}

.brand-icon::after {
  content: '';
  width: 5px;
  height: 5px;
  background: var(--cand-blue);
}

.brand-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Switcher Synthèse / Détaillé Ultra-Visible */
.header-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.header-nav::-webkit-scrollbar {
  display: none;
}

.mode-toggle-group {
  display: inline-flex;
  padding: 3px;
  background: #e2e8f0;
  border-radius: 8px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
}

.mode-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 180ms var(--ease-out);
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-toggle-btn:hover {
  color: var(--text-primary);
}

.mode-toggle-btn.active {
  background: #ffffff;
  color: var(--cand-blue);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.mode-toggle-btn .badge-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 6px;
  background: #f1f5f9;
  border-radius: 9999px;
  color: var(--text-secondary);
}

.mode-toggle-btn.active .badge-pill {
  background: #eff6ff;
  color: var(--cand-blue);
  font-weight: 700;
}

/* Boutons d'Action Header */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-action {
  background: #ffffff;
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 180ms var(--ease-out);
}

.btn-action:hover {
  border-color: var(--border-subtle);
  background: #f8fafc;
}

.btn-primary {
  background: var(--text-primary);
  color: #ffffff;
  border-color: var(--text-primary);
}

.btn-primary:hover {
  background: #1e293b;
  color: #ffffff;
}

/* ==========================================================================
   LAYOUT PRINCIPAL
   ========================================================================== */
.main-layout {
  flex: 1;
  display: flex;
  width: 100vw;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* ==========================================================================
   BARRE GAUCHE : SÉLECTION COMPACTE DES CANDIDATS (230px)
   ========================================================================== */
.sidebar-left {
  width: var(--sidebar-width);
  border-right: 1px solid var(--border-light);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  user-select: none;
}

.sidebar-header {
  padding: 12px 14px 10px 14px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.sidebar-scroll-hint {
  font-size: 11px;
  color: var(--cand-blue);
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}

.candidates-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scrollbar-width: thin;
}

.candidates-list::-webkit-scrollbar {
  width: 4px;
}
.candidates-list::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 2px;
}

/* Item Candidat Minimaliste */
.cand-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
  position: relative;
}

.cand-item:hover {
  background: #ffffff;
  border-color: var(--border-light);
}

.cand-item.active {
  background: #ffffff;
  border-color: var(--cand-blue);
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.12);
}

.cand-item.user-item {
  background: #f8fafc;
  border: 1px solid #bfdbfe;
  margin-bottom: 4px;
}

.cand-item.user-item:hover {
  background: #eff6ff;
  border-color: #3b82f6;
}

.cand-item.user-item.active {
  background: #eff6ff;
  border-color: #2563eb;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.18);
}

.cand-item-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-light);
  flex-shrink: 0;
}

.cand-item-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.cand-item.active .cand-item-name {
  color: var(--cand-blue);
  font-weight: 600;
}

.cand-item-affinity {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  background: #f1f5f9;
  color: #64748b;
  flex-shrink: 0;
}

.cand-item-affinity.high {
  background: #ecfdf5;
  color: #059669;
}

.cand-item-affinity.mid {
  background: #eff6ff;
  color: #2563eb;
}

.candidates-divider {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: 0.05em;
  padding: 6px 10px 2px 10px;
  border-top: 1px solid var(--border-light);
  margin-top: 4px;
}

.cand-item-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: transparent;
}

/* ==========================================================================
   ARÈNE CENTRALE : LE POLYGONE PREND TOUT L'ESPACE
   ========================================================================== */
.radar-arena {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #ffffff;
}

#radar-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Raccourci Flottant pour Basculer vers Mode Détaillé */
.floating-mode-pill {
  position: absolute;
  top: 16px;
  right: 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  padding: 6px 14px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--cand-blue);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 180ms var(--ease-out);
}

.floating-mode-pill:hover {
  background: #ffffff;
  border-color: var(--cand-blue);
  transform: translateY(-1px);
}

/* Carte Flottante Discrète du Candidat */
.floating-candidate-card {
  position: absolute;
  top: 16px;
  left: 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  pointer-events: none;
}

.floating-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid #ffffff;
}

.floating-name {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.floating-sub {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Tooltip Interactif & Paliers Dynamiques */
.radar-tooltip {
  position: absolute;
  z-index: 100;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 14px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -110%) scale(0.96);
  transition: opacity 120ms ease, transform 120ms ease;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
  width: max-content;
  max-width: 310px;
}

.radar-tooltip.visible {
  opacity: 1;
  transform: translate(-50%, -115%) scale(1);
}

.tooltip-title {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tooltip-cat {
  font-weight: 500;
  font-size: 10px;
  color: #64748b;
}

.tooltip-score {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--cand-blue);
  margin-bottom: 6px;
}

/* Tier Card à l'intérieur du Tooltip */
.tooltip-tier-card {
  margin: 6px 0;
  padding: 7px 9px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.tooltip-tier-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.tooltip-tier-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 4px;
}

.tier-modere {
  background: #e0f2fe;
  color: #0284c7;
}

.tier-affirme {
  background: #dbeafe;
  color: #2563eb;
}

.tier-rupture {
  background: #fee2e2;
  color: #dc2626;
}

.tier-neutral {
  background: #f1f5f9;
  color: #64748b;
}

.tooltip-tier-score {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: #64748b;
}

.tooltip-tier-desc {
  font-size: 10.5px;
  color: #1e293b;
  line-height: 1.35;
  font-weight: 500;
}

.tooltip-poles {
  font-size: 10px;
  color: #64748b;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-weight: 600;
  border-top: 1px solid #f1f5f9;
  padding-top: 4px;
}

.tooltip-desc {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 4px;
  line-height: 1.3;
}

/* Tiroir Sliders : description et badge de palier */
.slider-tier-hint {
  font-size: 10px;
  color: #475569;
  line-height: 1.35;
  min-height: 28px;
  padding: 5px 8px;
  background: #f8fafc;
  border-radius: 5px;
  border: 1px solid #e2e8f0;
  margin-top: 2px;
}

.tier-pill {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 1px 5px;
  border-radius: 3px;
}

/* Dock Flottant Mode Matching (Toutes les Affinités) */
.matching-dock {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  z-index: 20;
}

.matching-dock-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.matching-pills-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 2px 0;
  max-width: 66vw;
}

.matching-pills-scroll::-webkit-scrollbar {
  height: 4px;
}

.matching-pills-scroll::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 2px;
}

.matching-rank-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 140ms ease;
}

.matching-rank-pill:hover {
  border-color: var(--cand-blue);
  background: #f8fafc;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.matching-rank-pill.top-match {
  border-color: #10b981;
  background: #f0fdf4;
}

.matching-rank-pill .rank-num {
  font-size: 9px;
  font-weight: 700;
  color: #94a3b8;
  font-family: var(--font-mono);
}

.matching-rank-pill.top-match .rank-num {
  color: #059669;
}

.matching-rank-pill strong {
  font-family: var(--font-mono);
  font-size: 11px;
}

.matching-rank-pill.top-match strong {
  color: #059669;
}

.matching-rank-pill.mid-match strong {
  color: var(--cand-blue);
}

.matching-rank-pill.low-match strong {
  color: #64748b;
}

/* Tiroir Sliders */
.slider-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid var(--border-subtle);
  padding: 16px 28px;
  z-index: 50;
  transform: translateY(100%);
  transition: transform 300ms var(--ease-out);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.06);
  max-height: 38vh;
  overflow-y: auto;
}

.slider-drawer.open {
  transform: translateY(0);
}

.slider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.slider-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  gap: 8px;
  line-height: 1.25;
}

.slider-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #e2e8f0;
  outline: none;
  cursor: pointer;
}

.slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cand-blue);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.3);
}

/* Modale Export */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  width: 90%;
  max-width: 480px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
}

.export-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.export-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Légende Visuelle d'Interprétation */
.radar-legend-bar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 18px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-light);
  border-radius: 9999px;
  padding: 6px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
  z-index: 20;
  pointer-events: none;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-box {
  width: 14px;
  height: 10px;
  border-radius: 2px;
}

.legend-color-box {
  background: var(--cand-blue);
  opacity: 0.85;
}

.legend-hatch-box {
  background: repeating-linear-gradient(
    -45deg,
    #f1f5f9,
    #f1f5f9 2px,
    #94a3b8 2px,
    #94a3b8 4px
  );
  border: 1px dashed #94a3b8;
}
