:root {
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Akzentfarben – in beiden Themes identisch.
     *-rgb-Varianten erlauben rgba(var(--x-rgb), <alpha>). */
  --success: #34c759;            /* Grün: online, aktiv, erfolgreich */
  --success-rgb: 52, 199, 89;
  --danger: #ff453a;             /* Rot: Fehler, Löschen */
  --danger-rgb: 255, 69, 58;
  --active-fill: #e5e5ea;        /* Heller Aktiv-Hintergrund (Toggle an) */
  --active-fill-text: #1c1c1e;   /* Dunkler Text auf --active-fill */

  /* ===== Design-Tokens (theme-unabhängig) ===== */

  /* Eckenradius – abgestufte Skala */
  --radius-xs: 8px;              /* kleine Chips, Badges */
  --radius-sm: 10px;            /* Buttons, Eingaben */
  --radius-md: 12px;           /* Karten, Notizen */
  --radius-lg: 16px;          /* größere Karten */
  --radius-xl: 20px;         /* Kacheln, Sheets */
  --radius-2xl: 28px;       /* Tab-Bar */
  --radius-pill: 50%;      /* runde Buttons, Punkte */

  /* Schriftgrößen – abgestufte Skala */
  --fs-2xs: 11px;            /* Badges, Mini-Labels */
  --fs-xs: 12px;            /* Hilfetexte, Meta */
  --fs-sm: 13px;           /* sekundärer Text */
  --fs-base: 14px;        /* Standard-Text */
  --fs-md: 15px;         /* Eingaben, Buttons */
  --fs-lg: 17px;        /* Sheet-Titel */
  --fs-xl: 19px;       /* Abschnittstitel */
  --fs-2xl: 22px;     /* große Überschrift */
  --fs-3xl: 30px;    /* Seitentitel */

  /* Schriftgewichte */
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --fw-extrabold: 800;

  /* Festbreitschrift (Ziffern, Tags, MAC) */
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Standard-Beschleunigung für gleitende Animationen (FLIP, Sheets) */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);

  /* Zeilenhöhen */
  --lh-tight: 1.1;
  --lh-snug: 1.35;
  --lh-normal: 1.45;

  /* Rahmen- und Linienstärken */
  --bw-hairline: 0.5px;        /* dünne Trennlinien, Karten */
  --bw-thin: 1px;             /* Standard-Rahmen */
  --bw-thick: 2px;           /* hervorgehobene Rahmen */
  --stroke: 2;              /* SVG-Standard-Strichstärke */
  --stroke-thin: 1.8;     /* feinere Icons */

  /* Dark-Theme (Standard) */
  --bg: #000000;
  --text: #ffffff;
  --surface: #1c1c1e;          /* Kacheln */
  --surface-2: #2c2c2e;        /* Eingaben, Buttons */
  --surface-3: #3a3a3c;        /* Segmented-Hintergrund */
  --sheet-head: #141416;       /* Dialog-Kopf (dunkler als Body) */
  --card: rgba(30, 30, 32, 0.7);
  --card-strong: rgba(30, 30, 32, 0.72);
  --border: rgba(255, 255, 255, 0.12);
  --border-soft: rgba(255, 255, 255, 0.08);
  --text-dim: rgba(235, 235, 245, 0.85);
  --text-dim-2: rgba(235, 235, 245, 0.55);
  --text-dim-3: rgba(235, 235, 245, 0.4);
  --head-fade: rgba(0, 0, 0, 0.85);
  --overlay: rgba(0, 0, 0, 0.5);
  --btn-ghost: rgba(120, 120, 128, 0.24);
  --btn-ghost-active: rgba(120, 120, 128, 0.4);
  --nav-bg: rgba(30, 30, 32, 0.72);
  --card-elevated: #000000;
  --inset-shadow: none;
}

