/* ==========================================================================
   NV-STATS.CSS — 
   Styles pour le composant statistiques / graphiques (nv-stats-*, nv-graph-*)
   Chargé après base.css et layout.css.
   Respecte exactement les tokens et patterns de db-* / home.css.
   ========================================================================== */


/* ══════════════════════════════════════════════════════════════════════════
   ① SECTION WRAPPER
   Identique à .db-section — carte englobante avec padding, border, shadow.
   Tout le contenu (toolbar, charts, modal) vit à l'intérieur.
══════════════════════════════════════════════════════════════════════════ */

.nv-stats-section {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding: 1.4rem 1.5rem;
  border-radius: var(--radius-xl, var(--radius-4));
  background:
    radial-gradient(circle at 95% 5%,
      color-mix(in srgb, var(--accent-bg) 55%, transparent), transparent 50%),
    var(--card);
  border: 1px solid color-mix(in srgb, var(--muted) 12%, transparent);
  box-shadow: var(--shadow-2);
  margin-bottom: 1.25rem;
}


/* ══════════════════════════════════════════════════════════════════════════
   ② TOOLBAR (range selector)
   Pattern : db-section-head — label + contrôle sur une ligne
══════════════════════════════════════════════════════════════════════════ */

.nv-stats-graph-toolbar {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
}

/* nv-stats-label — toolbar label, scoped to this namespace */
.nv-stats-label {
  font-size: .78rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: .02em;
  white-space: nowrap;
  cursor: default;
  user-select: none;
}

/* Surcharge légère du select pour l'aligner sur la toolbar */
.nv-stats-select {
  padding-top: .42em;
  padding-bottom: .42em;
  font-size: .84rem;
  font-weight: 700;
  min-width: 160px;
  max-width: 220px;
  cursor: pointer;
}

.nv-stats-select:disabled {
  opacity: .5;
  cursor: not-allowed;
}


/* ══════════════════════════════════════════════════════════════════════════
   ③ CHARTS ROW — grille 3 colonnes
   Protocols est plus étroit (doughnut) — on le laisse stretch par défaut
   et on ajuste sa hauteur de canvas dans la section ⑤.
══════════════════════════════════════════════════════════════════════════ */

.nv-stats-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(180px, 280px);
  gap: 1rem;
  align-items: start;
  transition: opacity .25s ease;
}

.nv-stats-charts-row.nv-is-loading {
  opacity: .45;
  pointer-events: none;
}

@media (max-width: 900px) {
  /* 2 colonnes — bandwidth prend la ligne entière en haut */
  .nv-stats-charts-row {
    grid-template-columns: 1fr 1fr;
  }
  .nv-graph-bandwidth {
    grid-column: 1 / -1;
  }
  /* requests + protocols se partagent la 2e ligne */
  .nv-graph-requests,
  .nv-graph-protocols {
    grid-column: unset;
    max-width: 100%;
    margin-inline: 0;
  }
}

@media (max-width: 580px) {
  .nv-stats-charts-row {
    grid-template-columns: 1fr;
  }
  .nv-graph-protocols {
    grid-column: unset;
    max-width: 100%;
    margin-inline: 0;
  }
}


/* ══════════════════════════════════════════════════════════════════════════
   ④ GRAPH CARD — chaque carte de graphique
   Pattern : db-section (card + border + shadow) avec hover glow accent
   et cursor: zoom-in (déjà en inline style dans le template).
══════════════════════════════════════════════════════════════════════════ */

.nv-stats-graph-card {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  padding: 1.1rem 1.2rem;
  border-radius: var(--radius-4);
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--muted) 12%, transparent);
  box-shadow: var(--shadow-2);
  transition: border-color .2s ease, box-shadow .2s ease;
  overflow: hidden;
}

.nv-stats-graph-card:hover {
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  box-shadow:
    var(--shadow-2),
    0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent),
    var(--shadow-accent-glow);
}

/* Title row */
.nv-stats-graph-card h4 {
  display: flex;
  align-items: baseline;
  gap: .5em;
  flex-wrap: wrap;
  margin: 0;
  font-size: .9rem;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -.01em;
  line-height: 1.3;
}

/* Range label ( "month", "week"… ) */
.nv-stats-graph-card h4 small {
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .03em;
  text-transform: uppercase;
  margin-left: auto;
}

