/* indicator_cards.css - Styles responsive pour les cartes d'indicateurs */

/* =========================
   BASE STYLES
========================= */

/* Card body en flexbox pour que le graphique prenne l'espace disponible */
.card.h-100 > .card-body {
  display: flex;
  flex-direction: column;
}

/* Le chart-box prend tout l'espace restant */
.card.h-100 > .card-body > .chart-box {
  flex: 1;
  min-height: 200px;
}

/* Les éléments après le chart restent en bas */
.card.h-100 > .card-body > .table-section,
.card.h-100 > .card-body > .sources-footer,
.card.h-100 > .card-body > .mt-2 {
  flex-shrink: 0;
  margin-top: auto;
}

/* Row avec charts côte à côte prend aussi l'espace */
.card.h-100 > .card-body > .row.g-2 {
  flex: 1;
  min-height: 200px;
}

/* KPIs et header ne grandissent pas */
.card.h-100 > .card-body > .d-flex.align-items-start,
.card.h-100 > .card-body > .row.g-3.mb-3,
.card.h-100 > .card-body > .alert {
  flex-shrink: 0;
}

.chart-box {
  position: relative;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
}

.chart-box canvas {
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
  min-height: 100% !important;
  display: block;
}

/* Forcer alignement égal des graphiques côte à côte */
.chart-box-half {
  display: flex;
  align-items: stretch;
}

.chart-box-half canvas {
  flex: 1;
  min-height: 100% !important;
}

/* Source footer - réduire l'espace */
.sources-footer {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(0,0,0,0.05);
}

.card-body > .text-muted.small:last-child {
  margin-top: 0.75rem !important;
}

/* =========================
   DESKTOP (défaut)
========================= */
.chart-box {
  height: 280px;
}

/* Graphiques côte à côte (2 par ligne) */
.chart-box-half {
  height: 280px;
}

/* =========================
   TABLES COLLAPSIBLES - compact quand replié
========================= */
.table-section {
  margin-bottom: 0.5rem !important;
}

.table-section .btn[data-bs-toggle="collapse"] {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  margin-bottom: 0 !important;
}

.table-section .collapse:not(.show) + .table-responsive,
.table-section .collapsing + .table-responsive {
  display: none;
}

/* Réduire l'espace quand le tableau est replié */
.table-section:has(.collapse:not(.show)) {
  margin-bottom: 0.25rem !important;
}

/* Transition fluide pour le tableau */
.table-section .collapse {
  transition: none;
}

.table-section .table-responsive {
  margin-top: 0.5rem;
}

/* =========================
   TABLET (< 992px)
========================= */
@media (max-width: 991.98px) {
  .chart-box {
    height: 240px;
  }

  .chart-box-half {
    height: 200px;
  }

  /* Réduire l'espace des KPIs */
  .card-body .row.g-3.mb-3 {
    margin-bottom: 0.5rem !important;
  }

  /* Sources plus compactes */
  .sources-footer {
    margin-top: 0.25rem;
    padding-top: 0.25rem;
    font-size: 0.75rem;
  }
}

/* =========================
   MOBILE (< 768px)
========================= */
@media (max-width: 767.98px) {
  /* GRAPHIQUES : hauteur adaptée */
  .chart-box {
    height: 220px;
  }

  .chart-box-half {
    height: 180px;
  }

  /* Card padding réduit */
  .card-body {
    padding: 0.75rem !important;
  }

  /* Titres BEAUCOUP plus petits */
  .card-body h3.h5 {
    font-size: 0.85rem;
    line-height: 1.2;
  }

  /* Icônes dans les titres */
  .card-body h3.h5 i {
    font-size: 0.8rem;
  }

  /* Header titre + badge : réduire marge */
  .card-body > .d-flex.align-items-start.justify-content-between.mb-3 {
    margin-bottom: 0.4rem !important;
  }

  /* Badge plus petit */
  .card-body .badge {
    font-size: 0.6rem;
    padding: 0.2em 0.4em;
  }

  /* KPIs en grille 2 colonnes fixes */
  .card-body .row.g-3.mb-3 {
    margin-bottom: 0.4rem !important;
    gap: 0.2rem !important;
  }

  .card-body .row.g-3.mb-3 > div {
    flex: 0 0 50%;
    max-width: 50%;
    padding: 0.15rem !important;
  }

  /* Valeurs KPI BEAUCOUP plus petites */
  .card-body .row.g-3 .fs-5 {
    font-size: 0.85rem !important;
    line-height: 1.1;
  }

  /* Labels KPI très compacts */
  .card-body .row.g-3 .text-muted.small {
    font-size: 0.65rem;
    line-height: 1.1;
  }

  /* Sources très compactes */
  .sources-footer {
    margin-top: 0.1rem;
    padding-top: 0.1rem;
    font-size: 0.6rem;
  }

  /* Message block (alertes jaunes, bleues, etc.) - texte très petit */
  .card-body > .alert,
  .card-body .alert,
  .alert-info,
  .alert-warning,
  .alert-danger,
  .alert-success {
    padding: 0.25rem 0.4rem !important;
    font-size: 0.55rem !important;
    margin-bottom: 0.25rem !important;
    line-height: 1.15;
  }

  /* Boutons d'action plus petits */
  .card-body .btn-sm {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
  }
}

