:root {
  color-scheme: dark;
  --bg: #1e1e1e;
  --panel: #252526;
  --line: #454545;
  --text: #eeeeee;
  --muted: #aaaab2;
  --accent: #b890ef;
  /* Relief commun des tuiles : lumière en haut à gauche. */
  --tile-edge-light: color-mix(in srgb, var(--line) 60%, var(--accent) 40%);
  --tile-edge-dark: color-mix(in srgb, var(--line) 65%, black 35%);
  --tile-cast-shadow: 5px 8px 16px rgba(0, 0, 0, .23), 1px 2px 4px rgba(0, 0, 0, .12);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  font:
    15px system-ui,
    sans-serif;
  color: var(--text);
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 5%;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  gap: 12px;
  font-size: 28px;
  color: var(--accent);
  text-decoration: none;
}
.brand span {
  font-size: 18px;
  letter-spacing: 3px;
}
.brand small {
  display: block;
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 2px;
  margin-top: 4px;
}
#connection {
  font-size: 13px;
  color: var(--muted);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.header-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  padding: 4px 8px;
  border-radius: 20px;
  transition: background 0.2s ease;
}
.header-profile:hover {
  background: rgba(255, 255, 255, 0.05);
}
.avatar-ring {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--line);
  border: 2px solid var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.avatar-ring.large {
  width: 64px;
  height: 64px;
  border-width: 3px;
}
.user-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.user-initials {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  text-transform: uppercase;
}
.user-initials.large {
  font-size: 22px;
}
.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.pilotage-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  text-transform: uppercase;
}
.pilotage-badge.live {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  color: var(--accent);
}
.pilotage-badge.demo {
  background: rgba(234, 179, 8, 0.15);
  border-color: rgba(234, 179, 8, 0.5);
  color: #facc15;
}
.user-profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.account-name-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: var(--text);
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  background: var(--line);
  color: var(--muted);
}
.section-divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 24px 0 20px;
}
.dashboard-actions-dialog .action-buttons-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
}
.dashboard-actions-dialog .action-item {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  padding: 10px 14px;
  font-size: 14px;
  border-radius: 8px;
}
.dashboard-actions-dialog .danger-btn {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
}
main {
  max-width: 1400px;
  margin: auto;
  padding: 36px 5%;
}
.heading {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 30px;
}
.eyebrow {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--accent);
}
h1 {
  font-size: 34px;
  font-weight: 500;
  margin: 8px 0;
}
h2 {
  font-size: 18px;
  font-weight: 500;
  margin: 0 0 22px;
}
p {
  color: var(--muted);
  line-height: 1.5;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}
.card {
  min-height: 175px;
}
.label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 24px;
}
.card strong {
  font-size: 31px;
  font-weight: 500;
  display: block;
  margin-bottom: 10px;
}
.card small,
.switch-row small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}
.solar strong,
.yellow {
  color: #ecd08c;
}
.blue,
.grid strong {
  color: #a8caff;
}
.battery strong {
  color: var(--accent);
}
progress {
  width: 100%;
  height: 5px;
  accent-color: var(--accent);
  display: block;
  margin: 12px 0;
}
.columns {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 24px;
}
.panel {
  margin-bottom: 24px;
  min-width: 0;
}
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.section-title span,
.hint {
  font-size: 11px;
  color: var(--muted);
}
.legend {
  display: flex;
  gap: 20px;
  font-size: 11px;
}
canvas {
  width: 100%;
  height: 240px;
  display: block;
  margin-top: 15px;
}
label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 14px 0 7px;
}
input,
select,
button {
  font: inherit;
  border-radius: 7px;
  padding: 10px;
  border: 1px solid #405248;
}
input,
select {
  background: #101916;
  color: var(--text);
  width: 100%;
}
button {
  background: var(--accent);
  color: #1b2c1c;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}
button:hover {
  filter: brightness(1.08);
}
button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
button.secondary {
  background: transparent;
  color: var(--text);
}
form button {
  margin-top: 18px;
  width: 100%;
}
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.switch-row small {
  margin-top: 6px;
}
.buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.switch-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
td,
th {
  text-align: left;
  padding: 14px 10px;
  border-bottom: 1px solid var(--line);
}
th {
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
}
.table-wrap {
  overflow: auto;
}
summary {
  cursor: pointer;
  font-size: 17px;
}
footer {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 10px;
}
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 20px;
  background: #e4f5dc;
  color: #192a1b;
  border-radius: 10px;
  box-shadow: 0 10px 35px #0005;
  max-width: 90vw;
  font-size: 13px;
}
#toast.error {
  background: #f5d8ce;
  color: #581c13;
}
@media (max-width: 950px) {
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  .columns {
    grid-template-columns: 1fr;
  }
  .heading {
    align-items: flex-start;
    flex-direction: column;
  }
  .section-title {
    flex-direction: column;
  }
  .section-title h2 {
    margin-bottom: 5px;
  }
}
@media (max-width: 480px) {
  main {
    padding: 24px 16px;
  }
  .card,
  .panel {
    padding: 18px;
  }
  .card strong {
    font-size: 25px;
  }
  h1 {
    font-size: 28px;
  }
  .switch-row {
    flex-wrap: wrap;
  }
  .metrics {
    gap: 10px;
  }
  .label {
    min-height: 30px;
    margin-bottom: 12px;
  }
  header {
    padding: 20px 16px;
  }
}

/* Le fond initial utilise le thème neutre, avant le chargement des préférences. */
.card,
.panel {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  border-radius: 6px;
  box-shadow: 2px 2px 5px #000;
  border: 0;
}
nav {
  display: flex;
  gap: 8px;
  padding: 15px 5%;
  overflow: auto;
  border-bottom: 1px solid var(--line);
}
nav a {
  color: var(--muted);
  padding: 10px 14px;
  text-decoration: none;
  white-space: nowrap;
  border-radius: 6px;
}
nav a[aria-current="page"] {
  background: #ffffff18;
  color: white;
}
[hidden] {
  display: none !important;
}
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
}
.dashboard-grid .panel {
  margin: 0;
}
.clock {
  font-size: 5rem;
  text-align: center;
  font-weight: 300;
}
.date {
  text-align: center;
  margin-bottom: 24px;
}
.reading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid #ffffff0d;
}
.reading span {
  color: var(--muted);
}
.reading b {
  text-align: right;
  font-weight: 500;
}
.persons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}
.avatar {
  border-radius: 50%;
  background: #ffffff15;
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  font-size: 22px;
}
.persons small {
  display: block;
  font-size: 10px;
  color: var(--muted);
}
.placeholder {
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
  background: #0002;
  border: 1px dashed #ffffff22;
  border-radius: 6px;
  padding: 25px;
  color: var(--muted);
  margin-bottom: 15px;
}
.device-controls {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 18px;
}
.floorplan {
  min-height: 420px;
}
.unavailable {
  font-size: 12px;
  color: #d8ad7f;
}
.thermostat {
  font-size: 30px;
}
.dashboard-grid h3 {
  font-size: 16px;
  font-weight: 500;
}
.dashboard-grid a {
  color: var(--accent);
}
body.offline main {
  opacity: 0.65;
}
@media (max-width: 1050px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 650px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .clock {
    font-size: 4rem;
  }
  .persons {
    gap: 4px;
  }
  .heading {
    gap: 8px;
  }
  header {
    gap: 15px;
  }
  #connection {
    max-width: 150px;
  }
  .buttons {
    flex-shrink: 1;
    flex-wrap: wrap;
  }
}

