/**
 * tableau-de-bord.css
 * Styles spécifiques au gabarit "Mon tableau de bord"
 *
 * SOMMAIRE
 * 1. Layout général de la page tableau de bord
 * 2. Barre de contexte (territoire + année)
 * 3. Grille de widgets
 * 4. Widget – structure commune
 * 5. Widget – KPI (chiffre clé)
 * 6. Widget – Jauge (gauge)
 * 7. Widget – Graphiques (canvas Chart.js)
 * 8. Widget – Mini-carte
 * 9. Widget – Liste de progression
 * 10. Widget – Heatmap bar
 * 11. États vides & chargement
 * 12. Tooltip widgets
 */

/* ============================================================
   1. LAYOUT GÉNÉRAL
   ============================================================ */

.dashboard-page {
  padding: calc(var(--header-height) + var(--toolbar-height) + var(--spacing-lg)) var(--spacing-xl) var(--spacing-xl);
  min-height: 100vh;
  background-color: var(--color-bg);
}

/* ============================================================
   2. BARRE DE CONTEXTE (toolbar du tableau de bord)
   ============================================================ */

.dashboard-toolbar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  z-index: 999;
  height: var(--toolbar-height);
  background-color: var(--color-primary);
  display: flex;
  align-items: center;
  padding: 0 var(--spacing-xl);
  gap: var(--spacing-sm);
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  flex-wrap: wrap;
}

.dashboard-toolbar__titre {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-white);
  margin-right: var(--spacing-sm);
  letter-spacing: .3px;
  white-space: nowrap;
}

.dashboard-toolbar__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  text-decoration: none;
  font-size: 12px;
  flex-shrink: 0;
  transition: background .2s;
}
.dashboard-toolbar__back:hover {
  background: rgba(255,255,255,.28);
  color: white;
  text-decoration: none;
}

.dashboard-toolbar__groupe {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.dashboard-toolbar__label {
  font-size: 11px;
  color: rgba(255,255,255,.7);
  white-space: nowrap;
}

/* ============================================================
   3. GRILLE DE WIDGETS
   ============================================================ */

.dashboard-intro {
  margin-bottom: var(--spacing-lg);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--spacing-md);
}

.dashboard-intro__titre {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-text);
  margin: 0;
  line-height: 1.2;
}

.dashboard-intro__territoire {
  font-size: var(--font-size-lg);
  color: var(--color-primary);
  font-weight: 400;
}

.dashboard-intro__meta {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  text-align: right;
}

/* Grille Bootstrap override pour la trame 3 colonnes */
.dashboard-grille {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-md);
}

/* Widget pleine largeur (span 3) */
.dashboard-widget--large {
  grid-column: span 3;
}

/* Widget demi-largeur (span 2) */
.dashboard-widget--medium {
  grid-column: span 2;
}

/* ============================================================
   4. WIDGET – STRUCTURE COMMUNE
   ============================================================ */

.widget {
  background: var(--color-bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow .25s ease, transform .2s ease;
  position: relative;
}

.widget:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.widget__header {
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-shrink: 0;
}

.widget__icone {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.widget__titre {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  flex: 1;
  line-height: 1.35;
}

.widget__badge-thematique {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.widget__actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .2s ease;
}

.widget:hover .widget__actions {
  opacity: 1;
}

.widget__action-btn {
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 11px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}

.widget__action-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.widget__body {
  flex: 1;
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.widget__footer {
  padding: var(--spacing-xs) var(--spacing-md);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
  flex-shrink: 0;
}

.widget__footer-info {
  font-size: 10px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Barre de couleur en haut du widget selon thématique */
.widget::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--widget-accent-color, var(--color-primary));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* ============================================================
   5. WIDGET KPI (chiffre clé)
   ============================================================ */

.widget-kpi__valeur-principale {
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
  color: var(--widget-accent-color, var(--color-primary));
  letter-spacing: -1px;
}

.widget-kpi__unite {
  font-size: var(--font-size-lg);
  font-weight: 400;
  color: var(--color-text-muted);
  margin-left: 3px;
}

.widget-kpi__evolution {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin-top: var(--spacing-xs);
}

.widget-kpi__evolution--hausse {
  background: #E8F5E9;
  color: var(--color-success);
}

.widget-kpi__evolution--baisse {
  background: #FFEBEE;
  color: var(--color-danger);
}

.widget-kpi__description {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-top: var(--spacing-sm);
  line-height: 1.45;
}

/* ============================================================
   6. WIDGET JAUGE (gauge)
   ============================================================ */

.widget-gauge__container {
  position: relative;
  width: 160px;
  height: 100px;
  margin: 0 auto;
}

.widget-gauge__canvas {
  width: 160px;
  height: 100px;
}

.widget-gauge__valeur-centre {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  line-height: 1;
}

.widget-gauge__nombre {
  font-size: 28px;
  font-weight: 700;
  color: var(--widget-accent-color, var(--color-primary));
  display: block;
}

.widget-gauge__label {
  font-size: 11px;
  color: var(--color-text-muted);
  display: block;
}

/* ============================================================
   7. WIDGET GRAPHIQUES (canvas Chart.js)
   ============================================================ */

.widget-chart__canvas-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
}

/* On fixe les hauteurs pour Chart.js */
.widget--bar .widget__body,
.widget--line .widget__body,
.widget--donut .widget__body {
  height: 220px;
  padding: var(--spacing-sm) var(--spacing-md) var(--spacing-md);
}

.widget--bar .widget-chart__canvas-wrapper,
.widget--line .widget-chart__canvas-wrapper,
.widget--donut .widget-chart__canvas-wrapper {
  height: 180px;
}

/* ============================================================
   8. WIDGET MINI-CARTE
   ============================================================ */

.widget-minimap__container {
  height: 200px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #dce8f0;
  position: relative;
}

.widget-minimap__container #minimap-ol {
  width: 100%;
  height: 100%;
}

.widget-minimap__legende {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-md);
  margin-top: var(--spacing-sm);
  flex-wrap: wrap;
}