body.light {
  --bg: #e2e2e8;
  --text: #1c1c1e;
  --surface: #ffffff;
  --surface-2: #e9e9ee;
  --surface-3: #d8d8dd;
  --sheet-head: #d6d6dc;       /* Dialog-Kopf (dunkler als Body) */
  --card: rgba(255, 255, 255, 0.9);
  --card-strong: rgba(255, 255, 255, 0.92);
  --border: rgba(0, 0, 0, 0.12);
  --border-soft: rgba(0, 0, 0, 0.08);
  --text-dim: rgba(60, 60, 67, 0.95);
  --text-dim-2: rgba(60, 60, 67, 0.8);
  --text-dim-3: rgba(60, 60, 67, 0.65);
  --head-fade: rgba(226, 226, 232, 0.85);
  --overlay: rgba(0, 0, 0, 0.35);
  --btn-ghost: rgba(120, 120, 128, 0.16);
  --btn-ghost-active: rgba(120, 120, 128, 0.3);
  --nav-bg: rgba(255, 255, 255, 0.85);
  /* Main Controller etwas dunkler als der Hintergrund (#e2e2e8) */
  --card-elevated: #d8d8dd;
  --inset-shadow: none;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

/* Gemeinsame Icon-Grundeinstellung: Outline-Stil mit runden Enden.
   Komponenten setzen nur noch Größe und – falls abweichend – Strichfarbe
   oder -stärke. */
svg {
  fill: none;
  stroke: currentColor;
  stroke-width: var(--stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Scrollbalken in allen scrollbaren Bereichen ausblenden */
.page-scroll,
.scene-bar-scroll,
.module-tabs,
.channel-list,
.scene-preview {
  scrollbar-width: none;
}

.page-scroll::-webkit-scrollbar,
.scene-bar-scroll::-webkit-scrollbar,
.module-tabs::-webkit-scrollbar,
.channel-list::-webkit-scrollbar,
.scene-preview::-webkit-scrollbar {
  display: none;
}

body {
  background: var(--bg);
  color: var(--text);
  transition: background 0.25s ease, color 0.25s ease;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
}

.app {
  position: relative;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

/* ===== Pages ===== */
.pages {
  position: absolute;
  inset: 0;
}

.page {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.32s ease, transform 0.32s ease;
}

.page.is-active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ===== Module page ===== */
.page-scroll {
  padding: calc(env(safe-area-inset-top, 0px) + 40px) 18px
    calc(var(--safe-bottom) + 110px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Control-Page: zusätzlicher Platz für die Szenen-Leiste plus
   Scroll-Reserve, damit die letzte Kachel über die untere Fade-Zone
   hinausgescrollt werden kann (kein Überlappen mit dem Verlauf). */
#page-control.page-scroll {
  padding-bottom: calc(var(--safe-bottom) + 300px);
}

/* Kacheln am unteren Rand ausblenden, damit sie nicht hinter
   der Szenen-Leiste auftauchen */
body.page-control-active #page-control.page-scroll {
  -webkit-mask-image: linear-gradient(
    to bottom,
    #000 calc(100% - 270px),
    rgba(0, 0, 0, 0.85) calc(100% - 236px),
    transparent calc(100% - 195px)
  );
  mask-image: linear-gradient(
    to bottom,
    #000 calc(100% - 270px),
    rgba(0, 0, 0, 0.85) calc(100% - 236px),
    transparent calc(100% - 195px)
  );
}

/* Sticky Header für alle Seiten: bleibt oben stehen, sein Verlauf
   lässt durchscrollenden Inhalt darunter sanft verschwimmen */
.page-head {
  position: sticky;
  top: calc((env(safe-area-inset-top, 0px) + 40px) * -1);
  z-index: 5;
  margin: calc((env(safe-area-inset-top, 0px) + 40px) * -1) -18px 14px;
  padding: calc(env(safe-area-inset-top, 0px) + 40px) 18px 40px;
  text-align: center;
  background: linear-gradient(
    to bottom,
    var(--bg) 0%,
    var(--bg) 60%,
    var(--head-fade) 78%,
    transparent 100%
  );
  pointer-events: none;
}

/* Klickbare Elemente im sonst durchlässigen Header wieder aktivieren –
   nur auf der aktiven Seite, damit Buttons inaktiver Seiten (gleiche
   Position oben rechts) keine Klicks der sichtbaren Seite abfangen. */
.page.is-active .head-btn {
  pointer-events: auto;
}

/* "+"-Knopf im Control-Header (oben rechts) */
.head-btn {
  position: absolute;
  z-index: 31;
  top: calc(env(safe-area-inset-top, 0px) + 48px);
  width: 40px;
  height: 40px;
  border: var(--bw-hairline) solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--btn-ghost);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.15s ease;
}

.head-add {
  right: 16px;
}

.head-size {
  left: 16px;
}

.head-size svg {
  width: 18px;
  height: 18px;
  stroke-width: var(--stroke-thin);
}

.head-add svg {
  width: 20px;
  height: 20px;
}

.head-btn:active {
  transform: scale(0.9);
  background: var(--btn-ghost-active);
}

.page-title {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-extrabold);
  letter-spacing: -0.5px;
}

.page-sub {
  margin-top: 4px;
  font-size: var(--fs-base);
  color: var(--text-dim-2);
  font-weight: var(--fw-medium);
}

.mac-section {
  margin-bottom: 24px;
}

.mac-section[hidden] {
  display: none;
}

/* Abschnitts-Überschrift (Modul-Reiter + Kacheln + Regeln) */
.section-label {
  margin: 0;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim-3);
  padding: 0 6px 10px;
}

/* "Erneut suchen"-Button im Modul-Header (rund, oben rechts) */
.head-rescan {
  right: 16px;
}

.head-rescan:disabled {
  opacity: 0.7;
}

.head-rescan.is-scanning svg {
  animation: rescan-spin 0.8s linear infinite;
}

@keyframes rescan-spin {
  to {
    transform: rotate(360deg);
  }
}

.mac-hint {
  text-align: center;
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text-dim-3);
  padding: 28px 24px;
  background: var(--card);
  border: var(--bw-hairline) dashed var(--border);
  border-radius: var(--radius-lg);
}