body.has-background {
  background-image: url("/background.jpg");
  background-size: cover;
  background-position: center;
}
.floorplan img {
  display: block;
  width: 100%;
  height: auto;
}
.floorplan:has(img) {
  padding: 0;
  min-height: 0;
}

/* Les couleurs fonctionnelles restent des variables, y compris les formulaires. */
input,
select {
  background: var(--bg);
  color: var(--text);
  border-color: var(--line);
}
button {
  background: var(--accent);
  color: var(--bg);
}
button.secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}
.card,
.panel {
  background: var(--panel);
  border-color: var(--line);
}
.metrics {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
[hidden] {
  display: none !important;
}
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-box {
  width: min(440px, 100%);
  padding: 36px;
  margin: auto;
}
#login-error {
  color: #e07865;
}
.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 16px;
}
input[type="color"] {
  width: 100%;
  height: 45px;
  padding: 4px;
}
input[type="checkbox"] {
  width: auto;
  margin: 0 10px 0 0;
}
.card-option {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 12px 0;
}
.card-option label {
  flex: 1;
  margin: 0;
}
body[data-theme="light"] .solar,
body[data-theme="light"] .yellow {
  color: #765300;
}
body[data-theme="light"] .grid,
body[data-theme="light"] .blue {
  color: #225c91;
}
body[data-theme="light"].has-background {
  background: var(--bg);
}
@media (max-width: 700px) {
  .widget-editor {
    grid-template-columns: 1fr;
  }
  header {
    flex-wrap: wrap;
    gap: 16px;
  }
}
body[data-theme] {
  background: var(--bg);
}
nav a[aria-current="page"] {
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--line);
}
.reading {
  border-bottom-color: var(--line);
}

/* Composants et navigation : palette commune aux thèmes personnalisés. */
.settings-tabs {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 1rem 0 1.6rem;
}
.settings-tabs-divider {
  align-self: stretch;
  width: 1px;
  min-height: 1.5rem;
  background: var(--line);
  margin: 0 0.2rem;
}
.settings-tabs-divider[hidden] {
  display: none;
}
.settings-tabs [aria-current] {
  border-color: var(--accent);
  color: var(--accent);
}
.toggle-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}
.toggle-row input,
.remember input {
  width: auto;
  accent-color: var(--accent);
}
.remember {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
#history-chart {
  width: 100%;
  height: 340px;
  margin-top: 2rem;
}
.legend-item {
  display: inline-block;
  padding: 0.5rem 1rem;
}
#navigation {
  gap: 0.4rem;
  flex-wrap: wrap;
}
#navigation a {
  border-radius: 12px;
  padding: 0.75rem 1rem;
  transition: background 0.15s;
}
.panel,
.card {
  border-radius: 18px;
  box-shadow: 0 8px 28px #00000012;
}
.card {
  border-top: 2px solid var(--accent);
}
.login-box {
  max-width: 420px;
  border-top: 3px solid var(--accent);
}
.login-page {
  background:
    radial-gradient(ellipse at 15% 15%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 60%), var(--bg);
}
button {
  border-radius: 10px;
}
#zendure-values .card strong {
  font-size: 1.5rem;
}
#zendure-values .card small {
  overflow-wrap: anywhere;
}
textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  font: 13px/1.6 monospace;
  resize: vertical;
}
pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.editor-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  align-items: end;
  margin: 1rem 0;
}
.sensor-metric {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 85px;
}
.climate-sensor .sonoff-state {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  padding-top: 1rem;
}
.sensor-icon {
  color: var(--accent);
  font-size: 1.4rem;
}
.sensor-metric strong {
  font-size: 1.5rem;
  color: var(--text);
}
.integration-card {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.8rem;
  border-bottom: 1px solid var(--line);
  padding: 1rem 0;
}
.integration-card p {
  grid-column: 1/-1;
}
.history-picker select {
  width: 100%;
  min-height: 180px;
}
.battery-pack strong {
  font-size: 2.4rem !important;
}
meter {
  display: block;
  width: 100%;
  height: 20px;
  accent-color: var(--accent);
}
#view-dashboard > label {
  max-width: 450px;
}
#view-dashboard .metrics {
  margin-top: 1.5rem;
}
#view-dashboard .card small {
  overflow-wrap: anywhere;
}

/* Grilles uniformes : les longs noms passent sur deux lignes sans déplacer les
   mesures ni les actions des cartes voisines. */
#sensor-devices,
#light-devices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  grid-auto-rows: 1fr;
  gap: 20px;
  align-items: stretch;
}
#sensor-devices > .panel,
#light-devices > .panel {
  height: 100%;
  min-height: 230px;
  margin: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
