/* Maison Énergie — style de l'application.
   Trois mises en page : ordinateur (menu latéral, panneaux côte à côte), tablette
   (menu latéral, panneaux empilés), téléphone (une colonne, onglets en bas). */

:root {
  color-scheme: light dark;

  --page: #f9f9f7;
  --surface: #fcfcfb;
  --raised: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #6b6a65;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --hover: rgba(11, 11, 11, 0.045);
  --accent: #2a78d6;
  --shadow: 0 6px 24px rgba(11, 11, 11, 0.12);

  /* Une couleur par grandeur de la maison, toujours la même. */
  --s-consumption: #2a78d6;
  --s-grid: #eb6834;
  --s-battery: #1baf7a;
  --s-production: #eda100;
  --s-ev: #e87ba4;

  /* Couleurs d'état, jamais réutilisées pour une série. */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --raised: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #9a988f;
    --grid: #2c2c2a;
    --baseline: #383835;
    --hover: rgba(240, 239, 236, 0.06);
    --accent: #3987e5;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);

    --s-consumption: #3987e5;
    --s-grid: #d95926;
    --s-battery: #199e70;
    --s-production: #c98500;
    --s-ev: #d55181;
  }
}

.c-consumption { --c: var(--s-consumption); }
.c-grid { --c: var(--s-grid); }
.c-battery { --c: var(--s-battery); }
.c-production { --c: var(--s-production); }
.c-ev { --c: var(--s-ev); }

.tone-good { --tone: var(--good); }
.tone-warning { --tone: var(--warning); }
.tone-serious { --tone: var(--serious); }
.tone-critical { --tone: var(--critical); }
.tone-info { --tone: var(--ink-3); }

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p,
dl,
dd,
ul {
  margin: 0;
  padding: 0;
}

ul {
  list-style: none;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

code {
  font: 12.5px var(--mono);
}

.noscript {
  padding: 24px;
}

.icon {
  flex: none;
}

.icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.swatch {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--c);
}

/* ------------------------------------------------------------ ossature */

