/*
 * Styles propres à l'application. Bootstrap 5 est chargé avant ce fichier
 * (voir layouts/application.html.erb), en thème sombre (data-bs-theme="dark").
 *
 * Palette (proche de l'exemple de tableau de bord) :
 *   fond de page #0f1117, fond des cartes #161b27, bordures #2a3347,
 *   texte #e2e8f0, texte secondaire #94a3b8, texte discret #64748b.
 */

[data-bs-theme="dark"] {
  --app-page-bg: #0f1117;
  --app-surface: #161b27;
  --app-surface-hover: #1b2130;
  --app-border: #2a3347;
  --app-border-hover: #3b4660;
  --app-text: #e2e8f0;
  --app-text-secondary: #94a3b8;
  --app-text-muted: #64748b;

  --bs-body-bg: var(--app-page-bg);
  --bs-body-color: var(--app-text);
  --bs-emphasis-color: #ffffff;
  --bs-secondary-color: var(--app-text-secondary);
  --bs-tertiary-color: var(--app-text-muted);
  --bs-secondary-bg: var(--app-surface);
  --bs-tertiary-bg: var(--app-page-bg);
  --bs-border-color: var(--app-border);
  --bs-border-radius: 0.5rem;
  --bs-border-radius-lg: 0.625rem;
}

[data-bs-theme="dark"] .card {
  --bs-card-bg: var(--app-surface);
  --bs-card-border-color: var(--app-border);
}

[data-bs-theme="dark"] .list-group {
  --bs-list-group-bg: var(--app-surface);
  --bs-list-group-border-color: var(--app-border);
  --bs-list-group-action-hover-bg: var(--app-surface-hover);
  --bs-list-group-action-active-bg: var(--app-surface-hover);
}

[data-bs-theme="dark"] .table {
  --bs-table-bg: var(--app-surface);
  --bs-table-striped-bg: var(--app-surface-hover);
}

[data-bs-theme="dark"] .form-control {
  background-color: var(--app-page-bg);
}

.app-navbar {
  background-color: var(--app-surface);
}

/* ---------- Tableau de bord ---------- */

.tile {
  display: block;
  height: 100%;
  padding: 1rem 1.25rem;
  background-color: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: 0.625rem;
  color: var(--app-text);
  text-decoration: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.tile:hover,
.tile:focus-visible {
  color: var(--app-text);
  background-color: var(--app-surface-hover);
  border-color: var(--app-border-hover);
}

.tile-label {
  font-size: 0.875rem;
  color: var(--app-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-value {
  margin: 0.375rem 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--app-text);
  font-variant-numeric: tabular-nums;
}

.tile-unit {
  margin-left: 0.25rem;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--app-text-muted);
}

.tile-age {
  font-size: 0.75rem;
  color: var(--app-text-muted);
}

.tile-age.is-late { color: #f0b44c; }
.tile-age.is-stale { color: #f87171; }

.tile-age.is-late::before,
.tile-age.is-stale::before {
  content: "";
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.35rem;
  border-radius: 50%;
  background-color: currentColor;
  vertical-align: 0.05rem;
}

@media (max-width: 575.98px) {
  .tile { padding: 0.75rem 0.875rem; }
  .tile-label { font-size: 0.8rem; white-space: normal; } /* libellé sur 2 lignes plutôt que tronqué */
  .tile-value { font-size: 1.5rem; }
}

.dashboard-status {
  font-size: 0.75rem;
  color: var(--app-text-muted);
}

/* ---------- Graphiques ---------- */

.chart-range {
  font-size: 0.875rem;
  color: var(--app-text-secondary);
}

.chart-box {
  position: relative;
  height: 60vh;
  min-height: 320px;
  max-height: 560px;
  padding: 0.75rem;
  background-color: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: 0.625rem;
}

@media (max-width: 575.98px) {
  .chart-box { height: 50vh; min-height: 280px; padding: 0.5rem; }
}

.chart-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--app-text-muted);
  pointer-events: none;
}

.chart-status[hidden] { display: none; }

/* ---------- Barre d'onglets fixe en bas de l'écran sur téléphone ---------- */

.tab-bar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 1030;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background-color: var(--app-surface);
  border-top: 1px solid var(--app-border);
}

.tab-bar-item {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 0.125rem;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem; /* 6 onglets sur un écran de 360 px */
  color: var(--app-text-muted);
  text-decoration: none;
}