/* =========================
   SMALL MOBILE (< 576px)
========================= */
@media (max-width: 575.98px) {
  /* Graphiques : hauteur compacte */
  .chart-box {
    height: 180px;
  }

  .chart-box-half {
    height: 140px;
  }

  /* Card padding encore plus réduit */
  .card-body {
    padding: 0.5rem !important;
  }

  /* Titres minimaux */
  .card-body h3.h5 {
    font-size: 0.8rem;
  }

  /* Badge minimaliste */
  .card-body .badge {
    font-size: 0.55rem;
    padding: 0.15em 0.3em;
  }

  /* KPIs ultra-compacts */
  .card-body .row.g-3.mb-3 {
    margin-bottom: 0.3rem !important;
  }

  .card-body .row.g-3 .fs-5 {
    font-size: 0.8rem !important;
  }

  .card-body .row.g-3 .text-muted.small {
    font-size: 0.6rem;
  }

  /* Sources minimales */
  .sources-footer {
    font-size: 0.55rem;
  }

  /* Alertes encore plus petites */
  .card-body > .alert,
  .card-body .alert,
  .alert-info,
  .alert-warning,
  .alert-danger,
  .alert-success {
    padding: 0.2rem 0.35rem !important;
    font-size: 0.5rem !important;
    margin-bottom: 0.2rem !important;
  }
}

/* =========================
   CHART.JS LEGEND - permettre plus de place
========================= */
@media (max-width: 767.98px) {
  .chart-box canvas {
    max-height: 100%;
  }
}

/* =========================
   CONTAINER RESPONSIVE - alignement mobile
========================= */
@media (max-width: 767.98px) {
  /* Réduire le padding du container sur mobile */
  .container {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }

  /* Réduire le gap entre les cards */
  #dashboard .row.g-4 {
    --bs-gutter-x: 0.5rem;
    --bs-gutter-y: 0.5rem;
  }
}

@media (max-width: 575.98px) {
  .container {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }

  #dashboard .row.g-4 {
    --bs-gutter-x: 0.25rem;
    --bs-gutter-y: 0.4rem;
  }
}

/* =========================
   HEADER / TERRITORY SELECTOR RESPONSIVE
========================= */
@media (max-width: 767.98px) {
  /* Titre du territoire beaucoup plus petit */
  header .display-5 {
    font-size: 1.1rem !important;
    margin-bottom: 0.15rem !important;
    line-height: 1.2;
  }

  /* Sous-titre (type + code) */
  header p.text-muted {
    font-size: 0.6rem !important;
    margin-bottom: 0.25rem !important;
  }

  /* Card du sélecteur - même padding que les autres cards */
  header .card-body {
    padding: 0.5rem !important;
  }

  /* Espacements entre les éléments du formulaire */
  header .row.g-3 {
    --bs-gutter-x: 0.4rem;
    --bs-gutter-y: 0.3rem;
  }

  /* Labels flottants plus petits */
  header .form-floating > label {
    font-size: 0.65rem;
    padding: 0.5rem 0.5rem;
  }

  header .form-floating > .form-control,
  header .form-floating > .form-select {
    height: 2.2rem;
    min-height: 2.2rem;
    padding: 0.8rem 0.5rem 0.2rem 0.5rem;
    font-size: 0.7rem;
  }

  /* Bouton Aller */
  header .territory-go {
    height: 2.2rem !important;
    font-size: 0.7rem !important;
    padding: 0.25rem 0.5rem !important;
  }

  /* Hint text */
  header #territoryHint {
    font-size: 0.55rem !important;
    margin-top: 0.1rem !important;
  }

  /* Autocomplete dropdown */
  header #territoryDropdown {
    font-size: 0.7rem;
  }

  header #territoryDropdown .list-group-item {
    padding: 0.35rem 0.5rem;
    font-size: 0.65rem;
  }

  /* Marge du header */
  header.mb-4 {
    margin-bottom: 0.5rem !important;
  }
}

@media (max-width: 575.98px) {
  header .display-5 {
    font-size: 0.95rem !important;
  }

  header p.text-muted {
    font-size: 0.55rem !important;
  }

  header .card-body {
    padding: 0.35rem !important;
  }

  header .form-floating > .form-control,
  header .form-floating > .form-select {
    height: 2rem;
    min-height: 2rem;
    font-size: 0.65rem;
  }

  header .territory-go {
    height: 2rem !important;
    font-size: 0.65rem !important;
  }

  header.mb-4 {
    margin-bottom: 0.4rem !important;
  }
}

/* =========================
   FOOTER RESPONSIVE
========================= */
@media (max-width: 767.98px) {
  footer.main-footer {
    padding: 0.35rem 0 !important;
  }

  footer.main-footer .footer-title {
    font-size: 0.65rem !important;
  }

  footer.main-footer .footer-subtitle {
    font-size: 0.6rem !important;
  }

  footer.main-footer .footer-author {
    font-size: 0.55rem !important;
  }
}

@media (max-width: 575.98px) {
  footer.main-footer {
    padding: 0.25rem 0 !important;
  }

  footer.main-footer .footer-title {
    font-size: 0.6rem !important;
  }

  footer.main-footer .footer-author {
    font-size: 0.5rem !important;
  }
}

/* =========================
   GRAPHIQUES AVEC BEAUCOUP DE LEGENDES
========================= */
/* Les légendes sont gérées en mode compact dans public_dashboard.js */
