/* ============================================================================
 *  RéseauVision — feuille de style du tableau de bord de supervision.
 *
 *  Organisation :
 *    - Base & variables
 *    - En-tête
 *    - KPIs
 *    - Contrôles (filtres, tri) & légende
 *    - Grille de cartes (lignes)
 *    - États : chargement / erreur / vide
 *
 *  Les couleurs pilotées par la donnée (couleur d'une ligne, remplissage d'une
 *  jauge, etc.) sont posées en style inline par index.js ; ici on ne gère que
 *  la structure et les couleurs fixes.
 * ==========================================================================*/

/* --- Base & variables ----------------------------------------------------- */
:root {
  --bg: #EDEFF3;
  --card: #fff;
  --border: #E1E5EC;
  --ink: #15161C;
  --muted: #8C93A1;
  --muted-2: #7B8290;
  --mono: 'IBM Plex Mono', monospace;
  --sans: Manrope, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
::selection { background: #1b2a5b; color: #fff; }

body {
  min-height: 100vh;
  background: var(--bg);
  font-family: var(--sans);
  color: var(--ink);
  padding-bottom: 60px;
}

.spacer { flex: 1; }
.container { max-width: 1440px; margin: 0 auto; padding: 24px 26px 0; }

/* --- Barre de chargement (style YouTube) ---------------------------------- */
.topbar {
  position: fixed; top: 0; left: 0; z-index: 40;
  height: 3px; width: 0; opacity: 0;
  background: #0FBF6B;
  box-shadow: 0 0 8px rgba(15, 191, 107, .7), 0 0 4px rgba(15, 191, 107, .5);
}

/* --- En-tête -------------------------------------------------------------- */
.header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #DCE0E7;
}
.header-inner {
  max-width: 1440px; margin: 0 auto; padding: 14px 26px;
  display: flex; align-items: center; gap: 16px;
}
.brand-logo {
  width: 42px; height: 42px; border-radius: 11px; background: #0B7A4B;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(11, 122, 75, .3);
}
.brand-logo-ring { width: 18px; height: 18px; border: 3px solid #fff; border-radius: 50%; }
.brand { line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
.brand-name span { color: #0B7A4B; }
.brand-sub {
  font-size: 11px; color: var(--muted-2); font-weight: 600;
  letter-spacing: .02em; text-transform: uppercase;
}
.header-status { display: flex; align-items: center; gap: 18px; }
.status { display: flex; align-items: center; gap: 7px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #C9CED7; }
.status-label { font-size: 12px; font-weight: 600; color: #3A4150; }
.snap { text-align: right; line-height: 1.2; font-family: var(--mono); }
.snap-time { font-size: 13px; font-weight: 600; color: var(--ink); }
.snap-date { font-size: 10px; color: var(--muted); }

/* --- KPIs ----------------------------------------------------------------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px;
}
.kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 18px; position: relative; overflow: hidden;
}
.kpi-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.kpi-label {
  font-size: 11px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted);
}
.kpi-value {
  font-family: var(--mono); font-size: 32px; font-weight: 600;
  margin-top: 6px; letter-spacing: -.02em;
}
.kpi-value.red { color: #D8232A; }
.kpi-value.orange { color: #C26F08; }
.kpi-sub { font-size: 11px; color: var(--muted-2); font-weight: 500; margin-top: 2px; }

/* --- Contrôles & légende -------------------------------------------------- */
.controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px;
}
.chip-group {
  display: flex; gap: 6px; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; padding: 5px;
}
.chip {
  border: none; cursor: pointer; font-family: var(--sans); font-weight: 700;
  font-size: 13px; padding: 7px 13px; border-radius: 8px;
  background: transparent; color: #5A6171; transition: all .12s;
}
.chip.active { background: var(--ink); color: #fff; }
.chip-count { opacity: .6; font-family: var(--mono); font-weight: 500; }

.btn {
  cursor: pointer; font-family: var(--sans); font-weight: 700; font-size: 13px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: #3A4150; transition: all .12s;
}
.btn-toggle { display: flex; align-items: center; gap: 8px; }
.btn-toggle.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.toggle-dot { width: 9px; height: 9px; border-radius: 50%; background: #C9CED7; }
.btn-toggle.active .toggle-dot { background: #FF6B6B; }

.legend {
  display: flex; align-items: center; gap: 18px; margin: 10px 2px 18px;
  font-size: 11px; color: var(--muted); font-weight: 600; flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-bar { width: 16px; height: 7px; border-radius: 99px; }
.legend-bar.green { background: #2FA866; }
.legend-bar.red { background: #D8232A; }
.legend-threshold { width: 2px; height: 13px; background: var(--ink); opacity: .55; }
.legend-sep { color: #B7BDC8; }

/* --- Grille de cartes ----------------------------------------------------- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(345px, 1fr)); gap: 16px;
}
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; display: flex; flex-direction: column;
  box-shadow: 0 1px 2px rgba(20, 22, 28, .03);
}
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.badge {
  width: 46px; height: 46px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 600;
}
.card-title { min-width: 0; flex: 1; }
.card-name { font-weight: 800; font-size: 15px; letter-spacing: -.01em; line-height: 1.2; }
.card-mode {
  font-size: 11px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; margin-top: 1px;
}
.card-tags { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }

/* Info-bouton (coin haut-droit) : ouvre le popover « Top attente » au survol. */
.info-btn {
  flex-shrink: 0; align-self: flex-start;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--border); background: #fff; color: #8C93A1;
  font-family: Georgia, 'Times New Roman', serif; font-style: italic;
  font-weight: 700; font-size: 13px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .12s;
}
.info-btn:hover { border-color: #0B7A4B; color: #0B7A4B; background: #F0FAF5; }

/* Popover « Top attente » — ancré au bouton, purement visuel (survol). */
.popover {
  position: fixed; z-index: 50; display: none;
  width: 300px; max-height: 78vh; overflow: auto;
  background: #fff; border: 1px solid #E1E5EC; border-radius: 14px;
  box-shadow: 0 12px 34px rgba(20, 22, 28, .18);
  padding: 12px; pointer-events: none;
}
.pop-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pop-badge {
  width: 34px; height: 34px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 600; font-size: 13px;
}
.pop-title { font-size: 13px; font-weight: 800; letter-spacing: -.01em; }
.pop-line { font-size: 11px; color: var(--muted); font-weight: 600; margin-top: 1px; }

.pop-list { display: flex; flex-direction: column; }
.pop-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 2px; border-top: 1px solid #F0F2F6;
}
.pop-rank {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 6px;
  background: #F1F3F7; color: #6B7280; font-family: var(--mono);
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.pop-cell { flex: 1; min-width: 0; }
.pop-name {
  font-size: 12.5px; font-weight: 700; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pop-meta { font-size: 10.5px; color: var(--muted); font-weight: 500; margin-top: 1px; }
.pop-wait { flex-shrink: 0; font-family: var(--mono); font-size: 13px; font-weight: 600; }

.pop-state { padding: 22px 6px; text-align: center; color: var(--muted); font-size: 12px; font-weight: 600; }
.pop-foot {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid #F0F2F6;
  font-size: 10px; color: #A6ACB8; font-weight: 600; text-align: right;
}
.niv {
  font-size: 11px; font-weight: 700; padding: 3px 10px;
  border-radius: 99px; white-space: nowrap;
}
.trend { font-size: 10px; font-weight: 700; display: flex; align-items: center; gap: 4px; }

/* Ligne « HS » : snapshot périmé (> 1 h). Carte grisée + barre verticale à gauche. */
.card.stale { position: relative; opacity: .6; filter: grayscale(.9); overflow: hidden; }
.card.stale::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; background: #8C93A1;
}
.niv-hs {
  font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: 99px;
  background: #E4E8EF; color: #5A6171; letter-spacing: .06em;
}

/* Jauges de probabilité (3 horizons) */
.gauges { display: flex; gap: 12px; margin-top: 16px; }
.gauge { flex: 1; min-width: 0; }
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; }
.gauge-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: #9097A4;
}
.gauge-value { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.gauge-track { position: relative; height: 8px; background: #EAEDF2; border-radius: 99px; }
.gauge-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
.gauge-threshold { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .55; }
.gauge-tag {
  font-size: 9px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; margin-top: 5px;
}

/* Chips opérationnels (bas de carte) */
.chips {
  display: flex; gap: 8px; margin-top: 15px; padding-top: 13px;
  border-top: 1px solid #EEF0F4; flex-wrap: wrap;
}
.chip-op { flex: 1; min-width: 90px; }
.chip-op-label {
  font-size: 10px; font-weight: 600; color: #9097A4;
  text-transform: uppercase; letter-spacing: .03em;
}
.chip-op-value { font-family: var(--mono); font-size: 14px; font-weight: 600; margin-top: 2px; }

.footnote { text-align: center; margin-top: 32px; font-size: 11px; color: #A6ACB8; font-weight: 500; }

/* --- États : chargement / erreur / vide ----------------------------------- */
.state { text-align: center; padding: 80px 20px; }
.loading {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 90px 20px; color: var(--muted-2); font-weight: 600;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid #D5DBE4; border-top-color: #0B7A4B;
  animation: rv-spin .8s linear infinite;
}
.error-title { font-size: 15px; font-weight: 800; margin-bottom: 6px; color: #3A4150; }
.error-msg { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 18px; }
.btn-primary {
  cursor: pointer; font-family: var(--sans); font-weight: 700; font-size: 13px;
  padding: 9px 18px; border-radius: 10px; border: none; background: #0B7A4B; color: #fff;
}
.empty { color: var(--muted); font-weight: 600; }

@keyframes rv-spin { to { transform: rotate(360deg); } }
