/* ==========================================================================
   conso.css — Page « Consommation électrique ».
   Dépend de theme.css pour les tokens (surfaces, textes, rayons, boutons).
   ========================================================================== */

/* Couleurs des barres. Validées (contraste ≥ 3:1 sur la surface, écart
   suffisant pour les daltonismes) avec le validateur de palette :
   l'ambre reprend l'accent de la tuile Électricité, Bleu/Blanc/Rouge celles
   de Tempo. Le « Blanc » est forcément un gris : il est toujours accompagné
   de son nom (légende, infobulle, tableau), jamais lu à la seule couleur. */
:root {
  --c-accent: #d97706;
  --c-bleu:   #3b82f6;
  --c-blanc:  #64748b;
  --c-rouge:  #ef4444;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --c-blanc: #8391a5; }
}
:root[data-theme="dark"] { --c-blanc: #8391a5; }

.conso-body { background: var(--bg); }

.conso {
  max-width: 920px;
  margin: 0 auto;
  padding: 22px 16px calc(60px + env(safe-area-inset-bottom, 0px));
}

/* --------------------------------------------------------------
   Écrans d'attente
   -------------------------------------------------------------- */
.conso-gate {
  max-width: 440px;
  margin: 12vh auto 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.conso-gate-icon {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 1.6rem;
  background: color-mix(in srgb, var(--c-accent) 14%, transparent);
}
.conso-gate h1 { margin: 0; font-size: 1.6rem; font-weight: 700; letter-spacing: -0.03em; }
.conso-gate p { margin: 0; line-height: 1.5; }
.conso-gate .btn-primary { padding: 12px 22px; text-decoration: none; }

/* --------------------------------------------------------------
   En-tête
   -------------------------------------------------------------- */
.conso-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.conso-header h1 {
  margin: 0;
  font-size: clamp(1.4rem, 4.6vw, 1.9rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}
.conso-fresh { margin: 4px 0 0; font-size: .84rem; color: var(--text-3); }
.conso-settings { flex-shrink: 0; text-decoration: none; white-space: nowrap; }

.conso-alert {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  font-size: .85rem;
  line-height: 1.45;
  color: var(--text);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
}

/* --------------------------------------------------------------
   Les quatre chiffres
   -------------------------------------------------------------- */
.conso-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
@media (max-width: 760px) {
  .conso-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.conso-kpi {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
  padding: 14px 14px 12px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s var(--ease-soft), transform .15s var(--ease-soft);
}
.conso-kpi:hover { border-color: var(--border-strong); }
.conso-kpi:active { transform: scale(.985); }
.conso-kpi:focus-visible { outline: none; box-shadow: var(--shadow-glow); }

.conso-kpi-label {
  display: flex; align-items: center; gap: 6px;
  font-size: .8rem; font-weight: 600; color: var(--text-2);
}
.conso-kpi-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.approx-mark {
  margin-right: .18em;
  font-size: .6em;
  font-weight: 600;
  color: var(--text-3);
  vertical-align: .18em;
}
.conso-kpi-kwh   { font-size: .84rem; font-weight: 500; color: var(--text-3); }
.conso-kpi-sub   { font-size: .74rem; color: var(--text-3); line-height: 1.35; }
.conso-kpi .conso-evo { font-size: .74rem; line-height: 1.35; }

/* Évolution : plus de conso = rouge, moins = vert, toujours avec sa flèche. */
.conso-evo { color: var(--text-3); white-space: normal; }
.conso-evo.is-up   { color: var(--danger); }
.conso-evo.is-down { color: var(--success); }
.conso-evo-arrow { font-size: .8em; }

/* --------------------------------------------------------------
   Granularité
   -------------------------------------------------------------- */
.conso-gran {
  display: inline-flex;
  gap: 4px;
  margin: 18px 0 0;
  padding: 4px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  scroll-margin-top: calc(var(--nav-h) + 12px);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.conso-gran::-webkit-scrollbar { display: none; }
.conso-gran button {
  padding: 7px 16px;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: .86rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.conso-gran button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.conso-gran button:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }

/* --------------------------------------------------------------
   Cartes
   -------------------------------------------------------------- */
.conso-card {
  margin-top: 12px;
  padding: 16px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.conso-card-title { margin: 0 0 8px; font-size: 1rem; font-weight: 650; }

.conso-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.conso-chart-head h2 {
  margin: 0;
  font-size: .98rem;
  font-weight: 650;
  text-align: center;
}
.conso-nav {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.conso-nav:disabled { opacity: .35; cursor: default; }
.conso-nav:focus-visible { outline: 2px solid var(--ring); }

.conso-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin-top: 10px;
  font-size: .76rem;
  color: var(--text-2);
}
.conso-legend[hidden] { display: none; }
.conso-legend-item { display: inline-flex; align-items: center; gap: 6px; }

.conso-swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  background: var(--c-accent);
  flex-shrink: 0;
}
.conso-swatch.is-bleu  { background: var(--c-bleu); }
.conso-swatch.is-blanc { background: var(--c-blanc); }
.conso-swatch.is-rouge { background: var(--c-rouge); }
.conso-swatch.is-proj  { background: transparent; border: 1.5px dashed var(--text-3); box-sizing: border-box; }

.conso-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 6px;
  vertical-align: 1px;
  background: var(--c-accent);
}
.conso-dot.is-bleu  { background: var(--c-bleu); }
.conso-dot.is-blanc { background: var(--c-blanc); }
.conso-dot.is-rouge { background: var(--c-rouge); }
.conso-kpi-label .conso-dot { margin-right: 0; }

/* --------------------------------------------------------------
   Graphique
   -------------------------------------------------------------- */
.conso-chart {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  grid-template-rows: 220px auto;
  column-gap: 6px;
  margin-top: 30px;
}
@media (min-width: 760px) {
  .conso-chart { grid-template-rows: 270px auto; }
}

.chart-y { position: relative; }
.chart-y span {
  position: absolute;
  right: 0;
  transform: translateY(50%);
  font-size: .68rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  line-height: 1;
}
.chart-y .chart-y-unit { top: -24px; bottom: auto !important; transform: none; font-weight: 600; }

.chart-plot { position: relative; }

.chart-grid span {
  position: absolute;
  left: 0; right: 0;
  height: 1px;
  background: var(--border);
}
.chart-grid span:first-child { background: var(--border-strong); }

.chart-avg {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 1px solid color-mix(in srgb, var(--text-2) 55%, transparent);
  z-index: 2;
  pointer-events: none;
}
.chart-avg span {
  position: absolute;
  right: 0;
  bottom: 3px;
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--surface);
  font-size: .66rem;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.chart-bars {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  column-gap: 2px;
  z-index: 1;
}

.chart-bar {
  position: relative;
  height: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 6px 6px 0 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chart-bar:hover { background: color-mix(in srgb, var(--text) 4%, transparent); }
.chart-bar.is-selected { background: color-mix(in srgb, var(--text) 7%, transparent); }
.chart-bar:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }

.bar-fill,
.bar-proj,
.bar-none {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.bar-fill {
  width: min(24px, 100%);
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--c-accent);
  transition: height .35s var(--ease), filter .15s var(--ease-soft);
}
.bar-fill.is-bleu  { background: var(--c-bleu); }
.bar-fill.is-blanc { background: var(--c-blanc); }
.bar-fill.is-rouge { background: var(--c-rouge); }
.chart-bar:hover .bar-fill { filter: brightness(1.1) saturate(1.05); }

/* Barre empilée par couleur Tempo : 2 px de surface entre les segments. */
.bar-fill.is-stack {
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
  background: transparent;
  overflow: hidden;
}
.bar-seg { flex-basis: 0; min-height: 0; background: var(--c-accent); }
.bar-seg.is-bleu  { background: var(--c-bleu); }
.bar-seg.is-blanc { background: var(--c-blanc); }
.bar-seg.is-rouge { background: var(--c-rouge); }

/* Période en cours : remplissage atténué + projection en pointillés. */
.chart-bar.is-partial .bar-fill { opacity: .55; }
.bar-proj {
  width: min(24px, 100%);
  box-sizing: border-box;
  border: 1.5px dashed var(--text-3);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
}

/* Jour sans relevé : un trait au pied, pour ne pas lire « zéro ». */
.bar-none {
  width: min(10px, 70%);
  height: 3px;
  border-radius: 2px;
  background: var(--border-strong);
}

.chart-corner { grid-column: 1; grid-row: 2; }

.chart-x {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  column-gap: 2px;
  margin-top: 6px;
}
.chart-x span {
  font-size: .68rem;
  color: var(--text-3);
  text-align: center;
  white-space: nowrap;
  overflow: visible;
  display: flex;
  justify-content: center;
}
.chart-x span.is-selected { color: var(--text); font-weight: 700; }

/* --------------------------------------------------------------
   Infobulle
   -------------------------------------------------------------- */
.conso-tip {
  position: absolute;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 240px;
  padding: 8px 11px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: .78rem;
  color: var(--text-2);
  pointer-events: none;
}
.conso-tip[hidden] { display: none; }
.tip-value { font-size: 1rem; font-weight: 700; color: var(--text); }
.tip-label { color: var(--text-2); }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row .conso-dot { margin-right: 0; }
.tip-muted { color: var(--text-3); }
.tip-key { width: 12px; height: 2.5px; border-radius: 2px; background: var(--c-accent); flex-shrink: 0; }
.tip-key.is-bleu  { background: var(--c-bleu); }
.tip-key.is-blanc { background: var(--c-blanc); }
.tip-key.is-rouge { background: var(--c-rouge); }

/* --------------------------------------------------------------
   Détail de la période sélectionnée
   -------------------------------------------------------------- */
.conso-detail {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.conso-detail:empty { display: none; }

.detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.detail-head h3 { margin: 0; font-size: 1rem; font-weight: 650; }
.detail-chip {
  padding: 2px 9px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-2);
}
.detail-chip.is-bleu  { background: color-mix(in srgb, var(--c-bleu) 16%, transparent); }
.detail-chip.is-blanc { background: color-mix(in srgb, var(--c-blanc) 18%, transparent); }
.detail-chip.is-rouge { background: color-mix(in srgb, var(--c-rouge) 18%, transparent); }

.detail-figures { display: flex; flex-wrap: wrap; gap: 10px 26px; margin: 12px 0 8px; }
.detail-figure { display: flex; flex-direction: column; }
.detail-value { font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; color: var(--text-2); }
.detail-figure.is-main .detail-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); line-height: 1.1; }
.detail-figures { align-items: flex-end; }
.detail-label { font-size: .76rem; color: var(--text-3); }

.detail-notes { list-style: none; margin: 0; padding: 0; font-size: .84rem; color: var(--text-2); }
.detail-notes li { margin: 4px 0; }
.detail-muted { color: var(--text-3); }
.detail-empty { margin: 8px 0 0; font-size: .86rem; color: var(--text-3); }

.tempo-split {
  display: grid;
  grid-template-columns: auto auto auto auto;
  justify-content: start;
  gap: 4px 18px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
.tempo-split-row { display: contents; }
.tempo-split-name { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; color: var(--text); }
.tempo-split-days { color: var(--text-3); text-align: right; }
.tempo-split-kwh { text-align: right; color: var(--text-3); }
.tempo-split-cost { text-align: right; color: var(--text); font-weight: 600; }

/* --------------------------------------------------------------
   Tableau
   -------------------------------------------------------------- */
.conso-table-wrap { overflow-x: auto; margin: 0 -4px; }
.conso-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .86rem;
}
.conso-table th,
.conso-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.conso-table thead th {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
}
.conso-table tbody th { font-weight: 600; color: var(--text); }
.conso-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.conso-table td { color: var(--text-3); }
.conso-table td.cell-cost { color: var(--text); font-weight: 600; }
.conso-table tbody tr { cursor: pointer; }
.conso-table tbody tr:hover { background: var(--surface-2); }
.conso-table tbody tr.is-selected { background: color-mix(in srgb, var(--primary) 9%, transparent); }
.conso-table tbody tr:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.conso-table tbody tr:last-child th,
.conso-table tbody tr:last-child td { border-bottom: 0; }
.conso-table .conso-evo { font-size: .8rem; white-space: nowrap; }

.row-chip {
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-3);
}

@media (max-width: 520px) {
  .conso-table { font-size: .82rem; }
  .conso-table .col-avg { display: none; }
  .conso-table th, .conso-table td { padding: 9px 5px; }
  /* « en cours » passe sous le libellé plutôt que de pousser les colonnes. */
  .row-chip { display: table; margin: 3px 0 0; }
}

/* --------------------------------------------------------------
   Notes
   -------------------------------------------------------------- */
.conso-foot {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 18px 2px 0;
  font-size: .76rem;
  line-height: 1.5;
  color: var(--text-3);
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}