.mac-hint[hidden] {
  display: none;
}

.mac-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mac-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: var(--bw-hairline) solid var(--border-soft);
  border-radius: var(--radius-lg);
}

/* Main Controller (dieses Gerät): wirkt eingelassen (inset shadow),
   als läge er vertieft im Hintergrund statt erhaben darüber. */
.mac-item.is-local {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 0;
  padding: 18px 16px;
  background: var(--card-elevated);
  border: var(--bw-thin) solid var(--border);
  box-shadow: var(--inset-shadow);
}

/* Detailblock über die volle Kartenbreite, unter der ersten Zeile */
.mac-item.is-local .mac-details {
  grid-column: 1 / -1;
}

.mac-item.is-local .mac-dot {
  width: 10px;
  height: 10px;
}

.mac-item.is-local .mac-addr {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
}

.mac-item.is-local .mac-meta {
  font-weight: var(--fw-semibold);
}

.mac-item.is-local .mac-actions {
  margin-left: 0;
}

/* Detailzeilen (MAC, Version) */
.mac-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: var(--bw-hairline) solid var(--border-soft);
}

.mac-detail {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: var(--fs-xs);
}

.mac-detail-label {
  color: var(--text-dim-3);
}

.mac-detail-value {
  color: var(--text-dim);
}

.mac-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mac-btn {
  border: none;
  cursor: pointer;
  font-weight: var(--fw-bold);
  border-radius: var(--radius-sm);
  transition: transform 0.12s ease, filter 0.2s ease;
}

.mac-btn:active {
  transform: scale(0.9);
  filter: brightness(0.85);
}

/* Alle Modul-Buttons teilen Hintergrund, Höhe und gedämpfte Schrift.
   Quadratische Icon-Buttons (rename/remove/theme) zusätzlich 38px breit
   und zentriert; Text-Buttons (ping/wifi) bekommen horizontales Padding. */
.mac-rename,
.mac-remove,
.mac-theme,
.mac-ping,
.mac-wifi {
  height: 38px;
  background: var(--surface-2);
  color: var(--text-dim);
}

.mac-rename,
.mac-remove,
.mac-theme {
  width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mac-remove {
  color: var(--danger);
}

.mac-rename svg,
.mac-remove svg,
.mac-theme svg,
.head-rescan svg {
  width: 18px;
  height: 18px;
}

.mac-ping,
.mac-wifi {
  padding: 0 16px;
  font-size: var(--fs-base);
}

.mac-ping {
  letter-spacing: 0.5px;
}

.mac-wifi {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

/* Im Dark-Mode Mond zeigen, im Light-Mode Sonne */
.mac-theme .icon-sun {
  display: none;
}
.mac-theme .icon-moon {
  display: block;
}
body.light .mac-theme .icon-sun {
  display: block;
}
body.light .mac-theme .icon-moon {
  display: none;
}

/* Light-Mode: sichtbare Hervorhebungen statt weiß-auf-weiß */
body.light .tile-relay.is-on {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.15);
}
body.light .sheet-input:focus {
  border-color: rgba(0, 0, 0, 0.25);
}

.mac-dot {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-pill);
  background: var(--success);
  box-shadow: 0 0 8px rgba(var(--success-rgb), 0.7);
  flex-shrink: 0;
}

.mac-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.mac-addr {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}