.tab-bar-item.active {
  color: var(--app-text);
  font-weight: 600;
}

/* Laisse la place à la barre d'onglets pour que le bas de page reste visible. */
@media (max-width: 767.98px) {
  body.with-tabbar main {
    padding-bottom: calc(4rem + env(safe-area-inset-bottom)) !important;
  }
}

/* Permet à un élément flex de rétrécir (et à son texte d'être tronqué avec
   "…") au lieu de pousser ses voisins hors de l'écran. Absent de Bootstrap. */
.min-w-0 {
  min-width: 0;
}

/* Titre d'une liste : en entier sur téléphone (sur plusieurs lignes si
   besoin), sur une ligne tronquée par "…" à partir de 576 px. */
@media (min-width: 576px) {
  .list-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.measure-value {
  font-variant-numeric: tabular-nums;
}

/* ---------- Chauffage ---------- */

/* Un code couleur par mode du fil pilote, du plus chaud au plus froid. */
.mode-badge {
  --mode-color: #64748b;
  display: inline-block;
  min-width: 5.5rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid color-mix(in srgb, var(--mode-color) 45%, transparent);
  border-radius: 999px;
  background-color: color-mix(in srgb, var(--mode-color) 16%, transparent);
  color: var(--mode-color);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
}

.mode-confort   { --mode-color: #f87171; }
.mode-confort-1 { --mode-color: #fb923c; }
.mode-confort-2 { --mode-color: #fbbf24; }
.mode-eco       { --mode-color: #60a5fa; }
.mode-hors-gel  { --mode-color: #22d3ee; }
.mode-stop      { --mode-color: #94a3b8; }
.mode-unknown   { --mode-color: #64748b; }

.forced-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background-color: #f0b44c;
  color: #0f1117;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.command-status {
  margin-top: 0.375rem;
  font-size: 0.8rem;
}

.command-status.is-mismatch { color: #f87171; }

/* Formulaire d'un radiateur sur une ligne : mode et forçage (envoi automatique). */
.actuator-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.actuator-form .form-select {
  flex: 1 1 10rem;
  max-width: 14rem;
  background-color: var(--app-page-bg);
}

@media (max-width: 575.98px) {
  .actuator-form .form-select { max-width: none; }
}

.actuator-form[aria-busy="true"] {
  opacity: 0.6;
  pointer-events: none;
}

/* ---------- Planning ---------- */

.schedule-picker {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.schedule-picker .btn { white-space: nowrap; }

.week-chart {
  padding: 0.75rem;
  background-color: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: 0.625rem;
}

.week-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.week-day {
  flex: 0 0 2.25rem;
  font-size: 0.8rem;
  color: var(--app-text-secondary);
}

.week-row.is-today .week-day {
  color: var(--app-text);
  font-weight: 600;
}

.week-bar {
  position: relative;
  display: flex;
  flex: 1;
  height: 1.75rem;
  overflow: hidden;
  border-radius: 0.375rem;
  background-color: var(--app-page-bg);
}

.week-scale .week-bar {
  height: 1rem;
  overflow: visible;
  background: none;
  font-size: 0.7rem;
  color: var(--app-text-muted);
}

.week-scale .week-bar span { position: absolute; top: 0; }
.week-scale .week-bar span.end { right: 0; }

.week-seg {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 0.35rem;
  overflow: hidden;
  border-right: 1px solid var(--app-page-bg);
  background-color: color-mix(in srgb, var(--mode-color) 30%, transparent);
  color: var(--mode-color);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.week-seg:last-of-type { border-right: 0; }
.week-seg span { overflow: hidden; text-overflow: ellipsis; }

.week-now {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background-color: var(--app-text);
  pointer-events: none;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.switch-form {
  display: flex;
  flex: 1;
  gap: 0.5rem;
}

.switch-form .form-control { flex: 0 0 7rem; }
.switch-form .form-select { flex: 1 1 auto; max-width: 12rem; }

.switch-form[aria-busy="true"] {
  opacity: 0.6;
  pointer-events: none;
}

/* Liste de choix du mode, aux couleurs du mode choisi. */
.mode-select {
  color: var(--mode-color);
  font-weight: 600;
}

.mode-select option {
  color: var(--app-text);
  font-weight: 400;
}

.day-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