.widget-minimap__legende-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--color-text-muted);
}

.widget-minimap__legende-couleur {
  width: 12px;
  height: 8px;
  border-radius: 2px;
}

/* Gradient légende mini-carte */
.widget-minimap__gradient {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  margin-top: var(--spacing-sm);
}

.widget-minimap__gradient-barre {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #E3F2FD, #0D47A1);
}

.widget-minimap__gradient-label {
  font-size: 10px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ============================================================
   9. WIDGET LISTE DE PROGRESSION
   ============================================================ */

.widget-progress__item {
  margin-bottom: var(--spacing-sm);
}

.widget-progress__item:last-child {
  margin-bottom: 0;
}

.widget-progress__label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.widget-progress__label {
  font-size: 12px;
  color: var(--color-text);
  font-weight: 500;
}

.widget-progress__valeur {
  font-size: 12px;
  font-weight: 700;
  color: var(--widget-accent-color, var(--color-primary));
}

.widget-progress__barre-bg {
  height: 8px;
  background: var(--color-bg);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.widget-progress__barre-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--widget-accent-color, var(--color-primary));
  transition: width .8s ease;
}

/* ============================================================
   10. WIDGET HEATMAP BAR
   ============================================================ */

.widget-heatmap__item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: 6px;
}

.widget-heatmap__territoire {
  font-size: 11px;
  color: var(--color-text);
  width: 130px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-heatmap__barre-bg {
  flex: 1;
  height: 16px;
  background: var(--color-bg);
  border-radius: 3px;
  overflow: hidden;
}

.widget-heatmap__barre-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .8s ease;
}

.widget-heatmap__valeur {
  font-size: 11px;
  font-weight: 700;
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* Échelle de couleurs stress hydrique */
.heatmap-faible   { background: #81D4FA; }
.heatmap-moyen    { background: #FFF176; }
.heatmap-eleve    { background: #FFB74D; }
.heatmap-critique { background: #EF5350; }

/* ============================================================
   11. ÉTATS VIDES & CHARGEMENT
   ============================================================ */

.widget-vide {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xl);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  text-align: center;
  gap: var(--spacing-sm);
}

.widget-vide__icone {
  font-size: 28px;
  opacity: .3;
}

.widget-chargement {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xl);
  gap: var(--spacing-sm);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

/* ============================================================
   13. ANIMATION MISE À JOUR (flash au changement de données)
   ============================================================ */

/* Flash subtil quand les données sont mises à jour */
@keyframes widgetFlash {
  0%   { box-shadow: 0 0 0 0 rgba(var(--widget-accent-rgb, 21,101,192), 0.45); }
  40%  { box-shadow: 0 0 0 6px rgba(var(--widget-accent-rgb, 21,101,192), 0.18); }
  100% { box-shadow: 0 2px 12px rgba(0,0,0,0.07); }
}

.widget--updating {
  animation: widgetFlash 0.4s ease-out forwards;
}

/* Transition douce sur les barres de progression */
.widget-progress__barre-fill {
  transition: width 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

.widget-heatmap__barre-fill {
  transition: width 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Indicateur de changement sur le chiffre KPI */
.widget-kpi__valeur-principale {
  transition: color 0.3s ease;
}

/* Badge année mis en évidence au changement */
.widget__footer-info {
  transition: opacity 0.3s ease;
}