.mac-meta {
  font-size: var(--fs-xs);
  color: var(--text-dim-3);
}

/* Nur echte MAC-Adressen mit fester Breite (Monospace) */
.is-mac {
  font-family: var(--mono);
  letter-spacing: 0.3px;
}

/* ===== Control: tiles ===== */
.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  transition: opacity 0.16s ease;
}

.tile-grid.is-fading {
  opacity: 0;
}

/* Kompakte Ansicht: drei Kacheln pro Reihe */
.tile-grid.is-compact {
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

/* Inhalte in der kompakten Ansicht verkleinern */
.tile-grid.is-compact .tile-rgb,
.tile-grid.is-compact .tile-relay,
.tile-grid.is-compact .tile-analog {
  padding: 12px 10px 20px;
}

.tile-grid.is-compact .tile-rgb-dot {
  width: 44px;
  height: 44px;
}

.tile-grid.is-compact .tile-relay-toggle {
  width: 48px;
  height: 48px;
}

.tile-grid.is-compact .tile-relay-toggle svg {
  width: 22px;
  height: 22px;
}

.tile-grid.is-compact .tile-name {
  font-size: var(--fs-sm);
  max-width: 100%;
}

.tile-grid.is-compact .tile-rgb-hex,
.tile-grid.is-compact .tile-relay-state,
.tile-grid.is-compact .tile-analog-mode {
  display: none;
}

.tile-grid.is-compact .tile-analog-value {
  font-size: var(--fs-2xl);
}

.tile-grid.is-compact .tile-edit {
  right: 9px;
}

.tile {
  --tile-color: var(--text);
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: var(--bw-hairline) solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.12s ease;
}

/* Halten zum Löschen: Kachel fadet langsam aus */
.tile.is-deleting,
.scene-chip.is-deleting {
  animation: hold-delete-fade 3s linear forwards;
}

@keyframes hold-delete-fade {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.92);
  }
}

.tile:active {
  transform: scale(0.97);
}

/* Gemeinsames Layout aller Kacheltypen: Inhalt unten zentriert,
   das jeweilige Hauptelement (Kreis/Knopf/Wert) liegt absolut in der Mitte. */
.tile-rgb,
.tile-relay,
.tile-analog {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 16px 16px 22px;
  text-align: center;
}

/* Hauptelement jeder Kachel (Kreis / Knopf / Messwert) exakt mittig */
.tile-rgb-dot,
.tile-relay-toggle,
.tile-analog-value {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Farbiger Kreis – auch bei weißer Farbe durch dünnen Rand sichtbar */
.tile-rgb-dot {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-pill);
  background: var(--tile-color);
  border: var(--bw-thin) solid var(--border);
  box-shadow: 0 0 16px var(--tile-glow, transparent);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.tile-rgb .tile-name,
.tile-relay .tile-name,
.tile-analog .tile-name {
  position: static;
  margin-top: 8px;
  text-shadow: none;
  color: var(--text);
  text-align: center;
}

/* Bildunterschrift unter dem Kachel-Hauptelement (Hex / An-Aus / Modus) */
.tile-rgb-hex,
.tile-relay-state,
.tile-analog-mode {
  margin-top: 2px;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.03em;
  color: var(--text-dim-3);
}

.tile-rgb-hex {
  font-variant-numeric: tabular-nums;
}

.tile-name {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Nativer Picker liegt unsichtbar über der ganzen Kachel */
.tile-color {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  opacity: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

/* ===== Relais-Kachel (An/Aus) ===== */
.tile-relay {
  background: var(--surface);
  transition: background 0.2s ease, transform 0.12s ease;
}

.tile-relay.is-on {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.18);
}

.tile-relay:active {
  transform: scale(0.97);
}

/* Großer runder An/Aus-Knopf */
.tile-relay-toggle {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-dim-3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.tile-relay.is-on .tile-relay-toggle {
  background: var(--active-fill);
  color: var(--active-fill-text);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.25);
}

.tile-relay-power svg {
  width: 28px;
  height: 28px;
}

.tile-relay-state {
  text-transform: uppercase;
}

.tile-relay.is-on .tile-relay-state {
  color: var(--text);
}

/* ===== Analog-Kachel (Messwert) ===== */
.tile-analog {
  background: var(--surface);
}

/* Messwert */
.tile-analog-value {
  width: 100%;
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  color: var(--text);
  line-height: var(--lh-tight);
  font-variant-numeric: tabular-nums;
}

.tile-analog-unit {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--text-dim-2);
}

.tile-analog-mode {
  text-transform: uppercase;
}

.tile-edit {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 3;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.45);
  /* Button-Hintergrund ist immer dunkel – Icon daher fest weiß, damit es
     auch im Light-Mode gut sichtbar ist. */
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.tile-edit svg {
  width: 13px;
  height: 13px;
}

.tile-edit:active {
  filter: brightness(0.8);
}

/* ===== Typ-Auswahl-Popover (macOS-Stil, oben rechts) ===== */
.popover-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
}