.app {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  height: 100dvh;
  padding: 20px 14px 18px;
  background: var(--surface);
  border-right: 1px solid var(--grid);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand img {
  border-radius: 8px;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 500;
}

.side-nav a:hover {
  background: var(--hover);
  color: var(--ink);
}

.side-nav a.on {
  background: var(--hover);
  color: var(--ink);
  font-weight: 650;
  box-shadow: inset 3px 0 0 var(--accent);
}

.box {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding: 12px 10px 0;
  border-top: 1px solid var(--grid);
  font-size: 13px;
}

.box-name {
  color: var(--ink-3);
  font-size: 12px;
}

.box-version {
  color: var(--ink-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.main {
  min-width: 0;
  width: 100%;
  max-width: 1640px;
  padding: 18px 28px 24px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 40px;
  margin-bottom: 16px;
}

.title {
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.meta {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--ink-2);
  font-size: 13.5px;
}

.clock {
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: none;
}

/* ----------------------------------------------------- états et alertes */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.pill .icon {
  color: var(--tone);
}

.alerts:not(:empty) {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-left: 3px solid var(--tone);
  border-radius: 10px;
  font-size: 14px;
}

.alert .icon {
  margin-top: 1px;
  color: var(--tone);
}

/* ------------------------------------------------------------- panneaux */

.grid {
  display: grid;
  gap: 16px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 16px 20px 18px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 14px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 20px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.panel-title {
  font-size: 15px;
  font-weight: 650;
}

.panel-note {
  margin-top: 1px;
  color: var(--ink-3);
  font-size: 12.5px;
}

.fill {
  min-width: 0;
}

.empty {
  padding: 28px 8px;
  color: var(--ink-3);
  text-align: center;
}

.more {
  color: var(--ink-2);
  font-size: 13px;
}

/* --------------------------------------------------------- tableau de bord */

.dash {
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.p-now {
  grid-column: span 7;
}

.p-today {
  grid-column: span 5;
  container-type: inline-size;
}

.p-chart {
  grid-column: span 8;
}

.p-devices {
  grid-column: span 4;
}

.now-note {
  min-height: 21px;
  margin: -6px 0 6px;
  color: var(--ink-2);
  font-size: 14px;
}

/* Schéma des flux */

.flow {
  min-width: 0;
}

.flow-svg {
  display: block;
  margin: 0 auto;
}

.flow-track {
  fill: none;
  stroke: var(--grid);
  stroke-width: 2;
}

.flow-move {
  fill: none;
  stroke: var(--c);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 0.1 13;
  opacity: 0;
}

.flow-move.on {
  opacity: 1;
  animation: flow 1.1s linear infinite;
}

.flow-move.on.back {
  animation-direction: reverse;
}

@keyframes flow {
  from {
    stroke-dashoffset: 13.1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flow-move.on {
    animation: none;
  }
}

.flow-hub {
  fill: var(--baseline);
}

.flow-ring {
  fill: var(--surface);
  stroke: var(--c);
  stroke-width: 2;
}

.flow-node.c-battery .flow-ring {
  stroke: var(--grid);
  stroke-width: 4;
}

.flow-gauge {
  fill: none;
  stroke: var(--c);
  stroke-width: 4;
  stroke-linecap: round;
}

.flow-icon {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.flow-label {
  fill: var(--ink-2);
  font-size: 13px;
}

.flow-value {
  fill: var(--ink);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.flow-note {
  fill: var(--ink-3);
  font-size: 12px;
}

/* Bilan */

.summary {
  display: grid;
  gap: 16px;
}

.hero-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 13.5px;
}

.hero-value {
  font-size: 54px;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.025em;
}

.coverage {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-top: 8px;
  color: var(--ink-2);
  font-size: 13px;
}

.coverage .icon {
  margin-top: 1px;
  color: var(--tone);
}

.hero-unit {
  margin-left: 8px;
  color: var(--ink-2);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 20px;
  border-top: 1px solid var(--grid);
}

/* Dans un panneau étroit, les lignes du bilan passent sur une seule colonne. */
@container (max-width: 400px) {
  .stats,
  .meters {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
}

.stat dt {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 13px;
  white-space: nowrap;
}

.stat dd {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 24px;
}

.meter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 13.5px;
}

.meter-head strong {
  font-size: 18px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.meter-bar {
  height: 8px;
  margin: 6px 0;
  background: var(--grid);
  border-radius: 4px;
  overflow: hidden;
}

.meter-fill {
  width: 0;
  height: 100%;
  background: var(--ink-2);
  border-radius: 4px;
}

.meter-hint {
  color: var(--ink-3);
  font-size: 12px;
}

/* Liste d'appareils */

.device-list {
  display: grid;
  gap: 2px;
}

.device-list a,
.device-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  background: none;
  border: 0;
  border-radius: 9px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.device-list a:hover,
.device-list button:hover {
  background: var(--hover);
}

.device-list button.on {
  background: var(--hover);
  box-shadow: inset 3px 0 0 var(--accent);
}

.device-name {
  display: grid;
  min-width: 0;
}

.device-name strong {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-name span {
  color: var(--ink-3);
  font-size: 12.5px;
}

.device-state {
  display: grid;
  justify-items: end;
}

.since {
  color: var(--ink-3);
  font-size: 12px;
}

/* ----------------------------------------------------------- graphiques */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  color: var(--ink-2);
  font-size: 13px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart {
  position: relative;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}

.chart.pickable {
  cursor: pointer;
}

.chart-svg {
  display: block;
  overflow: visible;
}

.gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.baseline,
.tickmark {
  stroke: var(--baseline);
  stroke-width: 1;
}

.tick {
  fill: var(--ink-3);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.tick-y {
  text-anchor: end;
}

.line {
  fill: none;
  stroke: var(--c);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.area {
  fill: var(--c);
  opacity: 0.1;
}

.point {
  fill: var(--c);
}

.dot {
  fill: var(--c);
  stroke: var(--surface);
  stroke-width: 2;
}

.crosshair {
  stroke: var(--ink-3);
  stroke-width: 1;
}

.direct {
  fill: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
}

.seg {
  fill: var(--c);
}

.band {
  fill: var(--hover);
}

.tip {
  position: absolute;
  z-index: 5;
  min-width: 190px;
  padding: 10px 12px;
  background: var(--raised);
  border: 1px solid var(--grid);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  pointer-events: none;
}

.tip-title {
  margin-bottom: 6px;
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
}

.tip-rows {
  display: grid;
  gap: 3px;
}

.tip-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
}

.tip-row dt {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-2);
  white-space: nowrap;
}

.tip-row dd {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tip-total {
  margin-top: 3px;
  padding-top: 5px;
  border-top: 1px solid var(--grid);
}

.tip-empty {
  color: var(--ink-3);
}

/* ------------------------------------------------------------ historique */

.filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-bottom: 16px;
}

.spacer {
  flex: 1;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 10px;
}

.segmented button {
  min-height: 30px;
  padding: 0 14px;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--ink-2);
  font-weight: 500;
  cursor: pointer;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button.on {
  background: var(--ink);
  color: var(--page);
  font-weight: 600;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.stepper-label {
  min-width: 216px;
  font-size: 15px;
  font-weight: 650;
  text-align: center;
}

.btn,
.icon-btn,
.date-input,
.search {
  min-height: 38px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 10px;
}

.btn {
  padding: 0 14px;
  font-weight: 500;
  cursor: pointer;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  padding: 0;
  cursor: pointer;
}

.btn:hover:not(:disabled),
.icon-btn:hover:not(:disabled) {
  background: var(--hover);
}

.btn:disabled,
.icon-btn:disabled {
  color: var(--ink-3);
  opacity: 0.55;
  cursor: default;
}

.date-input,
.search {
  padding: 0 10px;
}

.search {
  width: 220px;
}

.history-grid {
  grid-template-columns: minmax(0, 1fr) 372px;
  align-items: start;
}

.history-charts {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.p-summary {
  position: sticky;
  top: 16px;
}

.p-summary .stats,
.p-summary .meters {
  grid-template-columns: minmax(0, 1fr);
}

/* -------------------------------------------------------------- tableaux */

.table-wrap {
  min-width: 0;
  overflow-x: auto;
}

.data {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.data th,
.data td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--grid);
  text-align: right;
  white-space: nowrap;
}

.data th:first-child,
.data .left {
  text-align: left;
}

.data thead th {
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  vertical-align: bottom;
}

.th-unit {
  display: block;
  color: var(--ink-3);
  font-weight: 400;
}

.data tbody th {
  font-weight: 500;
}

.data a {
  text-decoration-color: var(--baseline);
  text-underline-offset: 3px;
}

.data a:hover {
  text-decoration-color: currentColor;
}

.data tbody tr:hover {
  background: var(--hover);
}

.data tfoot th,
.data tfoot td {
  border-top: 2px solid var(--baseline);
  border-bottom: 0;
  font-weight: 650;
}

.data .stale td,
.data .stale th {
  color: var(--ink-3);
}

/* Les noms de mesures sont longs : ils passent à la ligne plutôt que d'élargir le tableau. */
.points tbody th {
  white-space: normal;
  overflow-wrap: break-word;
}

.data .source code {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
}

.reason {
  margin-left: 10px;
  color: var(--ink-2);
  font-size: 13px;
  white-space: normal;
}

/* ------------------------------------------------------------- appareils */

.devices {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
}

.p-list {
  grid-column: span 4;
}

.p-detail {
  grid-column: span 8;
}

.p-drivers,
.p-sources {
  grid-column: span 6;
}

.p-detail .panel-head {
  align-items: center;
}

.device-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px 20px;
  margin-bottom: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
}

.facts dt {
  color: var(--ink-3);
  font-size: 12px;
}

.facts dd {
  overflow-wrap: anywhere;
  font-size: 13.5px;
  font-weight: 500;
}

.p-detail .table-wrap {
  max-height: 560px;
  overflow-y: auto;
}

.p-detail thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
}

/* ------------------------------------------------- connexion et réglages */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

.gate {
  display: grid;
  grid-template-columns: minmax(0, 410px);
  place-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
}

/* Une seule colonne qui peut rétrécir : un champ de saisie ne force jamais la largeur. */
.gate-card,
.form,
.field {
  grid-template-columns: minmax(0, 1fr);
}

.gate-card {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 28px 26px 26px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 16px;
}

.gate-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 2px;
}

.gate-brand img {
  border-radius: 11px;
}

.gate-brand h1 {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.gate-text,
.notice {
  color: var(--ink-2);
}

.command {
  display: block;
  padding: 10px 12px;
  background: var(--page);
  border: 1px solid var(--grid);
  border-radius: 9px;
  font-size: 13.5px;
  -webkit-user-select: all;
  user-select: all;
}

.form {
  display: grid;
  gap: 14px;
  max-width: 460px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 13.5px;
  font-weight: 600;
}

.field-row {
  display: flex;
  gap: 8px;
}

/* 16 px : en dessous, l'iPhone agrandit la page à chaque saisie. */
.field-row input,
.field-row select {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  background: var(--raised);
  border: 1px solid var(--baseline);
  border-radius: 10px;
  font-size: 16px;
}

.reveal {
  min-height: 44px;
  padding: 0 12px;
  background: none;
  border: 1px solid var(--grid);
  border-radius: 10px;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
}

.reveal:hover {
  background: var(--hover);
}

.btn.primary {
  min-height: 44px;
  background: var(--ink);
  border-color: var(--ink);
  color: var(--page);
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: var(--ink);
  opacity: 0.86;
}

.btn.primary:disabled {
  color: var(--page);
}

.form-message {
  min-height: 21px;
  color: var(--ink-2);
  font-size: 14px;
}

.form-hint {
  color: var(--ink-3);
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

.settings {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.stack {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.p-sessions .notice {
  margin-bottom: 6px;
}

.subhead {
  margin: 18px 0 4px;
  padding-top: 14px;
  border-top: 1px solid var(--grid);
  font-size: 13.5px;
  font-weight: 650;
}

.push-devices {
  display: grid;
  margin-bottom: 10px;
}

.push-devices li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
}

/* Journal */

.p-journal {
  grid-column: 1 / -1;
}

.journal {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.journal li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--grid);
}

.journal li:last-child {
  border-bottom: 0;
}

.journal .icon {
  margin-top: 2px;
  color: var(--tone);
}

.journal-text {
  display: grid;
  min-width: 0;
}

.journal-text strong {
  font-weight: 600;
}

.journal-text span {
  color: var(--ink-2);
  font-size: 13.5px;
  overflow-wrap: anywhere;
}

.journal time {
  display: grid;
  justify-items: end;
  color: var(--ink-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.journal time span {
  color: var(--ink-3);
  font-size: 12px;
}

.p-box .facts {
  margin-bottom: 0;
  border-bottom: 0;
  padding-bottom: 0;
}

/* ----------------------------------------------------------- installation */

.save-bar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 12px;
}

.save-bar .actions {
  margin-top: 0;
}

.save-bar .form-message {
  min-height: 0;
}

.setup-grid {
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  align-items: start;
}

.cards,
.sources {
  display: grid;
  gap: 12px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.card,
.source {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  background: var(--page);
  border: 1px solid var(--grid);
  border-radius: 12px;
}

.card-head,
.source-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.card-head .actions {
  margin-top: 0;
}

.card-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 14px;
}

.add-row {
  padding-top: 4px;
}

.test-result:not(:empty) {
  display: grid;
  gap: 6px;
}

.test-output {
  max-height: 220px;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 9px;
  font: 12.5px/1.5 var(--mono);
  white-space: pre-wrap;
}

.follow {
  display: grid;
  gap: 6px;
}

.follow .subhead {
  margin: 2px 0 0;
}

.follow .form-hint {
  margin: 0;
}

.follow-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.follow-list .check {
  flex-wrap: wrap;
  row-gap: 2px;
}

.follow-id {
  color: var(--ink-3);
  font: 12.5px/1.4 var(--mono);
  overflow-wrap: anywhere;
}

.role {
  display: grid;
  gap: 8px;
  padding: 14px 0;
  border-top: 1px solid var(--grid);
}

.role:first-child {
  padding-top: 0;
  border-top: 0;
}

.role > .btn {
  justify-self: start;
}

.role-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
}

.rank {
  padding: 2px 8px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
}

.live {
  flex: 1;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.source-tools {
  display: inline-flex;
  gap: 4px;
}

.source-selects {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.source-selects select {
  min-width: 0;
  min-height: 40px;
  padding: 0 8px;
  background: var(--raised);
  border: 1px solid var(--baseline);
  border-radius: 10px;
  color: inherit;
  font: inherit;
}

.source-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  color: var(--ink-2);
  font-size: 13.5px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.btn.small,
.icon-btn.small {
  min-height: 32px;
  font-size: 13.5px;
}

.icon-btn.small {
  width: 32px;
}

/* ============================================================ tablette */

@media (max-width: 1179px) {
  .app {
    grid-template-columns: 208px minmax(0, 1fr);
  }

  .main {
    padding: 18px 20px 28px;
  }

  .p-now,
  .p-today,
  .p-chart,
  .p-devices,
  .p-list,
  .p-detail,
  .p-drivers,
  .p-sources {
    grid-column: 1 / -1;
  }

  .history-grid,
  .settings,
  .setup-grid {
    grid-template-columns: minmax(0, 1fr);
  }


  .p-summary {
    position: static;
    order: -1;
  }

  .p-summary .stats,
  .p-summary .meters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .p-detail .table-wrap {
    max-height: none;
  }
}

/* =========================================================== téléphone */

@media (max-width: 859px) {
  .app {
    display: block;
  }

  .side {
    display: none;
  }

  .main {
    padding: 14px 14px calc(86px + env(safe-area-inset-bottom));
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  .top {
    margin-bottom: 12px;
  }

  .title {
    font-size: 21px;
  }

  .clock {
    display: none;
  }

  .tabs {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    display: flex;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--grid);
  }

  .tabs a {
    display: grid;
    flex: 1;
    justify-items: center;
    gap: 2px;
    padding: 6px 4px;
    border-radius: 10px;
    color: var(--ink-3);
    font-size: 11.5px;
    font-weight: 500;
    text-decoration: none;
  }

  .tabs a.on {
    color: var(--ink);
    font-weight: 650;
  }

  .tabs a.on .icon {
    color: var(--accent);
  }

  .grid,
  .history-charts {
    gap: 12px;
  }

  .panel {
    padding: 14px 14px 16px;
  }

  .hero-value {
    font-size: 48px;
  }

  .stats,
  .meters,
  .p-summary .stats,
  .p-summary .meters {
    grid-template-columns: minmax(0, 1fr);
  }

  .filters {
    gap: 10px;
  }

  .filters .spacer {
    display: none;
  }

  .stepper {
    flex: 1 1 100%;
    justify-content: space-between;
    order: -1;
  }

  .stepper-label {
    min-width: 0;
  }

  .segmented {
    flex: 1;
  }

  .segmented button {
    flex: 1;
    min-height: 36px;
    padding: 0 8px;
  }

  .search {
    width: 100%;
  }

  .source-selects {
    grid-template-columns: minmax(0, 1fr);
  }

  .tabs a {
    font-size: 11px;
  }

  .data th,
  .data td {
    padding: 8px 8px;
  }

  .points code {
    font-size: 11.5px;
  }
}

/* -------------------------------------------------------------- pilotage */

/* Consigne du boîtier : trait neutre en pointillés, distinct de la batterie mesurée
   même sans les couleurs. */
.c-target { --c: var(--ink-2); }

.line.c-target {
  stroke-dasharray: 6 4;
}

.swatch.c-target {
  width: 14px;
  height: 3px;
  border-radius: 1px;
  background: repeating-linear-gradient(90deg, var(--c) 0 4px, transparent 4px 7px);
}

.pilot {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
}

.p-pilot-mode {
  grid-column: span 5;
}

.p-pilot-now {
  grid-column: span 7;
}

.p-pilot-chart,
.p-pilot-settings {
  grid-column: 1 / -1;
}

.pilot-lead {
  margin-bottom: 14px;
  color: var(--ink-2);
  font-size: 14px;
}

.pilot-actions {
  margin: 16px 0 8px;
}

.confirm {
  margin: 4px 0 10px;
  padding: 12px 14px;
  background: var(--raised);
  border: 1px solid var(--grid);
  border-left: 3px solid var(--warning);
  border-radius: 10px;
  font-size: 14px;
}

.confirm-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-weight: 650;
}

.confirm-title .icon {
  color: var(--warning);
}

.confirm .actions {
  margin-top: 12px;
}

.pilot-stats {
  grid-template-columns: minmax(0, 1fr);
}

.pilot-stats .stat dd {
  white-space: normal;
  text-align: right;
}

.p-pilot-now .alert {
  margin-bottom: 12px;
}

.chart-aside {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
}

.pilot-table {
  max-height: 420px;
  overflow-y: auto;
}

.pilot-rule {
  display: grid;
  gap: 6px;
  margin: 18px 0 12px;
}

.pilot-rule .field {
  max-width: 460px;
  margin-top: 8px;
}

.pilot-fine {
  margin-top: 18px;
}

.pilot-fine summary {
  margin-bottom: 12px;
  color: var(--ink-2);
  font-weight: 600;
  cursor: pointer;
}

.save-bar.pilot-save {
  position: static;
  margin: 18px 0 0;
}

.field-unit {
  align-self: center;
  min-width: 18px;
  color: var(--ink-3);
  font-size: 13px;
}

@media (max-width: 1179px) {
  .p-pilot-mode,
  .p-pilot-now {
    grid-column: 1 / -1;
  }
}

.pilot-note {
  margin-top: 12px;
}

.p-pilot-settings .card-fields {
  align-items: start;
}

/* Rythme d'une mesure, sous son âge. */
.points .rhythm {
  display: block;
  color: var(--ink-3);
  font-size: 12px;
}