/* Identity name inline — muted, non-bold */
.nv-graph-identity-inline {
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

/* Canvas wrapper — height fixe pour maintainAspectRatio: false */
.chart-wrapper {
  position: relative;
  width: 100%;
}

/* Line charts (bandwidth + requests) — taller */
.nv-graph-bandwidth .chart-wrapper,
.nv-graph-requests  .chart-wrapper  { height: 180px; }

/* Doughnut — plus court */
.nv-graph-protocols .chart-wrapper  { height: 200px; }

@media (max-width: 580px) {
  .nv-graph-bandwidth .chart-wrapper,
  .nv-graph-requests  .chart-wrapper  { height: 160px; }
  .nv-graph-protocols .chart-wrapper  { height: 180px; }
}


/* ══════════════════════════════════════════════════════════════════════════
   ⑤ LOADING OVERLAY
   Affiche un message centré sous les charts; opacity pilotée par Alpine.
══════════════════════════════════════════════════════════════════════════ */

.nv-stats-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .5rem 0;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .02em;
  pointer-events: none;
  transition: opacity .25s ease;
  gap: .5em;
}

.nv-stats-loading::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent);
  animation: nv-spin .7s linear infinite;
  flex-shrink: 0;
}

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


/* ══════════════════════════════════════════════════════════════════════════
   ⑥ GRAPH MODAL — overlay plein écran + carte centrée
   Pattern : modal system de base.css (--modal-radius, --shadow-2, --card)
   avec header db-section-head style, footer muted.
══════════════════════════════════════════════════════════════════════════ */

.nv-graph-modal {
  position: fixed;
  inset: 0;
  z-index: 500; /* above docs-toc (210) and header (50), below modal system (12000) */
  background: rgba(0, 0, 0, .62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.nv-graph-modal-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 960px;
  max-height: calc(100dvh - 3rem);
  border-radius: var(--modal-radius, var(--radius-4));
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
  box-shadow:
    var(--shadow-2),
    0 0 60px rgba(0, 0, 0, .35),
    var(--shadow-accent);
  /* pas overflow:hidden — les labels X à 45° du canvas dépassent en bas */
  overflow: visible;
}

/* ── Close button ── */
.nv-graph-close {
  position: absolute;
  top: .8rem;
  right: .8rem;
  z-index: 2;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-3);
  background: color-mix(in srgb, var(--card) 70%, transparent);
  border: 1px solid color-mix(in srgb, var(--muted) 14%, transparent);
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
}

.nv-graph-close:hover {
  background: var(--danger-bg);
  border-color: color-mix(in srgb, var(--danger) 22%, transparent);
  color: var(--danger);
}

/* ── Context header (title + meta + actions) ── */
.nv-graph-context {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  padding: 1.1rem 1.3rem .75rem;
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 10%, transparent);
  background:
    radial-gradient(circle at 95% 0%,
      color-mix(in srgb, var(--accent-bg) 40%, transparent), transparent 55%),
    var(--card);
}

.nv-graph-context h4 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 950;
  color: var(--text);
  letter-spacing: -.02em;
  padding-right: 2.5rem; /* room for close btn */
}

.nv-graph-hint {
  font-size: .73rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .01em;
  opacity: .8;
}

/* Meta row: identity + range */
.nv-graph-context-meta {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
}

.nv-graph-context-meta strong {
  color: var(--text);
  font-weight: 900;
}

/* Identity name — truncated pill */
.nv-graph-identity {
  display: flex;
  align-items: center;
  gap: .4em;
  max-width: 220px;
  overflow: hidden;
}

.nv-graph-identity-name {
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
  color: var(--accent);
  font-weight: 800;
}

/* Export actions row */
.nv-graph-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  padding-top: .2rem;
}

/* ── Canvas area ── */
.nv-graph-modal-canvas {
  padding: 1rem 1.2rem 0;
  height: 380px;
}

.nv-graph-modal-canvas canvas {
  display: block;
}

/* NE PAS forcer width/height sur le canvas — Chart.js les gère lui-même.
   Un canvas CSS à 0px ou 100% peut corrompre le contexte 2D et provoquer
   "Cannot read properties of null (reading 'getContext')". */

/* ── Footer ── */
.nv-graph-context-footer {
  padding: .55rem 1.3rem;
  border-top: 1px solid color-mix(in srgb, var(--muted) 10%, transparent);
  font-size: .73rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .01em;
}


/* ══════════════════════════════════════════════════════════════════════════
   ⑦ RESPONSIVE — modal
══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  .nv-graph-modal {
    padding: .5rem;
    align-items: flex-end;
  }

  .nv-graph-modal-card {
    max-height: calc(100dvh - 1rem);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .nv-graph-modal-canvas {
    padding: .75rem;
    min-height: 240px;
  }
}

/* ── FIX 13: Empty state ── */
.nv-stats-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
}
.nv-stats-empty svg {
  opacity: .35;
  margin-bottom: .25rem;
}
.nv-stats-empty p {
  margin: 0;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text);
}
.nv-stats-empty span {
  font-size: .8rem;
  opacity: .65;
}