.popover {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  right: 18px;
  min-width: 200px;
  padding: 6px;
  border-radius: var(--radius-md);
  background: var(--card-strong);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  border: var(--bw-hairline) solid var(--border);
  box-shadow: 0 16px 40px var(--overlay);
  transform-origin: top right;
  animation: popover-in 0.14s ease;
}

@keyframes popover-in {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.popover-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
}

.popover-item:active {
  background: var(--border);
}

.popover-icon {
  flex: none;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popover-icon svg {
  width: 19px;
  height: 19px;
  stroke: var(--text);
  stroke-width: var(--stroke-thin);
}

.popover-label {
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
}

/* ===== Szenen-Leiste (fix über der Navigation) ===== */
/* Standard ausgeblendet – nur auf der Control-Page sichtbar */
.scene-bar {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 92px);
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.scene-bar-title {
  padding-left: 4px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim-2);
}

.scene-bar-scroll {
  flex: 1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  pointer-events: auto;
}

.scene-chip {
  position: relative;
  flex: 0 0 auto;
  pointer-events: auto;
}

.scene-apply {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 96px;
  padding: 16px 14px 14px;
  border: var(--bw-hairline) solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--card-strong);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, background 0.15s ease;
}

.scene-apply:active {
  transform: scale(0.96);
  background: var(--border-soft);
}

.scene-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.scene-icon svg {
  width: 24px;
  height: 24px;
  stroke: var(--text-dim);
  stroke-width: var(--stroke-thin);
}

.scene-name {
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.page-control-active .scene-bar.has-scenes {
  opacity: 1;
  pointer-events: auto;
}

/* ===== Modul-Auswahl (horizontale Tab-Leiste) ===== */
/* hidden-Attribut hat Vorrang vor display-Regeln (z.B. im Szene-Modus) */
.module-tabs[hidden],
.channel-list[hidden],
.channel-summary[hidden],
.scene-preview[hidden] {
  display: none !important;
}

.module-tabs {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: visible;
  padding: 8px 2px 2px;
  -webkit-overflow-scrolling: touch;
}

.module-tab {
  position: relative;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-width: 96px;
  min-height: 46px;
  padding: 10px 14px;
  border: var(--bw-thin) solid transparent;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.module-tab.is-active {
  background: rgba(var(--success-rgb), 0.18);
  border-color: var(--success);
}

.module-tab-name {
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}

.module-tab-count {
  font-size: var(--fs-2xs);
  color: var(--text-dim-3);
}

.module-tab-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: var(--radius-sm);
  background: var(--success);
  color: var(--text);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.channel-list {
  margin-top: 12px;
  max-height: 34vh;
  overflow-y: auto;
  background: var(--surface-2);
  border-radius: var(--radius-md);
}

.channel-empty {
  text-align: center;
  font-size: var(--fs-base);
  color: var(--text-dim-3);
  padding: 28px 12px;
}

.channel-options {
  display: flex;
  flex-direction: column;
}

.channel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  cursor: pointer;
  user-select: none;
  border-top: var(--bw-hairline) solid var(--border-soft);
  transition: background 0.15s ease;
}

.channel-row:first-child {
  border-top: none;
}

.channel-row:active {
  background: var(--border-soft);
}

/* Bereits von einer anderen Kachel belegter Kanal – nicht wählbar */
.channel-row.is-locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.channel-row.is-locked:active {
  background: none;
}

.channel-taken {
  margin-left: 6px;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-dim-2);
}

.channel-row-label {
  flex: 1;
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  color: var(--text);
}

.channel-cb {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.channel-check {
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: var(--radius-pill);
  border: var(--bw-thick) solid var(--text-dim-3);
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.channel-row.is-checked .channel-check {
  background: var(--success);
  border-color: var(--success);
}

.channel-row.is-checked .channel-check::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 3px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.channel-summary {
  margin-top: 12px;
  text-align: center;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-dim);
}

/* Szene-Vorschau: was wird gespeichert */
.scene-preview {
  margin-top: 12px;
  max-height: 30vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
}

.scene-preview-group {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--text);
  margin-top: 4px;
}