#sensor-devices h2,
#light-devices h2 {
  min-height: 2.6em;
  margin-bottom: 12px;
  overflow-wrap: anywhere;
}
#sensor-devices .sonoff-state {
  margin-top: auto;
}
.light-card .buttons {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.light-icon {
  width: 52px;
  height: 52px;
  padding: 8px;
  border-radius: 16px;
  background: var(--bg);
  color: var(--muted);
  margin-bottom: 14px;
}
.light-icon svg {
  width: 100%;
  height: 100%;
}
.light-card[data-power="on"] .light-icon {
  color: var(--accent);
  box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 20%, transparent);
}
.light-card[data-power="on"] {
  border-color: var(--accent);
}
.battery-total meter,
.battery-pack meter {
  display: block;
  width: 100%;
  height: 22px;
  accent-color: var(--accent);
  margin: 12px 0;
}
.integration-editor {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.integration-editor textarea,
#custom-css {
  width: 100%;
  font-family: ui-monospace, monospace;
  tab-size: 2;
}
.pac-energy {
  margin-top: 20px;
}
@media (max-width: 360px) {
  #sensor-devices,
  #light-devices {
    grid-template-columns: 1fr;
  }
}
.battery-total meter::-webkit-meter-optimum-value,
.battery-pack meter::-webkit-meter-optimum-value {
  background: var(--accent);
}
.battery-total meter::-moz-meter-bar,
.battery-pack meter::-moz-meter-bar {
  background: var(--accent);
}
/* Navigation : vues personnelles et fonctions système restent distinctes. */
#navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}
.dashboard-tabs,
.system-menu {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.system-menu {
  border-left: 1px solid var(--line);
  padding-left: 18px;
  font-size: 0.9rem;
}
.board-cards {
  display: grid;
  gap: 20px;
  margin-top: 24px;
}
/* Dashboard editing controls now live in the navigation tabs.
   Do not reserve the old toolbar spacing above the cards. */
main:has(> #workspace-dashboard:not([hidden])) > .heading {
  margin-bottom: 8px;
}
#workspace-dashboard > .buttons:empty {
  display: none;
}
#workspace-dashboard > .board-cards {
  margin-top: 8px;
}
.configured-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 14px;
  padding: 20px;
  min-width: 0;
}
/* Éclairage commun des tuiles, sans modifier leurs fonds propres.
   Les conteneurs de mise en page (grid / hstack / vstack) restent invisibles. */
.configured-card:not(.grid):not(.hstack):not(.vstack) {
  position: relative;
  border-color: var(--tile-edge-dark);
  box-shadow: var(--tile-cast-shadow), inset 1px 1px 0 color-mix(in srgb, var(--tile-edge-light) 35%, transparent);
}
.configured-card:not(.grid):not(.hstack):not(.vstack)::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid transparent;
  border-radius: inherit;
  background: linear-gradient(135deg,
    var(--tile-edge-light) 0%,
    var(--line) 42%,
    var(--tile-edge-dark) 100%) border-box;
  /* Ne dessiner que la bordure, jamais par-dessus le contenu de la tuile. */
  -webkit-mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  pointer-events: none;
}
.configured-card.grid,
.configured-card.hstack,
.configured-card.vstack {
  border: 0;
  background: transparent;
  padding: 0;
}
.layout-grid {
  display: grid;
  grid-template-columns: repeat(var(--columns, 3), minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}
.layout-hstack {
  display: flex;
  gap: 16px;
  align-items: stretch;
}
.layout-hstack > * {
  flex: 1;
}
.layout-vstack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-value {
  display: block;
  font-size: 2rem;
  margin: 16px 0;
  font-variant-numeric: tabular-nums;
}
.configured-card h2 {
  font-size: 1rem;
  min-height: 2.4em;
}
.configured-card meter {
  width: 100%;
  height: 24px;
  accent-color: var(--accent);
}
.configured-card .entity-key {
  display: block;
  overflow-wrap: anywhere;
  color: var(--muted);
}
.configured-card[data-state="on"] {
  border-color: var(--accent);
}
.card-icon {
  font-size: 2.5rem;
  color: var(--accent);
}
.card-graph svg {
  width: 100%;
  min-height: 180px;
  max-height: 420px;
}
.graph-series {
  display: block;
  overflow-wrap: anywhere;
}
.editor-fields,
.config-fields {
  display: grid;
  gap: 12px;
}
.editor-fields textarea,
.editor-fields input,
.config-fields input {
  width: 100%;
}
.card-editor,
.program-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin: 12px 0;
}
.card-editor > summary,
.program-step > summary {
  margin-bottom: 12px;
  font-weight: bold;
}
.nested-cards,
.program-branch,
.program-conditions {
  padding-left: 20px;
  border-left: 2px solid var(--accent);
}
#workspace-dashboard > section {
  margin-top: 20px;
}
#program-debug {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 600px;
  overflow: auto;
}
@media (max-width: 800px) {
  .layout-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .layout-hstack {
    flex-wrap: wrap;
  }
  .layout-hstack > * {
    min-width: 200px;
  }
  .system-menu {
    border-left: 0;
    padding-left: 0;
  }
}
@media (max-width: 480px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }
  .layout-hstack {
    display: grid;
    grid-template-columns: 1fr;
  }
}
/* Largeur explicite des cartes, bornée par la grille disponible. */
.board-cards {
  grid-template-columns: repeat(var(--columns, 1), minmax(0, 1fr));
}
.board-cards > .configured-card,
.layout-grid > .configured-card {
  grid-column: span min(var(--card-span, 1), var(--available-columns, 1));
}
.configured-card {
  box-sizing: border-box;
  overflow-wrap: anywhere;
}
.configured-card .card-icon {
  display: block;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
}
.configured-card .card-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}
.configured-card .buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.configured-card button {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}
.configured-card input,
.configured-card select {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
/* A modal dialog must lock the page, not the dialog's own scrolling. */
html:has(dialog:modal) {
  overflow: hidden;
  scrollbar-gutter: stable;
}

/* Prevent a scroll gesture at the edge of a dialog from reaching the page. */
dialog:modal {
  overscroll-behavior: contain;
}

.card-dialog {
  box-sizing: border-box;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  overflow: auto;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
}
.card-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}
.card-dialog .editor-fields input,
.card-dialog textarea {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.card-dialog > button {
  margin: 8px 8px 0 0;
}
.card-preview {
  margin: 0;
  background: var(--panel);
  min-width: 0;
}
.card-preview h3,
.card-preview p {
  overflow-wrap: anywhere;
}
.dashboard-edit-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 16px;
  margin: 16px 0;
}
.editor-error {
  color: var(--red, #f87171);
}
@media (max-width: 800px) {
  .board-cards {
    grid-template-columns: repeat(min(var(--columns, 1), 2), minmax(0, 1fr));
  }
  .board-cards > .configured-card,
  .layout-grid > .configured-card {
    grid-column: span min(var(--card-span, 1), var(--available-columns, 1), 2);
  }
  .layout-hstack > * {
    min-width: 0;
    flex-basis: 200px;
  }
}
@media (max-width: 480px) {
  .board-cards {
    grid-template-columns: minmax(0, 1fr);
  }
  .board-cards > .configured-card,
  .layout-grid > .configured-card {
    grid-column: 1;
  }
}
/* Poignées explicites : sélectionner du texte ne déplace jamais une carte. */
.drag-handle {
  cursor: grab;
  font-size: 1.25rem;
  padding: 2px 8px;
  touch-action: manipulation;
}
.drag-handle:active {
  cursor: grabbing;
}
.dragging {
  opacity: 0.45;
}
.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}
.program-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}
.program-preview > strong {
  overflow-wrap: anywhere;
}
.program-preview label {
  margin: 0;
}
.automation-dialog {
  width: min(920px, calc(100vw - 24px));
  padding: 18px;
}
.program-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
}
.program-form label {
  margin: 0;
  min-width: 0;
  font-size: 0.88rem;
}
.program-form input,
.program-form select,
.program-form textarea {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.9rem;
  box-sizing: border-box;
}
.program-form input[type="checkbox"] {
  width: auto;
}
.program-form .program-steps,
.program-form > button {
  grid-column: 1 / -1;
}
.program-form .program-step {
  padding: 8px 10px;
  margin: 6px 0;
}
.program-form .program-step > summary {
  margin: 0;
  font-size: 0.9rem;
}
.program-form .program-step[open] > summary {
  margin-bottom: 8px;
}
.program-form .editor-fields {
  gap: 6px;
}
.program-form .program-branch,
.program-form .program-conditions {
  padding-left: 10px;
}
.program-form h3 {
  margin: 6px 0;
  font-size: 0.9rem;
}
.program-form button {
  padding: 5px 9px;
  margin: 3px;
}
@media (max-width: 600px) {
  .program-form {
    grid-template-columns: minmax(0, 1fr);
  }
}
.entity-icon {
  display: inline-flex;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  color: var(--accent);
}
.entity-icon svg {
  width: 100%;
  height: 100%;
}
.icon-picker {
  display: flex;
  align-items: center;
  gap: 12px;
}
.icon-picker select {
  flex: 1;
  min-width: 0;
}
.configured-card.card-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  min-height: 52px;
  overflow: visible;
}
.card-row > h2 {
  margin: 0;
  min-height: 0;
  flex: 1 1 auto;
  white-space: normal;
}
.card-row > .card-value {
  font-size: 1.05rem;
  margin: 0 0 0 auto;
  text-align: right;
  white-space: normal;
}

