/* Device cards and their controls. Every control keeps its size whatever
   the state, values use tabular figures, and the busy mark sits on top of
   the card: live updates change what is shown, never where. */

.rooms { display: flex; flex-direction: column; gap: 20px; }
.room-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 2px 10px;
  font-size: 17px;
  font-weight: 650;
}
.room-count { font-size: 13px; font-weight: 500; color: var(--text-2); white-space: nowrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }

.dev {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.dev-head {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}
.dev-head:has(> :nth-child(2):last-child) { grid-template-columns: 40px minmax(0, 1fr); }
.dev-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-2);
  transition: background-color 0.2s, color 0.2s;
}
.dev.on .dev-icon { background: var(--accent-soft); color: var(--accent); }
/* A lit lamp shows its own light: the colour or the white it is set to. */
.dev[data-kind="light"].on .dev-icon {
  background: var(--glow);
  background: color-mix(in srgb, var(--glow) 55%, var(--surface));
  color: var(--text);
}
.dev.warn .dev-icon { background: var(--warn-soft); color: var(--warn); }
.dev.offline .dev-icon { opacity: 0.5; }
.dev.offline .dev-status { color: var(--danger); }
.dev-text { min-width: 0; }
.dev-name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dev-status {
  margin: 0;
  min-height: 1.45em;
  font-size: 14px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dev-body { display: flex; flex-direction: column; gap: 10px; }
.dev-note { margin: 0; font-size: 13px; color: var(--text-2); }
/* Sensors: readings sit under the name; "offline" is a corner label in its
   own layer, so a sensor dropping off never resizes its card. */
.dev-text > .readings { margin-top: 2px; gap: 2px 16px; }
.dev-flag {
  position: absolute;
  top: 10px;
  right: 14px;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  font-weight: 650;
}
.dev-sensor.offline .readings { opacity: 0.5; }
.dev-sensor.offline .dev-name { padding-right: 96px; }
.dev[aria-busy="true"]::after {
  content: "";
  position: absolute;
  top: 0;
  left: 14px;
  right: 14px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
  transform-origin: left;
}
@media (prefers-reduced-motion: no-preference) {
  .dev[aria-busy="true"]::after { animation: busy 0.9s ease-in-out infinite; }
}
@keyframes busy {
  0% { transform: scaleX(0); opacity: 1; }
  70% { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(1); opacity: 0; }
}

/* The on/off switch: a 52 x 32 track in a 60 x 44 target. */
.switch {
  display: grid;
  place-items: center;
  width: 60px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.switch-track {
  position: relative;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  background: var(--surface-3);
  transition: background-color 0.2s;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 25%);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.switch[aria-checked="true"] .switch-track { background: var(--accent); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(20px); }
.switch:disabled { opacity: 0.45; cursor: default; }
.switch:focus-visible { outline: none; }
.switch:focus-visible .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sliders: a 6 px track in a 44 px tall target. */
.slider { display: flex; flex-direction: column; }
.slider-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--text-2); }
.slider-value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.range {
  --p: 0%;
  width: 100%;
  height: 44px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.range:focus-visible { outline: none; }
.range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--surface-3) var(--p));
}
.range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--surface-3); }
.range::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
.range::-webkit-slider-thumb {
  width: 26px;
  height: 26px;
  margin-top: -10px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 22%);
  -webkit-appearance: none;
  appearance: none;
}
.range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 22%);
}
.range:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.range:focus-visible::-moz-range-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Colour temperature: the track shows the light itself, warm to cold. */
.range-color_temp::-webkit-slider-runnable-track { background: linear-gradient(to right, #ffb35c, #fff1dc 50%, #cfe2ff); }
.range-color_temp::-moz-range-track { background: linear-gradient(to right, #ffb35c, #fff1dc 50%, #cfe2ff); }
.range-color_temp::-moz-range-progress { background: transparent; }
.range:disabled { opacity: 0.45; cursor: default; }

/* Colour presets: 44 px targets around 32 px swatches. */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.swatch {
  display: grid;
  place-items: center;
  justify-self: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.swatch::before {
  content: "";
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 14%);
}
.swatch[aria-checked="true"]::before { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch:disabled { opacity: 0.45; cursor: default; }

/* Covers, gates, garages and locks: equal buttons in a row. */
.cover-row, .lock-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.lock-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.seg-btn { padding: 0 8px; font-size: 14px; }
.seg-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.dev.warn .lock-row .seg-btn[aria-pressed="true"] { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 400px) {
  /* Three labelled buttons fit a small phone only without their icons;
     the words carry the meaning. */
  .cover-row .icon { display: none; }
}

.media-btn { align-self: flex-start; min-width: 132px; }

/* The thermostat. */
.thermo { display: flex; flex-direction: column; gap: 10px; }
.thermo-set { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.thermo-label { color: var(--text-2); font-size: 14px; }
.thermo-stepper { display: flex; align-items: center; gap: 6px; }
.thermo-value {
  min-width: 5.5ch;
  font-size: 22px;
  font-weight: 650;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.segs { display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); gap: 6px; }
.seg {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.seg[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.seg:disabled { opacity: 0.45; cursor: default; }

/* Readings: each value in a slot that does not change width with it. */
.readings { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.reading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 6.5em;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.reading .icon { width: 18px; height: 18px; color: var(--text-2); }
.reading[data-alert="info"] { color: var(--accent); font-weight: 600; }
.reading[data-alert="warn"] { color: var(--warn); font-weight: 600; }
.reading[data-alert="danger"] { color: var(--danger); font-weight: 650; }
.reading[data-alert="info"] .icon, .reading[data-alert="warn"] .icon, .reading[data-alert="danger"] .icon { color: currentColor; }

/* Scenes: one tap each, above the rooms. */
.scenes { display: flex; flex-wrap: wrap; gap: 8px; }
.scene-btn { background: var(--surface); box-shadow: var(--shadow); max-width: 100%; }
.scene-btn > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene-btn .icon { color: var(--accent); }

/* Loading: the shape of the page, not a spinner. */
.skeleton { min-height: 76px; justify-content: center; }
.sk-line { height: 14px; width: 70%; border-radius: 7px; background: var(--surface-2); }
.sk-line.short { width: 40%; }
.sk-title { width: 120px; height: 18px; margin: 4px 2px 12px; border-radius: 9px; background: var(--surface-2); }
@media (prefers-reduced-motion: no-preference) {
  .sk-line, .sk-title { animation: pulse 1.4s ease-in-out infinite; }
}
@keyframes pulse { 50% { opacity: 0.5; } }