.scene-preview-group:first-child {
  margin-top: 0;
}

.scene-preview-item {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  padding-left: 4px;
}

.scene-preview-empty {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-dim-3);
  text-align: center;
}

/* Anzeigeart-Auswahl (digital/Spannung) im Analog-Dialog */
.display-mode {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.display-mode[hidden] {
  display: none;
}

.display-mode-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-dim-2);
}

/* Szene-Umfang: Label über den Buttons, damit die drei Optionen
   die volle Breite nutzen können */
#rgb-scene-scope {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

#rgb-scene-scope .display-mode-label {
  padding-left: 2px;
}

#rgb-scene-scope .segmented {
  width: 100%;
}

.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn.is-active {
  background: var(--surface-3);
  color: var(--text);
}

/* Einzelauswahl-Zeile (Analog): runder Radio-Punkt statt Häkchen */
.channel-row.is-single .channel-check {
  border-radius: var(--radius-pill);
}

.channel-row.is-single.is-checked .channel-check {
  background: var(--success);
  border-color: var(--success);
}

.channel-row.is-single.is-checked .channel-check::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border: none;
  border-radius: var(--radius-pill);
  background: #fff;
  transform: translate(-50%, -50%);
}

/* ===== Rename sheet ===== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sheet-backdrop:not([hidden]) {
  opacity: 1;
}

.sheet-backdrop[hidden] {
  display: none;
}

.sheet {
  width: 100%;
  max-width: 340px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 20px 18px;
  border: var(--bw-hairline) solid var(--border);
  transform: scale(0.92);
  opacity: 0;
  transition: transform 0.28s var(--ease), opacity 0.2s ease;
}

.sheet-backdrop:not([hidden]) .sheet {
  transform: scale(1);
  opacity: 1;
}

/* Dunkler Kopfbereich (Titel, Untertitel, Namensfeld) – etwas dunkler
   als die darunterliegende Body-Fläche. */
.sheet-header {
  margin: -20px -18px 0;
  padding: 20px 18px 18px;
  background: var(--sheet-head);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.sheet-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  text-align: center;
}

.sheet-error {
  margin-top: 8px;
  font-size: var(--fs-sm);
  text-align: center;
  color: var(--danger);
}

.sheet-error[hidden] {
  display: none;
}

.sheet-mac {
  margin-top: 3px;
  text-align: center;
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  color: var(--text-dim-3);
}

.sheet-input {
  width: 100%;
  margin-top: 14px;
  padding: 12px 14px;
  font-size: var(--fs-md);
  text-align: center;
  color: var(--text);
  background: var(--surface-2);
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

/* ===== WLAN-Dialog ===== */
.sheet-wifi {
  max-width: 360px;
  padding: 24px 20px 20px;
}

.wifi-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.sheet-wifi .sheet-title {
  font-size: var(--fs-xl);
}

.wifi-sub {
  margin-top: 4px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-dim-2);
}

.wifi-field {
  margin-top: 18px;
}

.wifi-label {
  display: block;
  margin-bottom: 7px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-dim-2);
}

.sheet-wifi .sheet-input {
  margin-top: 0;
  text-align: left;
  background: var(--surface-2);
  border: var(--bw-hairline) solid var(--border);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.sheet-wifi .sheet-input:focus {
  border-color: var(--success);
  background: var(--surface-3);
}

.wifi-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 16px;
  font-size: var(--fs-xs);
  line-height: var(--lh-normal);
  text-align: left;
  color: var(--text-dim-2);
}

.wifi-hint svg {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  margin-top: 1px;
}

.wifi-note[hidden] {
  display: none;
}

.wifi-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 12px 14px;
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
  text-align: left;
  color: var(--success);
  background: rgba(var(--success-rgb), 0.12);
  border: var(--bw-hairline) solid rgba(var(--success-rgb), 0.3);
  border-radius: var(--radius-md);
}

.wifi-note svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  stroke-width: 2.5;
}

.wifi-note.is-error {
  color: var(--danger);
  background: rgba(var(--danger-rgb), 0.12);
  border-color: rgba(var(--danger-rgb), 0.3);
}

/* Nach dem Speichern: nur noch ein "Schließen"-Button */
#wifi-close {
  display: none;
}

.sheet-actions.is-saved #wifi-cancel,
.sheet-actions.is-saved #wifi-save {
  display: none;
}