.card-row > .entity-key {
  display: none;
}
.card-row > .card-icon {
  margin: 0;
  width: 28px;
  height: 28px;
  flex-basis: 28px;
  padding: 2px;
}
.card-row > .buttons,
.card-row > form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.card-row button {
  white-space: normal;
  padding: 6px 9px;
}
.card-row input[type="number"] {
  width: 85px;
}
.card-row meter {
  width: 100px;
  flex: 0 0 100px;
}
.card-row .card-graph {
  min-width: 0;
  flex: 1;
}
.card-row .card-graph svg {
  min-height: 60px;
  max-height: 80px;
}
.curve-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0;
}
.curve-colors label {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-wrap: anywhere;
}
.user-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.user-row > .ui-action-menu {
  margin-left: auto;
}
/* Couleurs facultatives : l'absence de valeur conserve le thème courant. */
.configured-card { color: var(--text-color, var(--text)); }
.configured-card > h2 { color: var(--title-color, inherit); }
.configured-card > .card-value { color: var(--value-color, inherit); }
.chart-tooltip { padding: .7rem; border: 1px solid var(--muted); border-radius: 8px; font-size: .85rem; }
.entity-suggestions { max-height: 220px; overflow: auto; display: flex; flex-direction: column; gap: .25rem; }
.entity-suggestions[hidden] { display: none; }
.entity-suggestions button { text-align: left; overflow-wrap: anywhere; }
.entity-dialog pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow: auto; }

/* ==========================================================================
   TUILLE MÉTÉO RICHE & GHI SOLAIRE
   ========================================================================== */
.card-weather-rich {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0;
}
.weather-rich-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.weather-location-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.weather-location-chip svg {
  color: var(--accent);
}
.weather-source-badge {
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.8;
}
.weather-rich-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 0;
}
/* Compact day-ahead outlook beside the current weather, same theme. */
.weather-forecast-strip {
  display: flex;
  gap: 6px;
  align-items: stretch;
  margin-left: auto;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}
.weather-forecast-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 62px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(155deg, color-mix(in srgb, var(--accent) 8%, transparent), rgba(255,255,255,.015));
}
.weather-forecast-label { font-size: 10px; font-weight: 600; color: var(--muted); }
.weather-forecast-art { width: 30px; height: 30px; display: grid; place-items: center; }
.weather-forecast-art svg { width: 30px; height: 30px; }
.weather-forecast-high { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1; }
.weather-forecast-low { font-size: 10px; color: var(--muted); }
@container (max-width: 370px) {
  .weather-rich-hero { flex-wrap: wrap; }
  .weather-forecast-strip { width: 100%; border-left: none; border-top: 1px solid var(--line); padding: 8px 0 0; justify-content: space-around; }
}
.card-weather-rich { container-type: inline-size; }

.weather-hero-art {
  width: 68px;
  height: 68px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.25));
}
.weather-hero-data {
  flex: 1;
  min-width: 0;
}
.weather-temp-wrap {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.weather-temp-num {
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: -0.5px;
}
.weather-temp-unit {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
}
.weather-condition-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-top: 4px;
}
.weather-apparent-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.weather-solar-card {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 12px;
  padding: 10px 14px;
}
.weather-solar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.weather-solar-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #f59e0b;
}
.weather-solar-value {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #f59e0b;
}
.weather-solar-value small {
  font-size: 11px;
  font-weight: normal;
  opacity: 0.85;
}
.weather-solar-bar-wrap {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin: 6px 0;
}
.weather-solar-bar {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #fbbf24, #fef08a);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.weather-solar-sub {
  font-size: 11px;
  color: var(--muted);
}
.weather-metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.weather-metric-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 8px;
}
.weather-metric-item svg {
  color: var(--muted);
  flex-shrink: 0;
}
.weather-metric-item .metric-val {
  display: block;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.weather-metric-item .metric-val small {
  font-size: 11px;
  font-weight: normal;
  color: var(--muted);
}
.weather-metric-item .metric-lbl {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

/* ==========================================================================
   INTÉGRATIONS UNIFIÉES
   ========================================================================== */
.integration-editor {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.integration-editor:hover {
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
.integration-editor summary.integration-summary-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.integration-editor summary.integration-summary-bar::-webkit-details-marker {
  display: none;
}
.integration-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  flex-shrink: 0;
}
.integration-status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
  letter-spacing: 0.3px;
}
.integration-status-pill.online {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.35);
}
.integration-status-pill.waiting {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}
.integration-status-pill.disabled {
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border: 1px solid var(--line);
}
.integration-status-pill.error {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.35);
}
.integration-entity-pill {
  font-size: 11px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 3px 9px;
  border-radius: 12px;
}
.integration-quick-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin-left: 6px;
}
.integration-quick-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.integration-editor-body {
  padding: 16px 20px 20px;
}