.sheet-actions.is-saved #wifi-close {
  display: block;
}

.sheet-input:focus {
  border-color: rgba(255, 255, 255, 0.35);
}

.sheet-actions {
  display: flex;
  gap: 9px;
  margin-top: 16px;
}

.sheet-btn {
  flex: 1;
  padding: 12px;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sheet-cancel {
  background: var(--surface-2);
  color: var(--text);
}

.sheet-save {
  background: var(--success);
  color: #fff;
}

.sheet-btn:active {
  filter: brightness(0.85);
}

/* Deaktiviert: sichtbar ausgegraut, damit klar ist, dass noch etwas fehlt */
.sheet-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.sheet-btn:disabled:active {
  filter: none;
}

/* ===== Tab Bar (Apple Music style) ===== */
.tabbar {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 8px);
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 440px;
  display: flex;
  gap: 6px;
  padding: 8px;
  border-radius: var(--radius-2xl);
  background: var(--card-strong);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  border: var(--bw-hairline) solid var(--border);
  box-shadow:
    0 18px 40px var(--overlay),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  z-index: 10;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--text-dim-2);
  cursor: pointer;
  padding: 8px 6px;
  border-radius: var(--radius-lg);
  transition: color 0.25s ease;
}

.tab-icon {
  display: inline-flex;
}

.tab-icon svg {
  width: 22px;
  height: 22px;
  transition: transform 0.2s ease;
}

.tab-text {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1;
}

.tab.is-active {
  color: var(--text);
}

.tab:active .tab-icon svg {
  transform: scale(0.9);
}

/* ===== Automation: Regel-Liste ===== */
.rule-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rule-empty {
  margin-top: 8px;
  padding: 0 6px;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text-dim-3);
}

.rule-empty[hidden] {
  display: none;
}

/* Regel-Karte: gleiche Optik wie die MAC-Listen-Karten */
.rule-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: var(--bw-hairline) solid var(--border-soft);
  overflow: hidden;
}

/* Mittlerer Textblock: Name oben, WENN/DANN darunter */
.rule-card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.rule-card-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--text);
}

/* Rechte Aktions-Spalte: ▲ / Bearbeiten / ▼ vertikal gestapelt */
.rule-actions {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* Sortier-Pfeile (schlank) und Bearbeiten (quadratisch) teilen die Optik;
   nur die Höhe und der Opacity-Übergang der Pfeile unterscheiden sich. */
.rule-move,
.rule-edit {
  width: 34px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease, opacity 0.15s ease;
}

.rule-move {
  height: 24px;
}

.rule-edit {
  height: 34px;
}

.rule-move svg,
.rule-edit svg {
  width: 16px;
  height: 16px;
}

.rule-move:active,
.rule-edit:active {
  transform: scale(0.9);
  filter: brightness(0.85);
}

.rule-move:disabled {
  opacity: 0.3;
  cursor: default;
}

.rule-move:disabled:active {
  transform: none;
  filter: none;
}

/* Runder An/Aus-Button mit Positionsnummer: aus = neutral, an = grün gefüllt */
.rule-power {
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease,
    border-color 0.2s ease, box-shadow 0.2s ease, transform 0.12s ease;
}

/* Positionsnummer in Festbreitschrift */
.rule-power-num {
  font-family: var(--mono);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  line-height: 1;
  color: var(--text-dim-2);
  transition: color 0.2s ease;
}

.rule-power.is-on {
  background: var(--success);
  border-color: var(--success);
  box-shadow: 0 0 12px rgba(var(--success-rgb), 0.45);
}

.rule-power.is-on .rule-power-num {
  color: #fff;
}

.rule-power:active {
  transform: scale(0.9);
}

/* Zeilen "Wenn ..." und "Dann ..." */
.rule-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text-dim);
}

/* WENN/DANN als Monospace-Badge: fett, getönt, technischer Look */
.rule-tag {
  flex: none;
  width: 44px;
  padding: 2px 0;
  font-family: var(--mono);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  letter-spacing: 0.08em;
  text-align: center;
  border-radius: var(--radius-xs);
}

.rule-tag-when,
.rule-tag-then {
  background: var(--surface-2);
  color: var(--text-dim-2);
}

.rule-line-text {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rule-line-text strong {
  font-weight: var(--fw-semibold);
  color: var(--text);
}

/* Deaktivierte Regel: Inhalt gedimmt, Schalter/Status bleiben klar lesbar */
.rule-card.is-disabled {
  border-style: dashed;
}

.rule-card.is-disabled .rule-card-name,
.rule-card.is-disabled .rule-line {
  opacity: 0.45;
}

/* Lösch-Fortschritt beim Halten (wie Kacheln) */
.rule-card.is-deleting {
  animation: hold-delete-fade 3s linear forwards;
}

/* ===== Automation: Editor-Sheet ===== */
.sheet-rule {
  max-width: 360px;
}

/* Einklappbare Sektionen (Wenn / Dann) – flach im Sheet, keine eigenen
   Kästen. Nur eine dezente Trennlinie zwischen den Sektionen. */
.rule-section {
  border-top: var(--bw-hairline) solid var(--border-soft);
}

#rule-when {
  border-top: none;
}

.rule-section-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 2px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.rule-section-title {
  flex: none;
  font-family: var(--mono);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim-2);
}

.rule-section.is-open .rule-section-title {
  color: var(--text);
}

.rule-section-summary {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-dim-2);
  text-align: right;
}

.rule-section-chevron {
  flex: none;
  width: 16px;
  height: 16px;
  stroke: var(--text-dim-3);
  transition: transform 0.22s ease;
}

.rule-section.is-open .rule-section-chevron {
  transform: rotate(180deg);
}

/* Inhalt: flach, kein Rahmen/Hintergrund. */
.rule-section-body {
  padding: 0 0 14px;
}

/* Erstes Element im Body sitzt direkt unter dem Header (kein
   doppelter Abstand durch den module-tabs-Standard-margin). */
.rule-section-body > .module-tabs:first-child {
  margin-top: 0;
}

/* Gleicht den Header-Abstand des Aktion-Buttons an die module-tabs an:
   diese haben 8px internes Top-Padding (für Badges/Ränder), wodurch die
   Chips 8px tiefer starten. Der Button bekommt denselben Vorlauf. */
.rule-section-body > .rule-action-pick:first-child {
  margin-top: 8px;
}

.rule-section:not(.is-open) .rule-section-body {
  display: none;
}

.rule-section.is-open .rule-section-summary {
  display: none;
}

/* Schwellwert + Hysterese nebeneinander */
.rule-field-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.rule-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rule-field-label {
  padding-left: 2px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-dim-2);
}

.rule-field .sheet-input {
  margin-top: 0;
}

/* Zahlen-Eingaben in Festbreitschrift, damit Ziffern sauber ausgerichtet sind */
.sheet-input[type="number"] {
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

/* Aktion-Auswahl-Button (öffnet Popover) */
.rule-action-pick {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: background 0.15s ease;
}

.rule-action-pick svg {
  flex: none;
  width: 16px;
  height: 16px;
  stroke: var(--text-dim-2);
}

.rule-action-pick:active {
  background: var(--surface-2);
}

/* Effekt-Pick-Feld: Abstand zur darüberliegenden Kanal-Liste */
#rule-effect-pick {
  margin-top: 12px;
}

.rule-action-text.is-placeholder {
  color: var(--text-dim-3);
  font-weight: var(--fw-medium);
}

/* Typ-spezifische Aktionsfelder */
.rule-action-fields {
  margin-top: 12px;
}

.rule-action-fields[hidden] {
  display: none;
}

.rule-action-fields .module-tabs,
.rule-action-fields .channel-list {
  margin-top: 8px;
}

.rule-select {
  text-align: left;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

/* Farbauswahl-Zeile */
.rule-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding: 10px 14px;
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.rule-color-input {
  width: 44px;
  height: 30px;
  padding: 0;
  border: var(--bw-hairline) solid var(--border);
  border-radius: var(--radius-xs);
  background: none;
  cursor: pointer;
}

.rule-color-input::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.rule-color-input::-webkit-color-swatch {
  border: none;
  border-radius: var(--radius-xs);
}

/* Aktions-/Effekt-Auswahl-Popover liegt über dem geöffneten Regel-Sheet und
   wird mittig eingeblendet (statt oben rechts wie das Kachel-Popover). */
#action-sheet.popover-backdrop,
#effect-sheet.popover-backdrop {
  position: fixed;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
}

#action-sheet.popover-backdrop[hidden],
#effect-sheet.popover-backdrop[hidden] {
  display: none;
}

#action-sheet .popover,
#effect-sheet .popover {
  position: static;
  top: auto;
  right: auto;
  width: 100%;
  max-width: 280px;
  transform-origin: center;
}