/* ==========================================================================
   GÉOCODAGE & RECHERCHE D'ADRESSE MAISON
   ========================================================================== */
.geocode-search-wrap {
  position: relative;
  margin-bottom: 12px;
}
.geocode-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  max-height: 240px;
  overflow-y: auto;
  margin-top: 4px;
}
.geocode-results[hidden] {
  display: none;
}
.geocode-item {
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: block;
  transition: background 0.15s ease;
}
.geocode-item:last-child {
  border-bottom: none;
}
.geocode-item:hover,
.geocode-item:focus {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  outline: none;
}
.geocode-item strong {
  display: block;
  font-size: 13px;
  color: var(--text);
}
.geocode-item small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}


/* L'avatar du compte est l'action permettant de changer sa photo. */
.avatar-edit-button {
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  position: relative;
}
.avatar-edit-button:hover { box-shadow: 0 0 0 3px var(--accent); }
.avatar-edit-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.avatar-file-input { display: none; }

/* Suppression distincte du clic de remplacement de la photo. */
.user-profile-header { position: relative; }
.avatar-delete-button {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 54px;
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  padding: 4px;
  border: 1px solid var(--border, #666);
  border-radius: 50%;
  color: var(--text, currentColor);
  background: var(--panel, #252525);
  cursor: pointer;
}
.avatar-delete-button[hidden] { display: none; }
.avatar-delete-button:hover { color: #fff; background: #b33b43; }
.avatar-delete-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Entity information and configuration dialogs. */
.entity-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.entity-dialog-header h2 { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.entity-edit-button { flex: none; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); font-size: 25px; cursor: pointer; }
.entity-edit-button:hover, .entity-edit-button:focus-visible { border-color: var(--accent); color: var(--accent); }
.entity-current-value { overflow-wrap: anywhere; }
.entity-config-dialog .entity-debug { margin: 16px 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.entity-config-dialog .entity-debug summary { cursor: pointer; font-weight: 600; }
.entity-config-dialog .entity-debug pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow: auto; }
@media (max-width: 600px) { .entity-dialog, .entity-config-dialog { padding: 16px; width: calc(100vw - 20px); } }

/* Keep entity dialog actions right-aligned and vertically centered. */
.entity-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.entity-dialog-actions > button { margin: 0; }

.entity-config-dialog .entity-delete-button {
  margin-right: auto;
  color: #ef7777;
  border-color: color-mix(in srgb, #ef7777 55%, var(--line));
}
.entity-config-dialog .entity-delete-button:hover { color: #ff9999; }
/* Conditions reuse the same compact cards, headers and controls as actions. */
.program-conditions { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.program-condition { min-width: 0; }
.program-condition > summary::-webkit-details-marker { display: none; }
.program-condition.dragging { opacity: .55; }
.program-conditions.drop-target { outline: 2px dashed var(--accent, currentColor); }

/* Shared touch-friendly action and condition picker. */
.program-picker-dialog { width: min(420px, calc(100vw - 32px)); max-width: 100%; }
.program-picker-dialog select { width: 100%; }
.program-picker-description { min-height: 3em; margin: 12px 0 20px; color: var(--text-muted, var(--text-secondary, inherit)); line-height: 1.5; }
.program-picker-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.program-picker-actions button { min-height: 44px; }

/* Shared history period selector: same layout in entity details and explorer. */
.history-control-panel { border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; background: var(--panel); min-width: 0; }
.history-control-panel > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; user-select: none; }
.history-period-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 12px 14px 14px; min-width: 0; }
.history-period-section-heading { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.history-period-section-heading strong, .history-period-custom-heading { font-size: .9rem; font-weight: 600; color: var(--text); }
.history-period-section-heading small { font-size: .72rem; color: var(--muted); }
.history-period-presets { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 7px; width: 100%; min-width: 0; }
.history-period-presets > button { width: 100%; min-width: 0; min-height: 35px; padding: 6px 2px; margin: 0; white-space: nowrap; }
.history-period-presets > button.selected { border-color: var(--accent); background: var(--accent); color: var(--bg); }
.history-period-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .75rem; }
.history-period-divider::before, .history-period-divider::after { content: ""; height: 1px; background: var(--line); flex: 1; min-width: 0; }
.history-period-custom-heading { display: block; margin: 0; }
.history-period-dates { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.15fr); align-items: end; gap: 10px; min-width: 0; }
.history-period-controls .history-period-date-label { display: grid; gap: 5px; min-width: 0; margin: 0; font-size: .8rem; }
.history-period-date { display: block; width: 100%; min-width: 0; max-width: none; margin: 0; box-sizing: border-box; }
.history-period-now { min-width: 0; padding-bottom: 2px; }
.history-period-controls .history-period-now-label { display: flex; align-items: center; gap: 6px; margin: 0 0 5px; font-size: .8rem; color: var(--text); }
.history-period-now-label input[type="checkbox"] { margin: 0; }
.history-period-now small { display: block; font-size: .7rem; line-height: 1.3; color: var(--muted); }
.history-period-actions { display: flex; justify-content: flex-end; gap: 8px; }
.history-period-actions > button { width: auto; min-width: 0; padding: 8px 13px; margin: 0; }
/* Three equal statistics, matching the compact summary mockup. */
.history-statistics-panel > summary { padding-block: 9px; }
.history-summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; padding: 10px 12px; }
.history-summary-grid > .history-summary-item { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 3px 16px; }
.history-summary-grid > .history-summary-item + .history-summary-item { border-left: 1px solid var(--line); }
.history-summary-icon { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%; background: color-mix(in srgb, var(--text) 5%, var(--panel)); color: color-mix(in srgb, var(--text) 78%, var(--muted)); }
.history-summary-icon svg { display: block; width: 23px; height: 23px; }
.history-summary-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.history-summary-info > small { display: block; color: var(--muted); font-size: .72rem; line-height: 1.3; overflow-wrap: anywhere; }
.history-summary-info > strong { display: block; color: var(--text); font-size: 1.05rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .history-summary-grid > .history-summary-item { gap: 7px; padding-inline: 9px; }
  .history-summary-icon { flex-basis: 32px; width: 32px; height: 32px; }
  .history-summary-icon svg { width: 20px; height: 20px; }
}
@media (max-width: 600px) {
  .history-summary-grid { grid-template-columns: minmax(0, 1fr); }
  .history-summary-grid > .history-summary-item { padding: 10px 8px; }
  .history-summary-grid > .history-summary-item + .history-summary-item { border-left: 0; border-top: 1px solid var(--line); }
  .history-period-dates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-period-now { grid-column: 1 / -1; }
}
@media (max-width: 380px) {
  .history-period-presets { gap: 3px; }
  .history-period-presets > button { font-size: .7rem; padding-inline: 0; }
  .history-period-dates { grid-template-columns: minmax(0, 1fr); }
  .history-period-now { grid-column: auto; }
}

/* Zendure integration: one IP per row, with simple add and remove actions. */
.integration-dialog .zendure-ip-editor { display: grid; gap: 12px; min-width: 0; }
.integration-dialog .zendure-ip-list { display: grid; gap: 8px; }
.integration-dialog .zendure-ip-row, .integration-dialog .zendure-ip-entry {
  display: flex; align-items: center; gap: 10px; min-width: 0;
}
.integration-dialog .zendure-ip-row {
  justify-content: space-between; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 9px;
}
.integration-dialog .zendure-ip-row span { min-width: 0; overflow-wrap: anywhere; }
.integration-dialog .zendure-ip-entry input { flex: 1 1 auto; min-width: 0; }
.integration-dialog .zendure-ip-row button, .integration-dialog .zendure-ip-entry button {
  flex-shrink: 0; margin: 0;
}

/* Zendure: each configured IP owns its polling interval. */
.integration-dialog .zendure-ip-row .zendure-interval-label {
  display: flex; flex-direction: column; gap: 3px; min-width: 98px;
  max-width: 120px; margin: 0; font-size: .8rem;
}
.integration-dialog .zendure-ip-row .zendure-interval-label input {
  width: 100%; min-width: 0; box-sizing: border-box; margin: 0;
}
@media (max-width: 460px) {
  .integration-dialog .zendure-ip-row { flex-wrap: wrap; }
  .integration-dialog .zendure-ip-row > span { flex: 1 1 100%; }
}

/* Zendure: align the modal footer actions without changing other integrations. */
.integration-dialog .zendure-dialog-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.integration-dialog .zendure-dialog-actions button { margin: 0; }

/* Zendure: the empty status paragraph must not leave space below the footer. */
.integration-dialog:has(.zendure-dialog-actions) p[data-module="zendure"]:empty {
  display: none;
}

/* Shelly discovery in the integration configuration dialog. */
.shelly-discovery-editor { display: grid; gap: 12px; min-width: 0; }
.shelly-discovery-list { display: grid; gap: 8px; }
.shelly-discovery-row { display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px;
  min-width: 0; flex-wrap: wrap; }
.shelly-discovery-row span { flex: 1; min-width: 150px; overflow-wrap: anywhere; }
.shelly-discovery-row small { display: block; opacity: .7; }
/* Alexa devices share the integration list but use compact, frameless icons. */
.integration-dialog .alexa-media-player-devices .shelly-discovery-row {
  padding: 6px 2px;
  gap: 10px;
  border: 0;
  border-radius: 0;
  flex-wrap: nowrap;
}
.integration-dialog .alexa-media-player-devices .shelly-discovery-row + .shelly-discovery-row {
  border-top: 1px solid var(--line);
}
.alexa-media-player-device-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.alexa-media-player-device-icon svg { width: 26px; height: 26px; }
.alexa-media-player-device-details { flex: 1; min-width: 0; }
.alexa-media-player-device-details strong,
.alexa-media-player-device-details small { display: block; overflow-wrap: anywhere; line-height: 1.25; }
.alexa-media-player-device-details small { font-size: .75rem; }

.integration-dialog .shelly-remove-device {
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  color: #ef7777;
  border-color: color-mix(in srgb, #ef7777 50%, var(--line));
}
.integration-dialog .shelly-remove-device:hover {
  background: color-mix(in srgb, #ef7777 12%, var(--panel));
}

/* All integration popups use a right-aligned action footer. */
.integration-dialog .integration-dialog-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}
.integration-dialog .integration-dialog-actions > button {
  width: auto;
  margin: 0;
}
/* Empty integration status placeholders must never leave a gap below the footer. */
.integration-dialog p[data-module]:empty {
  display: none;
}
/* Shelly uses the opt-in .control-checkbox rule in ui/controls.css. */

/* MQTT prefixes reuse the Shelly/APsystems device-list components. */
.integration-dialog .mqtt-prefix-identity { display: block; flex: 1; min-width: 150px; }
.integration-dialog .mqtt-prefix-identity strong,
.integration-dialog .mqtt-prefix-identity small { overflow-wrap: anywhere; }
.integration-dialog .mqtt-prefix-identity small { margin-top: 6px; }
.integration-dialog .mqtt-prefix-actions {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px; margin-left: auto; flex: 0 0 auto;
}
@media (max-width: 420px) {
  .integration-dialog .mqtt-prefix-actions { width: 100%; }
}

/* Options > Entités: identical footers for entity and device editors. */
.inventory-detail-dialog > .inventory-device-actions,
.entity-config-dialog > .entity-dialog-actions {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.inventory-detail-dialog .entity-delete-button,
.entity-config-dialog .entity-delete-button {
  margin-right: auto;
  color: #ef7777;
  border-color: color-mix(in srgb, #ef7777 55%, var(--line));
}
.inventory-detail-dialog .entity-delete-button:hover,
.entity-config-dialog .entity-delete-button:hover { color: #ff9999; }

/* Plan interactif : positions relatives au dessin, sans boîtes de tuiles. */
.plan-scene {position:relative;width:100%;overflow:hidden;border-radius:10px;background:transparent;}
.plan-background {display:block;width:100%;height:auto;}
.plan-overlay {position:absolute;inset:0;width:100%;height:100%;pointer-events:none;}
.plan-marker {position:absolute;transform:translate(-50%,-50%);display:flex;gap:.3em;align-items:center;white-space:nowrap;padding:.2em .45em;border-radius:8px;background:#111b; color:white;font-size:clamp(10px,1.5vw,15px);text-shadow:0 1px 3px #000;}
.plan-editor-preview .plan-marker {cursor:grab;touch-action:none;user-select:none;}
.plan-editor-preview .plan-marker:active {cursor:grabbing;}
.plan-editor-preview {margin:.75rem 0;max-width:850px;}
.plan-editor-preview .plan-scene {outline:1px solid var(--border-color,#777);}

/* Dedicated visual plan editor */
.plan-config-dialog {width:min(1100px,96vw);max-width:96vw;max-height:94vh;overflow:auto;}
.plan-config-toolbar,.plan-config-actions {display:flex;gap:.65rem;flex-wrap:wrap;justify-content:flex-end;margin:.75rem 0;}
.plan-config-preview {margin:1rem 0;min-height:5rem;}
.plan-config-preview .plan-editor-preview {max-width:100%;}
.plan-config-items {display:grid;gap:1rem;}
.plan-config-section {border:1px solid var(--border-color,#555);border-radius:10px;padding:1rem;}
.plan-config-entry {display:flex;gap:.6rem;align-items:end;flex-wrap:wrap;padding:.7rem 0;border-bottom:1px solid var(--border-color,#555);}
.plan-image-field {display:flex;gap:.6rem;align-items:center;flex-wrap:wrap;margin:.5rem 0;}
.plan-image-field small {overflow-wrap:anywhere;max-width:35rem;}
@media(max-width:650px){.plan-config-dialog {width:98vw;max-width:98vw;padding:.7rem;}.plan-config-entry>* {max-width:100%;}}

/* Plan editor: lightweight selectable markers and responsive property controls. */
.plan-scene-empty {aspect-ratio: 16 / 10; min-height: 220px; background: repeating-linear-gradient(45deg,#1d2733,#1d2733 14px,#253141 14px,#253141 28px);}
.plan-empty-caption {position:absolute;bottom:.7rem;left:50%;transform:translateX(-50%);white-space:nowrap;color:#e4eaf2;font-size:.8rem;pointer-events:none;}
.plan-config-toolbar {align-items:end;justify-content:flex-start;}
.plan-config-toolbar label {min-width:220px;flex:1;}
/* The selected marker must remain clearly visible during editing, with the active theme color. */
.plan-editor-preview .plan-marker.plan-marker-selected {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px color-mix(in srgb, var(--accent) 20%, transparent);
}
.plan-marker-config.plan-marker-selected {
  border-radius: 6px;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--accent) 9%, transparent);
}
.plan-marker-config {align-items:end;}
.plan-marker-config label {flex:1 1 105px;min-width:95px;}
.plan-marker-config input[type=number] {width:80px;max-width:100%;}
.plan-marker-config input:not([type=number]) {max-width:100%;}
.plan-marker-icon:empty {display:none;}
@media(max-width:650px){.plan-config-toolbar label {min-width:100%;}.plan-marker-config label {flex:1 1 40%;}}

/* Interactive-plan marker label and switch controls. */
.plan-marker-name {font-size:.88em;font-weight:600;}
.plan-marker-icon .entity-icon {display:inline-flex;align-items:center;justify-content:center;}
.plan-marker-icon svg {width:1.15em;height:1.15em;}
.plan-marker-clickable {cursor:pointer;}
.plan-marker-clickable:hover {background:#22334cdd;}
.plan-marker-clickable:focus-visible {outline:2px solid var(--accent,#81b9ef);outline-offset:3px;}
.plan-marker-on .plan-marker-icon {color:#ffd67c;}
.plan-marker-config .icon-picker {min-width:125px;}

/* Plan interactive actions: keep tap and click on markers above decorative layers. */
.plan-scene .plan-marker {z-index:2;}
.plan-scene .plan-marker-clickable {cursor:pointer;touch-action:manipulation;}
.plan-scene .plan-marker-clickable:active {filter:brightness(1.2);}

/* Value and gauge tiles: icon and title share a compact, vertically centred header. */
.configured-card:is(.value, .gauge) .card-value-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}
.configured-card:is(.value, .gauge) .card-value-header > .tile-icon {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
}
.configured-card:is(.value, .gauge) .card-value-header > h2 {
  flex: 1 1 auto;
  color: var(--title-color, inherit);
  margin: 0;
  min-height: 0;
  min-width: 0;
  line-height: 1.3;
}

/* Interactive floor plans preserve the alpha channel of imported PNG/WebP
   images all the way to the dashboard. Other tile types keep their panel. */
.configured-card.plan {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.configured-card.plan .plan-scene {
  background: transparent;
}

/* Camera tile: streams run only while the tile is visible. */
.configured-card.camera .camera-preview {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #111821;
  border-radius: 10px;
  display: grid;
  place-items: center;
}
.configured-card.camera .camera-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.configured-card.camera .camera-preview img[hidden] { display: none; }
.configured-card.camera .camera-status {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  padding: 5px 9px;
  border-radius: 6px;
  background: rgb(0 0 0 / 75%);
  color: #fff;
  font-size: .78rem;
}
.configured-card.camera .camera-status[data-state="playing"] {
  color: #b7f4ce;
}

/* Camera form follows the shared integration dialog spacing and theme. */
.camera-settings-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 14px; margin: 16px 0; }
.camera-settings-form label { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.camera-settings-form input, .camera-settings-form select { width: 100%; box-sizing: border-box; }
.camera-settings-form small { grid-column: 1 / -1; }

/* Camera fullscreen, capture and local PTZ controls. No inline styles/CSP exceptions. */
.configured-card.camera .camera-preview video { width: 100%; height: 100%; object-fit: contain; }
/* The tile is 16:9, but fullscreen must use the real screen dimensions.
   Letterbox / pillarbox video instead of cropping it. */
.configured-card.camera .camera-preview:fullscreen {
  position: fixed;
  inset: 0;
  display: block;
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  background: #080d13;
  overflow: hidden;
}
.configured-card.camera .camera-preview:fullscreen video,
.configured-card.camera .camera-preview:fullscreen img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  object-position: center center;
}
/* The inactive media element stays hidden during stream/fallback changes. */
.configured-card.camera .camera-preview:fullscreen video[hidden],
.configured-card.camera .camera-preview:fullscreen img[hidden] {
  display: none;
}
.configured-card.camera .camera-tools {
  position: absolute; z-index: 4; right: .5rem; top: .5rem;
  display: flex; align-items: center; gap: .25rem;
}
.configured-card.camera .camera-tool { min-width: 2.3rem; min-height: 2.3rem; cursor: pointer; }
.configured-card.camera .camera-ptz {
  position: absolute; z-index: 4; bottom: .5rem; right: .5rem;
  display: grid; grid-template-columns: repeat(3, 2.4rem);
  grid-template-rows: repeat(3, 2.4rem); gap: .15rem;
}
.configured-card.camera .camera-ptz[hidden] { display: none; }
.configured-card.camera .camera-ptz-button { min-width: 0; padding: 0; cursor: pointer; }
.configured-card.camera .camera-ptz-button[data-direction="up"] { grid-column: 2; grid-row: 1; }
.configured-card.camera .camera-ptz-button[data-direction="left"] { grid-column: 1; grid-row: 2; }
.configured-card.camera .camera-ptz-button[data-direction="right"] { grid-column: 3; grid-row: 2; }
.configured-card.camera .camera-ptz-button[data-direction="down"] { grid-column: 2; grid-row: 3; }

/* Camera controls remain reachable on touch screens and in browser fullscreen. */
.configured-card.camera .camera-preview:fullscreen .camera-tools {
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
}
.configured-card.camera .camera-preview:fullscreen .camera-ptz {
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(12px, env(safe-area-inset-right));
  grid-template-columns: repeat(3, 3.25rem);
  grid-template-rows: repeat(3, 3.25rem);
}
.configured-card.camera .camera-preview:fullscreen .camera-ptz-button {
  min-height: 3.25rem;
  touch-action: manipulation;
}
.configured-card.camera .camera-preview:focus-visible {
  outline: 2px solid var(--accent-color, currentColor);
  outline-offset: 2px;
}

/* Collapsible application navigation. Dashboard tabs remain in the top bar. */
.app-shell {
  --sidebar-width: 58px;
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 120px);
}
.app-shell.sidebar-expanded { --sidebar-width: 202px; }
.app-content { flex: 1; min-width: 0; }
.app-sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px 7px;
  transition: width .2s ease, flex-basis .2s ease;
  min-width: 0;
  z-index: 5;
}
.sidebar-links { display: grid; gap: 5px; }
.app-sidebar .sidebar-toggle,
.app-sidebar .sidebar-link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 13px;
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: background .15s ease, color .15s ease;
}
.app-sidebar .sidebar-toggle { margin-bottom: 13px; }
.app-sidebar svg {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.app-sidebar .sidebar-label { overflow: hidden; white-space: nowrap; }
.app-shell:not(.sidebar-expanded) .sidebar-label { display: none; }
.app-sidebar .sidebar-link:hover,
.app-sidebar .sidebar-toggle:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--text); }
.app-sidebar .sidebar-link[aria-current="page"] {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}
.app-sidebar :is(a,button):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#navigation { justify-content: flex-start; min-width: 0; }
#navigation .dashboard-tabs { min-width: 0; }
@media (max-width: 700px) {
  .app-shell { --sidebar-width: 52px; }
  .app-shell.sidebar-expanded { --sidebar-width: 52px; }
  .app-sidebar { padding: 10px 4px; }
  .app-shell.sidebar-expanded .app-sidebar {
    /* Keep the expanded rail at its real width in Android WebView. */
    width: 202px;
    flex: 0 0 202px;
    position: relative;
    margin-right: -150px;
    box-shadow: 8px 0 24px #0004;
  }
  .app-content { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .app-sidebar { transition: none; }
}

/* Éditeur des courbes de l’historique : feuille autorisée par la CSP. */
.history-curve-config { min-width: 0; }
.history-curve-config-rows { display: grid; gap: 10px; padding: 12px 14px 16px; }
.history-curve-config-row { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--panel) 90%, var(--bg)); }
.history-curve-config-id { display: block; margin-bottom: 9px; font-size: .75rem; color: var(--muted); overflow-wrap: anywhere; }
.history-curve-config-fields { display: grid; grid-template-columns: 54px minmax(0, 1fr) minmax(170px, auto); gap: 12px; align-items: end; }
.history-curve-config-fields > label { display: grid; gap: 5px; min-width: 0; margin: 0; font-size: .8rem; color: var(--muted); }
.history-curve-config-fields input, .history-curve-config-fields select { width: 100%; min-width: 0; margin: 0; height: 40px; }
.history-curve-config-fields input[type=color] { padding: 4px; cursor: pointer; }
.history-curve-config-empty { margin: 4px 0; font-size: .85rem; color: var(--muted); }
@media (max-width: 550px) { .history-curve-config-fields { grid-template-columns: 54px minmax(0, 1fr); } .history-curve-config-trace { grid-column: 1 / -1; } }

/* Options : informations système — utilise les tokens du thème et les jauges des tuiles. */
.system-info .system-metrics { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; margin:18px 0; }
.system-info .system-metric, .system-info .system-chart-panel, .system-info .system-detail-panel {
  min-width:0; padding:16px; border:1px solid var(--line); border-radius:12px; background:var(--panel); color:var(--text);
}
.system-info .system-metric-heading, .system-info .system-chart-heading { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:14px; }
.system-info .system-metric-heading strong { font-size:1.35rem; font-variant-numeric:tabular-nums; text-align:right; }
.system-info .system-chart-panel { margin-bottom:12px; }
.system-info .system-chart-heading h3 { margin:0; font-size:1rem; }
.system-info .system-chart-legend { display:flex; gap:16px; color:var(--muted); font-size:.8rem; margin-bottom:8px; }
.system-info .system-chart-legend span::before { content:""; display:inline-block; width:9px; height:9px; margin-right:6px; border-radius:50%; background:var(--accent); }
.system-info .system-chart-legend span:last-child::before { background:var(--muted); }
.system-info #sys-chart { display:block; width:100%; height:150px; overflow:visible; }
.system-info .system-chart-grid { fill:none; stroke:var(--line); stroke-width:1; stroke-dasharray:4 6; }
.system-info .system-chart-cpu, .system-info .system-chart-ram { fill:none; stroke:var(--accent); stroke-width:1; vector-effect:non-scaling-stroke; stroke-linejoin:round; }
.system-info .system-chart-ram { stroke:var(--muted); }
.system-info .system-detail-panel summary { cursor:pointer; font-weight:600; }
.system-info .system-details { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; margin-top:16px; }
.system-info .system-details > div { display:flex; flex-direction:column; gap:8px; padding:12px; border:1px solid var(--line); border-radius:8px; }
.system-info .system-details span { color:var(--muted); }
.system-info .system-details strong { font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }
@media(max-width:620px) { .system-info .system-metrics, .system-info .system-details {grid-template-columns:1fr;} }

/* Éditeur commun des entrées d'énumération virtuelle. */
.virtual-enum-choice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.virtual-enum-choice input { min-width: 0; }
@media (max-width: 560px) {
  .virtual-enum-choice { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .virtual-enum-choice button { grid-column: 1 / -1; }
}

/* Actions des entités virtuelles : menu compact commun aux lignes. */
.virtual-card-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 8px;
}
.virtual-card-info { min-width: 0; overflow-wrap: anywhere; }
.card-dialog > .buttons { justify-content: flex-end; }
