:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f6f8fa;
  --text: #17202a;
  --muted: #6b7684;
  --line: #dde2e8;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --green: #1a9f53;
  --red: #d93b3b;
  --yellow: #e0a800;
  --blue: #1f6feb;
  --off: #c9d0d8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f141a; --panel: #19212b; --panel-2: #212b37; --text: #e6ebf1; --muted: #8b97a6;
  --line: #2c3746; --accent: #4c8dff; --off: #3a4656; --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --panel: #19212b; --panel-2: #212b37; --text: #e6ebf1; --muted: #8b97a6;
    --line: #2c3746; --accent: #4c8dff; --off: #3a4656; --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--text); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); min-height: 56px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand { cursor: pointer; padding: 4px 8px; margin: -4px -8px; border-radius: 8px; }
.brand:hover { background: var(--panel-2); }
.brand-caret { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: -4px; }
.brand-edit { display: none; font-size: 13px; color: var(--muted); font-weight: 400; padding: 2px 6px; border-radius: 6px; }
.brand-edit:hover { background: var(--line); color: var(--text, inherit); }
body.editing .brand-edit { display: inline; }
.anlage-row.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.anlage-tools { display: flex; gap: 2px; }
.anlage-tools .btn { text-decoration: none; }
.anlage-tools .btn:disabled { opacity: .3; cursor: default; }
.btn.primary.danger-fill { background: var(--red); border-color: var(--red); }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #00b3a4); }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; min-width: 0; }
.tab {
  border: 0; background: none; padding: 8px 14px; border-radius: 8px; color: var(--muted);
  white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--panel-2); color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.tab.add { font-weight: 700; }
.tab-x { color: var(--muted); padding: 0 2px; }
.tab-x:hover { color: var(--red); }
.tab-edit { color: var(--muted); padding: 0 2px; }
.tab-edit:hover { color: var(--accent); }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.lang-select {
  width: auto; margin: 0; padding: 4px 6px; font-size: 13px; color: var(--text); cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
}
.lang-select option { color: var(--text); background: var(--panel); }

/* Seitenleiste am Rand */
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 970; width: min(300px, 86vw); overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line); box-shadow: var(--shadow);
  transform: translateX(-104%); transition: transform .22s ease-out; padding: 0 0 16px;
}
body.sidebar-right .sidebar { left: auto; right: 0; border-right: 0; border-left: 1px solid var(--line); transform: translateX(104%); }
body.sidebar-open .sidebar { transform: none; }
.sidebar-handle {
  position: fixed; top: 50%; left: 0; z-index: 965; transform: translateY(-50%);
  width: 22px; height: 56px; padding: 0; font-size: 13px; color: var(--muted); cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-left: 0; border-radius: 0 10px 10px 0; box-shadow: var(--shadow); opacity: .8;
}
.sidebar-handle:hover { opacity: 1; color: var(--accent); }
body.sidebar-right .sidebar-handle { left: auto; right: 0; border-left: 1px solid var(--line); border-right: 0; border-radius: 10px 0 0 10px; }
body.sidebar-open .sidebar-handle { display: none; }
.sb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 8px 10px 16px; font-weight: 700; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.sb-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 14px 16px 6px; }
.sb-pages { display: flex; flex-direction: column; }
.sb-page { text-align: left; padding: 11px 16px; border: 0; background: none; color: var(--text); font: inherit; cursor: pointer; border-left: 3px solid transparent; }
.sb-page:hover { background: var(--panel-2); }
.sb-page.active { font-weight: 700; border-left-color: var(--accent); background: var(--panel-2); }
.sb-fav { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 16px; min-height: 44px; }
.sb-fav + .sb-fav { border-top: 1px solid var(--line); }
.sb-fav.bad .sb-value { color: var(--muted); text-decoration: line-through; }
.sb-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-value { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.toggle.sb-toggle { width: 48px; height: 28px; flex: none; cursor: pointer; }
.toggle.sb-toggle .knob { top: 3px; left: 3px; width: 22px; height: 22px; }
.toggle.sb-toggle.on .knob { left: 23px; }
.sb-empty { padding: 16px; }
.sb-fav-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Einstellungsmenü (⚙) */
.settings { position: relative; }
#btn-settings { font-size: 17px; line-height: 1; }
#btn-settings.active { background: var(--panel-2); }
.settings-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 960; min-width: 240px;
  display: flex; flex-direction: column; padding: 6px; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; margin: 0;
  border: 0; border-radius: 7px; background: none; color: var(--text); text-align: left; text-decoration: none;
  cursor: pointer; font: inherit; white-space: nowrap;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--panel-2); outline: none; }
.menu-icon { width: 20px; text-align: center; flex: none; }
.menu-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.menu-text small { font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.menu-text small:empty { display: none; }

.btn {
  border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.icon { padding: 8px 10px; }
.btn.danger { color: var(--red); }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: var(--off); }
.dot.connected { background: var(--green); }
.dot.connecting { background: var(--yellow); animation: pulse 1s infinite alternate; }
.dot.error { background: var(--red); }
@keyframes pulse { to { opacity: .35; } }

/* Kopfleiste einklappen */
body.bar-closed .topbar { display: none; }
#bar-open { display: none; }
body.bar-closed #bar-open {
  display: block; position: fixed; top: 0; right: 12px; z-index: 900; padding: 1px 12px; font-size: 13px; line-height: 1.3;
  background: var(--panel); color: var(--muted); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; box-shadow: var(--shadow);
}

/* ---------- Arbeitsfläche ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.board { flex: 1; overflow: auto; padding: 8px; position: relative; }
/* Ebenen von hinten nach vorne: Formen (hinten) → Elemente (#grid) → Formen (vorne) */
.grids { position: relative; }
/* --gap 0: Formen werden ohne Innenabstand gezeichnet – sie haben ihr eigenes feines Raster */
.shape-layer { position: absolute; inset: 0; pointer-events: none; --gap: 0px; }
#shapes-back { z-index: 0; }
/* Vorlage: zwischen den hinteren Formen und den Elementen der Seite. Leere Stellen der Seite lassen Klicks zur Vorlage durch */
.template-layer { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
#template-grid { position: absolute; top: 0; left: 0; right: 0; }
#template-grid > .grid-stack-item { pointer-events: auto; }
body:not(.editing) #grid { pointer-events: none; }
body:not(.editing) #grid > .grid-stack-item { pointer-events: auto; }
body.editing .template-layer { opacity: .35; filter: grayscale(.4); }
body.editing #template-grid > .grid-stack-item { pointer-events: none; }
#template-grid :is(.w-tools, .w-grip, .w-tag) { display: none !important; }
.tpl-mark { color: var(--accent); margin-right: 2px; }
/* Reiter ziehen (Bau-Modus): Markierung, wo die Seite landet */
body.editing .tab[draggable="true"] { cursor: grab; }
.tab.dragging { opacity: .4; }
body.editing .tab[data-id] { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.tab.drop-before { box-shadow: inset 3px 0 0 var(--accent); }
.tab.drop-after { box-shadow: inset -3px 0 0 var(--accent); }
.page-move { display: flex; gap: 8px; flex-wrap: wrap; }
.tpl-help { margin: -6px 0 12px 26px; }
#grid { z-index: 1; }
#shapes-front { z-index: 2; }
body.editing.layer-shapes #grid { pointer-events: none; opacity: .35; }
body.editing.layer-shapes .shape-item { pointer-events: auto; cursor: move; }

.shape-item { position: absolute; touch-action: none; }
.shape-inner { position: absolute; inset: var(--gap, 8px); }
.shape-box { position: absolute; inset: 0; }
.shape-label { position: absolute; top: 6px; left: 10px; font-size: 13px; font-weight: 700; letter-spacing: .02em; }
.shape-line { position: absolute; inset: 0; display: flex; }
.shape-line.h { align-items: center; }
.shape-line.h > div { width: 100%; }
.shape-line.v { justify-content: center; }
.shape-line.v > div { height: 100%; }
.shape-tools, .shape-resize, .shape-badge { display: none; }
body.editing.layer-shapes .shape-item:hover > .shape-inner,
body.editing.layer-shapes .shape-item.selected > .shape-inner { outline: 2px dashed var(--accent); outline-offset: 2px; }
body.editing.layer-shapes .shape-item:hover .shape-tools,
body.editing.layer-shapes .shape-item.selected .shape-tools { display: flex; }
body.editing.layer-shapes .shape-item.selected .shape-resize,
body.editing.layer-shapes .shape-item:hover .shape-resize { display: block; }
body.editing .shape-badge { display: block; }
.shape-tools { position: absolute; top: 0; right: 0; gap: 2px; z-index: 2; transform: translateY(-60%); }
.shape-tools button { border: 0; background: var(--panel); color: var(--text); box-shadow: var(--shadow); border-radius: 6px; padding: 2px 7px; font-size: 12px; }
.shape-tools button:hover { background: var(--panel-2); }
.shape-resize {
  position: absolute; right: calc(var(--gap, 8px) - 7px); bottom: calc(var(--gap, 8px) - 7px); width: 14px; height: 14px;
  background: var(--accent); border: 2px solid var(--panel); border-radius: 3px; cursor: nwse-resize;
}
.shape-badge { position: absolute; left: var(--gap, 8px); bottom: calc(var(--gap, 8px) + 2px); font-size: 10px; padding: 0 5px; border-radius: 4px; background: var(--accent); color: #fff; opacity: .8; }
.shape-photo { width: 100%; height: 100%; display: block; border-radius: 4px; user-select: none; pointer-events: none; }
.shape-photo-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: 14px; border: 1px dashed var(--line); border-radius: 4px; }
.shape-item.dragging { opacity: .8; }
.shape-item.just-added > .shape-inner { animation: added 1.2s ease-out; }
.shape-ghost { position: fixed; z-index: 2000; pointer-events: none; padding: 8px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--accent); box-shadow: var(--shadow); font-size: 13px; }
#layer-switch { margin-bottom: 10px; }

body.editing .board {
  background-image: radial-gradient(var(--line) 1.2px, transparent 1.2px);
  background-size: 24px 24px;
}
body.offline .board { opacity: .5; }
body.offline::after {
  content: "Keine Verbindung zum Server – verbinde neu …"; position: fixed; bottom: 16px; left: 50%;
  transform: translateX(-50%); background: var(--red); color: #fff; padding: 8px 16px; border-radius: 8px;
}

.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); pointer-events: none; }
.empty h2 { margin: 8px 0 4px; color: var(--text); }
.empty-icon { font-size: 48px; opacity: .4; }

/* Handy: Knopf und Abdunklung fuers Slide-In, siehe @media unten */
#btn-add, #drawer-back, #drawer-close { display: none; }

/* ---------- Palette ---------- */
.palette {
  width: 200px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  padding: 12px; overflow-y: auto; display: none;
}
body.editing .palette { display: block; }
.palette h3 { margin: 0; font-size: 14px; }
.palette .hint { margin: 2px 0 12px; color: var(--muted); font-size: 13px; }
/* nur die Einträge in der Leiste – nicht das gezogene Abbild (das positioniert gridstack selbst) */
.palette .palette-item { position: relative !important; width: auto !important; height: auto !important; margin-bottom: 6px; cursor: grab; }
body > .palette-item.ui-draggable-dragging { width: 180px !important; height: auto !important; opacity: .9; cursor: grabbing; z-index: 1000; }
.palette .palette-item > .grid-stack-item-content, body > .palette-item.ui-draggable-dragging > .grid-stack-item-content {
  position: static; display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; inset: auto;
}
.palette-item:hover .grid-stack-item-content { border-color: var(--accent); }
.palette-item:active .grid-stack-item-content { background: color-mix(in srgb, var(--accent) 14%, var(--panel-2)); }
.grid-stack-item.just-added > .grid-stack-item-content { animation: added 1.2s ease-out; }
@keyframes added { from { box-shadow: 0 0 0 4px var(--accent); } to { box-shadow: var(--shadow); } }
.palette-sub { margin-top: 16px !important; margin-bottom: 6px !important; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 6px; font-size: 13px; color: var(--muted); }
.seg button.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.p-icon { width: 28px; text-align: center; font-size: 17px; color: var(--accent); font-weight: 700; }

/* ---------- Elemente ---------- */
.grid-stack-item-content {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden !important;
}
.grid-stack-item-content.bad { border-style: dashed; border-color: var(--red); }
.grid-stack-item-content.bad .w-body { opacity: .45; }
.grid-stack-item-content.offline::after {
  content: attr(data-offline); position: absolute; right: 6px; bottom: 6px; z-index: 2; pointer-events: none;
  font-size: 11px; line-height: 1; padding: 3px 6px; border-radius: 4px; background: var(--red); color: #fff;
}
.grid-stack-placeholder > .placeholder-content { background: color-mix(in srgb, var(--accent) 12%, transparent); border: 2px dashed var(--accent); border-radius: var(--radius); }

.w-head { display: flex; align-items: center; gap: 6px; padding: 8px 12px 0; min-height: 30px; }
.w-title { flex: 1; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-tools { display: none; gap: 2px; }
.w-tools button { border: 0; background: var(--panel-2); border-radius: 6px; padding: 2px 7px; font-size: 13px; }
.w-tools button:hover { background: var(--line); }
.w-more, .w-grip { display: none; }
body.editing .w-tools { display: flex; }
body.editing .w-head { cursor: move; }
body.editing .w-body { pointer-events: none; }
body.editing .choose-tag { pointer-events: auto; }
.w-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px 12px; }
.w-tag { display: none; font-size: 11px; color: var(--muted); padding: 0 12px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.editing .w-tag, .w-tag.always { display: block; }
/* Überschrift ausgeblendet: im Betrieb ganz weg (mehr Platz), beim Bauen bleibt die Zeile als Griff zum Verschieben */
.no-title .w-title { visibility: hidden; }
body:not(.editing) .no-title .w-head { display: none; }
body:not(.editing) .no-title .w-body { padding-top: 10px; }
.w-missing { padding: 12px; color: var(--red); }

.choose-tag {
  border: 2px dashed var(--accent); color: var(--accent); background: none; border-radius: 8px;
  padding: 10px 14px; font-weight: 600;
}

.w-value { font-size: clamp(22px, 3.2vw, 40px); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

.w-gauge { width: 100%; height: 100%; }
.g-bg, .g-fg { fill: none; stroke-width: 16; stroke-linecap: round; }
.g-bg { stroke: var(--panel-2); }
.scan-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.scan-form .field { flex: 1 1 70px; min-width: 70px; margin: 0; }
.scan-form .btn { flex: none; }
.scan-list { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.scan-row { display: flex; align-items: center; gap: 10px; padding: 3px 6px; border-radius: 6px; }
.scan-row.changed { background: color-mix(in srgb, var(--yellow) 22%, transparent); }
.scan-addr { flex: none; width: 64px; font-variant-numeric: tabular-nums; font-weight: 600; }
.scan-values { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.scan-val { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--text); font: inherit; font-size: 12px; font-variant-numeric: tabular-nums; cursor: pointer; }
.scan-val:hover { border-color: var(--accent); }
.g-zone { fill: none; stroke-width: 4; }
/* Runde Enden ragen über den Wert hinaus, an den Grenzen des Rings fiele das auf */
.zoned .g-bg, .zoned .g-fg { stroke-linecap: butt; }
.zones { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.zones:empty { display: none; }
.zone-flags { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.zone-flags[hidden] { display: none; }
.zone-row { display: flex; align-items: center; gap: 8px; }
.zone-row input[type=number] { flex: 1; min-width: 0; }
.zone-row input[type=color] { flex: none; width: 44px; height: 34px; padding: 2px; }
.g-fg { stroke: var(--accent); stroke-dasharray: 0 100; transition: stroke-dasharray .4s; }
.g-val { text-anchor: middle; font-size: 30px; font-weight: 650; fill: var(--text); font-variant-numeric: tabular-nums; }
.g-unit { text-anchor: middle; font-size: 14px; fill: var(--muted); }
.g-scale { text-anchor: middle; font-size: 11px; fill: var(--muted); }

.w-bar { display: flex; align-items: center; gap: 12px; height: 100%; }
.bar-track { width: 42px; height: 100%; background: var(--panel-2); border-radius: 8px; position: relative; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { position: absolute; bottom: 0; left: 0; right: 0; background: var(--accent); transition: height .4s; }
.bar-val { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }

.w-led { display: flex; align-items: center; gap: 12px; }
.lamp { width: 34px; height: 34px; border-radius: 50%; background: var(--off); transition: .2s; }
.lamp.on.c-green { background: var(--green); box-shadow: 0 0 14px var(--green); }
.lamp.on.c-red { background: var(--red); box-shadow: 0 0 14px var(--red); }
.lamp.on.c-yellow { background: var(--yellow); box-shadow: 0 0 14px var(--yellow); }
.lamp.on.c-blue { background: var(--blue); box-shadow: 0 0 14px var(--blue); }
.lamp-text { font-size: 18px; font-weight: 600; }

.w-switch { display: flex; align-items: center; gap: 12px; }
.toggle { width: 72px; height: 40px; border-radius: 20px; border: 0; background: var(--off); position: relative; transition: .2s; }
.toggle .knob { position: absolute; top: 4px; left: 4px; width: 32px; height: 32px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle.on { background: var(--w-on, var(--green)); }
.toggle.on .knob { left: 36px; }
.switch-text { font-weight: 600; min-width: 36px; }

/* Element „Lampe“ */
.w-lamp { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.lamp-toggle { --lamp: #ffc95c; flex: 1 1 auto; min-height: 0; width: 100%; max-height: 96px; border: 0; background: none; padding: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.lamp-bulb { display: block; height: 100%; max-height: 72px; aspect-ratio: 1; min-height: 28px; background: var(--off); transition: background .2s, filter .2s;
  mask: url(/lib/icons/filled/bulb.svg) center / contain no-repeat; -webkit-mask: url(/lib/icons/filled/bulb.svg) center / contain no-repeat; }
.lamp-toggle.on .lamp-bulb { background: var(--lamp); filter: drop-shadow(0 0 10px var(--lamp)); }
.lamp-row { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 28px; }
.lamp-state { font-weight: 600; }
.lamp-more { border: 1px solid var(--border); background: var(--panel-2); border-radius: 8px; width: 30px; height: 28px; padding: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text); }
.lamp-more-icon { width: 18px; height: 18px; background: currentColor;
  mask: url(/lib/icons/outline/adjustments-horizontal.svg) center / contain no-repeat; -webkit-mask: url(/lib/icons/outline/adjustments-horizontal.svg) center / contain no-repeat; }
body.editing .lamp-toggle, body.editing .lamp-more { pointer-events: none; }
.lamp-panel { display: flex; flex-direction: column; gap: 18px; min-width: min(320px, 80vw); }
.lamp-panel-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }
.lamp-panel-row.col { flex-direction: column; align-items: stretch; }
.lamp-panel-head { display: flex; justify-content: space-between; }
.lamp-panel-val { color: var(--muted); font-weight: 500; }
.lamp-range { width: 100%; height: 28px; -webkit-appearance: none; appearance: none; border-radius: 14px; background: var(--panel-2); outline: none; }
.lamp-range.bri { background: linear-gradient(90deg, #333, #fff3d6); }
.lamp-range.kelvin { background: linear-gradient(90deg, #ff9329, #ffd6a5, #fff, #c9dcff); }
.lamp-range::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid #555; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.lamp-range::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid #555; }
.lamp-wheel { position: relative; width: min(240px, 70vw); aspect-ratio: 1; margin: 4px auto; border-radius: 50%; touch-action: none; cursor: crosshair;
  background: radial-gradient(circle closest-side, #fff, rgba(255,255,255,0)), conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.lamp-wheel-mark { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.4); pointer-events: none; left: 50%; top: 50%; }
.lamp-presets { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.lamp-preset { width: 32px; height: 32px; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--text) 30%, transparent); cursor: pointer; }

.w-button { width: 100%; height: 100%; display: flex; }
.push {
  flex: 1; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-size: 18px; font-weight: 700;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, #000); user-select: none; touch-action: none; margin-bottom: 4px;
}
.push.down { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.push.active { outline: 3px solid var(--green); outline-offset: 2px; }
.push.link { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 12px; cursor: pointer; min-width: 0; }
.push.link:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.push.link.missing { background: var(--panel-2); color: var(--muted); box-shadow: none; font-weight: 500; cursor: default; }
.link-arrow { font-size: 1.1em; opacity: .85; }

/* Auswahl (Seite wechseln / Wert schreiben) */
.w-choice { width: 100%; height: 100%; display: flex; align-items: center; }
.choice-select {
  width: 100%; min-width: 0; margin: 0; padding: 10px 36px 10px 12px; font-size: 16px; font-weight: 600; cursor: pointer;
  color: var(--text); background-color: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  appearance: none; -webkit-appearance: none; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%; background-size: 6px 6px; background-repeat: no-repeat;
}
.choice-select:hover:not(:disabled) { border-color: var(--accent); }
.choice-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.choice-select:disabled { cursor: default; color: var(--muted); font-weight: 500; }
.choice-select option { color: var(--text); background: var(--panel); font-weight: 400; }
.page-checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.page-check { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.field .page-check input { width: auto; padding: 0; }
.choice-rows { display: flex; flex-direction: column; gap: 6px; }
.choice-row { display: flex; align-items: center; gap: 4px; }
.field .choice-row input { padding: 6px 8px; min-width: 0; }
.field .choice-row input.choice-value { width: 90px; flex: 0 0 90px; }
.field .choice-row input.choice-text { width: auto; flex: 1 1 auto; }
.choice-arrow { color: var(--muted); }
.choice-bad { color: var(--red); cursor: help; }
.choice-row .btn.icon { padding: 4px 6px; }
.choice-row .btn:disabled { opacity: .3; cursor: default; }

/* Schmale Kacheln (Handy quer, kleine Spalten): richtet sich nach der Kachel selbst, nicht nach dem Bildschirm */
.grid-stack-item-content { container-type: inline-size; }
@container (max-width: 150px) {
  .w-head { padding-left: 8px; padding-right: 8px; }
  .w-tools button { padding: 2px 4px; }
  .w-body { padding-left: 6px; padding-right: 6px; }
  .w-tag { padding-left: 8px; padding-right: 8px; }
  .w-switch, .w-led { flex-direction: column; gap: 4px; }
  .switch-text, .lamp-text { min-width: 0; font-size: 14px; text-align: center; }
  .w-bar { gap: 6px; }
  .bar-track { width: 24px; }
  .bar-val { font-size: 14px; }
  .push { font-size: 14px; overflow-wrap: anywhere; }
  .push.link { padding: 0 4px; gap: 4px; }
  .choose-tag { padding: 6px 4px; font-size: 12px; max-width: 100%; }
}
@container (max-width: 100px) {
  .toggle { width: 56px; height: 32px; }
  .toggle .knob { top: 4px; left: 4px; width: 24px; height: 24px; }
  .toggle.on .knob { left: 28px; }
  .lamp { width: 26px; height: 26px; }
}

.w-slider { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.slider-val { font-size: 24px; font-weight: 650; text-align: center; font-variant-numeric: tabular-nums; }
.w-slider input { width: 100%; accent-color: var(--accent); height: 28px; }

.w-trend { width: 100%; height: 100%; display: flex; flex-direction: column; min-height: 0; }
.trend-plot { flex: 1; min-height: 0; position: relative; }
.trend-legend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--muted); padding-bottom: 2px; }
.trend-legend i, .trend-tip i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }
.trend-tip {
  position: absolute; z-index: 3; pointer-events: none; max-width: 90%; padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); font-variant-numeric: tabular-nums;
}
.trend-tip[hidden] { display: none; }
.trend-tip-time { color: var(--muted); font-size: 11px; }
.zone-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zone-spacer { flex: none; width: 34px; }
.zone-row select.zone-axis { flex: none; width: 88px; padding-left: 6px; padding-right: 2px; }
.scan-form[hidden] { display: none; }
.w-trend .uplot { font-family: inherit; }

/* Anlagensymbole */
.w-body.w-symbol-body { padding: 4px; flex-direction: column; gap: 2px; }
.sym-wrap { flex: 1; min-height: 0; width: 100%; display: flex; }
.sym {
  --sym-off: var(--off); --sym-line: var(--text); --sym-on: var(--green);
  width: 100%; height: 100%; overflow: visible;
}
.sym .ln, .sym .pipe, .sym .coil { fill: none; stroke: var(--sym-line); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.sym .ln.thin { stroke-width: 2.5; }
.sym .ln.thick { stroke-width: 6; }
.sym .bd { fill: var(--sym-off); stroke: var(--sym-line); stroke-width: 4; stroke-linejoin: round; transition: fill .3s; }
.sym.on .bd { fill: var(--sym-on); }
.sym .in { fill: var(--panel); }
.sym .in.ln { fill: var(--panel); }
.sym .hub { fill: var(--sym-line); }
.sym .lbl { fill: var(--sym-line); font: 700 30px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; }
.sym .lbl.small { font-size: 22px; }
.sym .lvl { fill: var(--sym-on); }
.sym .coil { stroke-width: 5; stroke: var(--sym-off); transition: stroke .3s; }
.sym.on .coil { stroke: var(--sym-on); filter: drop-shadow(0 0 4px var(--sym-on)); }
.sym .pipe { stroke-width: 12; stroke-linecap: butt; }
.sym .pipe-flow { fill: none; stroke: var(--sym-on); stroke-width: 4; opacity: 0; }
.sym.on .pipe-flow { opacity: 1; }
.sym.stretch .pipe, .sym.stretch .pipe-flow { vector-effect: non-scaling-stroke; }
.sym .flow { stroke-dasharray: 10 8; }
.sym.on .flow { animation: sym-flow .6s linear infinite; }
.sym .spin { transform-box: fill-box; transform-origin: center; }
.sym.on .spin { animation: sym-spin 1.2s linear infinite; }
@keyframes sym-spin { to { transform: rotate(360deg); } }
@keyframes sym-flow { to { stroke-dashoffset: -18; } }
@media (prefers-reduced-motion: reduce) { .sym.on .spin, .sym.on .flow { animation: none; } }
.sym-val { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Piktogramme */
.icon-mask {
  display: block; background: currentColor;
  mask: center / contain no-repeat; -webkit-mask: center / contain no-repeat;
}
.w-icon { width: 100%; height: 100%; background: var(--accent); transition: background .3s; }
.w-icon.off { background: var(--icon-off, var(--off)); }
.icon-search { display: flex; gap: 8px; }
.icon-search input { flex: 1 1 auto; min-width: 0; width: auto; }
.icon-search select { flex: 0 0 170px; width: 170px; }
.icon-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px;
  max-height: 230px; overflow-y: auto; margin-top: 8px; padding: 2px;
}
.icon-pick { height: 44px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); padding: 9px; color: var(--text); }
.icon-pick .icon-mask { width: 100%; height: 100%; }
.icon-pick:hover { border-color: var(--muted); }
.icon-pick.active { border: 2px solid var(--accent); color: var(--accent); }

/* Auswahl als Kacheln (Anlagensymbole) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 4px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 12px; color: var(--text);
}
.tile-pic { width: 100%; height: 44px; display: flex; }
.tile:hover { border-color: var(--muted); }
.tile.active { border: 2px solid var(--accent); }

/* Foto */
.w-body.w-image-body { padding: 4px 8px 8px; }
.w-image { width: 100%; height: 100%; display: block; border-radius: calc(var(--radius) - 4px); user-select: none; }
.w-image-empty { color: var(--muted); font-size: 14px; text-align: center; }
.grid-stack-item-content.no-frame { background: transparent; border-color: transparent; box-shadow: none; }
.no-frame .w-body.w-image-body { padding: 0; }
.no-frame .w-head { position: absolute; inset: 0 0 auto 0; z-index: 1; padding: 6px; }
.no-frame .w-title { visibility: hidden; }
body:not(.editing) .no-frame .w-head { display: none; }
body.editing .grid-stack-item-content.no-frame { border: 1px dashed var(--line); }
.img-preview {
  height: 140px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; overflow: hidden;
}
.img-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.img-actions { display: flex; gap: 8px; margin-top: 8px; }
.img-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; max-height: 150px; overflow-y: auto; margin-top: 4px; }
.img-thumb { padding: 0; height: 56px; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--panel-2); cursor: pointer; }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-thumb:hover { border-color: var(--muted); }
.img-thumb.active { border-color: var(--accent); }

.w-text { width: 100%; font-weight: 600; }
.w-text.s-l { font-size: 22px; }
.w-text.s-xl { font-size: 32px; }

/* ---------- Dialoge ---------- */
.dlg {
  border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dlg.wide { width: min(860px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(10, 15, 25, .45); }
.dlg-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; flex: 1; font-size: 18px; }
.dlg-body { padding: 16px 18px; overflow: auto; max-height: calc(100vh - 120px); }
.dlg-actions { display: flex; gap: 8px; margin-top: 16px; }
/* Knöpfe unten im Dialog bleiben beim Scrollen sichtbar */
.dlg-body > .dlg-actions:last-child {
  position: sticky; bottom: -16px; margin: 16px -18px -16px; padding: 12px 18px;
  background: var(--panel); border-top: 1px solid var(--line);
}

.color-section { margin: 4px 0 12px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.color-section summary { cursor: pointer; font-weight: 600; }
.color-section summary small { color: var(--muted); font-weight: 400; }
.color-section[open] summary { margin-bottom: 8px; }

/* Farbwahl */
.color-field { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); padding: 0; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatch.custom {
  position: relative; overflow: hidden; display: grid; place-items: center;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
}
.swatch.auto {
  background: linear-gradient(135deg, #ffffff 50%, #19212b 50%); color: #7a8899;
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}
.swatch.clear, .grid-stack-item-content.w-transparent { --checker: color-mix(in srgb, #7a8899 35%, transparent); }
.swatch.clear {
  background: repeating-conic-gradient(var(--checker) 0 25%, transparent 0 50%) 0 0 / 10px 10px;
}
.grid-stack-item-content.w-transparent { background: transparent; border-color: transparent; box-shadow: none; }
body.editing .grid-stack-item-content.w-transparent { border: 1px dashed var(--line); }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.color-values { display: flex; gap: 8px; margin-top: 8px; }
.rgb { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rgb span { font-size: 11px; color: var(--muted); font-weight: 600; }
.rgb input {
  width: 64px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
  font-variant-numeric: tabular-nums; font-size: 14px; text-align: center;
}
.rgb input.hex { width: 96px; font-family: ui-monospace, monospace; font-size: 13px; }
.rgb input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .search {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); width: 100%;
}
.field input:focus, .field select:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field small { color: var(--muted); font-size: 12px; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint-box { background: var(--panel-2); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.tag-line { display: flex; gap: 8px; align-items: center; }
.tag-line > span { flex: 1; padding: 8px 0; }

/* Datenpunkt-Auswahl */
.picker { display: grid; grid-template-columns: 200px 1fr; gap: 16px; min-height: 380px; }
.pick-side { display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--line); padding-right: 12px; }
.pick-conn { display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 9px 10px; border-radius: 8px; text-align: left; }
.pick-conn:hover { background: var(--panel-2); }
.pick-conn.active { background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 600; }
.pick-conn.add { color: var(--accent); margin-top: 8px; }
.pick-right { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.pick-main h4 { margin: 12px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.pick-main h4:first-child { margin-top: 0; }
.pick-list { display: flex; flex-direction: column; gap: 2px; }
.pick-item {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left;
  padding: 8px 10px; border-radius: 8px;
}
.pick-item:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.pick-item.active { outline: 2px solid var(--accent); }
.pick-item.disabled { opacity: .45; }
.pick-row { display: flex; align-items: center; gap: 4px; }
.pick-row > .pick-item { flex: 1; min-width: 0; }
.pick-edit { border: 0; background: none; color: var(--muted); border-radius: 8px; padding: 6px 9px; }
.pick-edit:hover { background: var(--panel-2); color: var(--text); }
.own-tag { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.own-tag > summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 4px 0 10px; list-style: none; }
.own-form { display: block; }
.pi-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pi-val { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.w { color: var(--accent); }
.tree-folder > summary { padding: 7px 10px; border-radius: 8px; cursor: pointer; list-style: none; }
.tree-folder > summary::before { content: "▸"; display: inline-block; width: 18px; color: var(--muted); transition: transform .15s; }
.tree-folder[open] > summary::before { transform: rotate(90deg); }
.tree-folder > summary:hover { background: var(--panel-2); }
.tree-children { padding-left: 18px; }
.notice { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--panel-2); border-radius: 8px; }
.notice > div { flex: 1; font-size: 14px; }

/* Verbindungsliste */
.conn-list { display: flex; flex-direction: column; gap: 8px; }
.conn-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel-2); border-radius: 8px; }
.conn-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.conn-info small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.matter-box h4 { margin: 16px 0 8px; }
.matter-pair { display: flex; gap: 8px; }
.matter-pair input { flex: 1; min-width: 0; }

/* Meldungen */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--panel); border-left: 4px solid var(--red); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); transition: opacity .4s; max-width: 360px; }
.toast.info { border-left-color: var(--accent); }
.toast.out { opacity: 0; }

/* ---------- Handy ---------- */
@media (max-width: 700px) {
  .topbar { gap: 8px; padding: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  #btn-connections { font-size: 0; gap: 0; }
  #btn-connections .dot { font-size: 15px; }
  .btn-label { display: none; }
  body.bar-closed #bar-open { padding: 6px 18px; }
  .brand { flex: 1; min-width: 0; }
  .topbar-right { gap: 2px; }
  .settings-menu { max-width: calc(100vw - 16px); }
  .menu-item { padding: 12px 10px; }
  /* Slide-In von links: Elemente einfuegen. Formen und Raster gibt es nur am PC */
  body.editing .palette {
    display: block; position: fixed; top: 0; bottom: 0; left: 0; z-index: 950; width: min(300px, 86vw);
    transform: translateX(-102%); transition: transform .2s ease-out; box-shadow: var(--shadow);
  }
  body.drawer-open .palette { transform: none; }
  body.editing #drawer-close { display: inline-flex; position: absolute; top: 6px; right: 6px; }
  .palette h3:first-of-type { padding: 4px 0 12px; font-size: 16px; }
  .palette .hint, #layer-switch, .palette-sub, #palette-shapes, #grid-levels { display: none !important; }
  #palette-items { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .palette .palette-item { margin: 0; cursor: pointer; }
  body.editing #btn-add { display: inline-flex; position: fixed; left: 12px; bottom: 16px; z-index: 900; box-shadow: var(--shadow); padding: 12px 18px; }
  body.drawer-open #drawer-back { display: block; position: fixed; inset: 0; z-index: 940; background: rgba(10, 15, 25, .45); }
  body.editing .board { padding-bottom: 80px; }

  /* Auch beim Bearbeiten wie spaeter auf dem Handy: Tipp aufs Element statt Ziehen, siehe phoneActions() */
  body.editing .w-head { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; min-height: 40px; padding-top: 4px; }
  body.editing .w-grip { display: inline; color: var(--muted); font-size: 18px; line-height: 1; }
  #grid > .grid-stack-item.phone-dragging { z-index: 800; opacity: .9; transition: none !important; }
  .phone-dragging > .grid-stack-item-content { box-shadow: 0 8px 24px rgba(0, 0, 0, .3); outline: 2px solid var(--accent); }
  body.editing .w-tools button { display: none; }
  body.editing .w-tools .w-more { display: inline-block; padding: 2px 10px; font-size: 16px; font-weight: 700; }
  body.editing .w-tag:not(.always) { display: none; }
  .phone-actions { display: flex; flex-direction: column; gap: 12px; }
  .phone-action { justify-content: flex-start; padding: 12px 14px; }
  .phone-actions .field { margin: 0; }
  .phone-actions .seg button { padding: 10px 4px; }
  .phone-move { display: flex; gap: 8px; }
  .phone-move .btn { flex: 1; justify-content: center; padding: 12px 8px; }

  /* Elemente fortlaufend statt im Raster: schmale Elemente zu zweit nebeneinander, siehe markMobileWidth().
     Formen passen dazu nicht, daher ausblenden */
  .shape-layer { display: none; }
  .grid-stack { height: auto !important; display: flex; flex-wrap: wrap; align-items: flex-start; }
  :is(#grid, #template-grid) > .grid-stack-item {
    position: relative !important; top: auto !important; left: auto !important;
    flex: 1 1 100%; min-width: 0; width: auto !important;
    height: calc(var(--rows, 2) * var(--cell, 80px)) !important; margin-bottom: 0;
  }
  :is(#grid, #template-grid) > .grid-stack-item.m-half { flex-basis: 50%; }
  :is(#grid, #template-grid) > .grid-stack-item.m-third { flex-basis: 33.33%; }
  /* Handy: Vorlage-Elemente stehen oben über denen der Seite */
  .template-layer, #template-grid { position: static; }
  .picker { grid-template-columns: 1fr; }
  .pick-side { border-right: 0; flex-direction: row; overflow-x: auto; padding: 0 0 8px; border-bottom: 1px solid var(--line); }
}

/* Zugriffsschutz */
.access-problem { color: var(--red); min-height: 1.2em; margin: 4px 0; font-size: 13px; }
.access-nudge { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.access-nudge > span { flex: 1; }
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; box-sizing: border-box; overflow: auto; }
.login-box { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
.login-box h1 { display: flex; align-items: center; gap: 10px; font-size: 20px; margin: 0 0 8px; }
.login-box .btn { justify-content: center; }

/* Kamera */
.w-body.w-camera-body { position: relative; padding: 0; overflow: hidden; background: #000; border-radius: 0 0 var(--radius) var(--radius); }
.w-camera-media { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.w-camera-media[hidden] { display: none; }
.w-camera-note { position: absolute; left: 8px; right: 8px; top: 8px; padding: 4px 8px; border-radius: 6px; background: rgba(0, 0, 0, .65); color: #fff; font-size: 13px; text-align: center; }
.w-camera-note[hidden] { display: none; }
.w-camera-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 12px; }
.w-camera-bar .spacer { flex: 1; }
.w-camera-bar .btn { padding: 2px 8px; font-size: 12px; }
.w-camera-player { width: 100%; max-height: 60vh; background: #000; border-radius: 6px; margin-bottom: 8px; }
.w-camera-player[hidden] { display: none; }
.w-camera-bar { flex-wrap: wrap; }
.w-camera-controls { display: flex; align-items: center; gap: 8px; margin: -2px 0 8px; }
.w-camera-controls[hidden] { display: none; }
.w-camera-track { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.w-camera-fill { height: 100%; width: 0; background: var(--accent, #1f6feb); }
.w-camera-clock { font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.w-camera-large { width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: 6px; display: block; }
.w-camera-large[hidden], .w-camera-nav[hidden] { display: none; }
.w-camera-nav { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.w-camera-nav .spacer { flex: 1; }
.w-camera-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.w-camera-thumb { padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; color: inherit; cursor: pointer; overflow: hidden; text-align: center; }
.w-camera-thumb img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: #000; }
.w-camera-thumb small { display: block; padding: 2px 4px; font-size: 11px; }
.w-camera-body { cursor: pointer; }
.w-camera-bar { background: none; pointer-events: none; }
.w-camera-time { padding: 2px 6px; border-radius: 4px; background: rgba(0, 0, 0, .55); }
.w-camera-actions { display: none; gap: 6px; flex-wrap: wrap; justify-content: flex-end; pointer-events: auto; }
.w-camera-open .w-camera-actions, .w-camera-actions:focus-within { display: flex; }
.editing .w-camera-actions { display: none; }
.w-camera-time:empty { display: none; }
.bosch-login [hidden] { display: none; }
.bosch-login ol { margin: 6px 0; padding-left: 20px; }
.bosch-room { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.bosch-room select { min-width: 160px; }
.bosch-weeks { margin-top: 12px; }
.bosch-week { padding: 8px 0; border-top: 1px solid var(--line); }
.bosch-day { display: flex; gap: 10px; margin-top: 4px; font-size: 13px; flex-wrap: wrap; }
.bosch-days { min-width: 58px; font-weight: 600; }
.bosch-slots { display: flex; gap: 6px; flex-wrap: wrap; }
.bosch-slot { padding: 1px 6px; border: 1px solid var(--line); border-radius: 4px; font-variant-numeric: tabular-nums; }
.bosch-edit-day { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.bosch-edit-slot { display: inline-flex; align-items: center; gap: 4px; }
.bosch-edit-slot input[type=number] { width: 62px; }
.bosch-restore { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.bosch-restore[hidden] { display: none; }
.bosch-gas-row { display: grid; grid-template-columns: 90px 1fr 170px; gap: 8px; align-items: center; font-size: 13px; padding: 2px 0; }
.bosch-gas-bar { display: flex; height: 10px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bosch-gas-bar i { display: block; height: 100%; }
.bosch-gas-bar .heat { background: #e0702a; }
.bosch-gas-bar .water { background: var(--accent); }
.bosch-week-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }

/* Wetter und Uhr */
.w-body.w-wx { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 4px; padding: 6px 10px; overflow: hidden; height: 100%; min-height: 0; container-type: size; }
.w-wx-head { display: flex; align-items: center; gap: 10px; flex: none; }
.w-wx-now { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.w-wx-now small, .w-wx-temp small { color: var(--muted); font-size: 11px; }
.w-wx-now small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-wx-temp { display: flex; flex-direction: column; align-items: flex-end; }
.w-wx-temp b { font-size: 22px; line-height: 1.1; }
.w-wx-icon { display: inline-block; width: 22px; height: 22px; background: currentColor; mask-repeat: no-repeat; mask-size: contain; mask-position: center; -webkit-mask-repeat: no-repeat; -webkit-mask-size: contain; -webkit-mask-position: center; flex: none; }
.w-wx-icon.large { width: 34px; height: 34px; }
.w-wx-icon.sunny { background: #f5b301; }
.w-wx-hours { display: flex; justify-content: space-between; }
.w-wx-hour, .w-wx-day { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; }
.w-wx-label { color: var(--muted); font-size: 11px; white-space: nowrap; }
.w-wx-days { display: flex; justify-content: space-between; }
.w-wx-line { width: 100%; height: 26px; flex: none; }
.w-wx-line path { fill: none; stroke: #e0702a; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
/* Niedrige Elemente zeigen weniger, statt abzuschneiden */
@container (max-height: 150px) { .w-wx-line { display: none; } }
@container (max-height: 105px) { .w-wx-hours, .w-wx-days { display: none; } }
.w-body.w-clock { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px; }
.w-clock-time { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.w-clock-date { color: var(--muted); font-size: 13px; }

/* Meldungen */
.w-body.w-messages { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 4px; padding: 6px 10px; overflow: hidden; height: 100%; min-height: 0; }
.w-messages-note { color: var(--muted); font-size: 12px; }
.w-messages-note[hidden] { display: none; }
.w-messages-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; flex: 1; }
.w-msg { display: grid; grid-template-columns: 10px auto minmax(0, 1fr); column-gap: 8px; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.w-msg:last-child { border-bottom: 0; }
.w-msg-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); align-self: center; }
.w-msg.lvl-warn .w-msg-dot { background: #e0a800; }
.w-msg.lvl-alarm .w-msg-dot { background: #d93b3b; }
.w-msg.active.lvl-alarm { background: color-mix(in srgb, #d93b3b 14%, transparent); }
.w-msg.active.lvl-warn { background: color-mix(in srgb, #e0a800 14%, transparent); }
.w-msg.active .w-msg-text { font-weight: 600; }
.w-msg-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.w-msg-text { overflow-wrap: anywhere; }
.w-msg-extra { grid-column: 3; color: var(--muted); font-size: 11px; }
.w-msg.unacked { box-shadow: inset 3px 0 0 #d93b3b; padding-left: 8px; }
.w-msg.unacked.lvl-warn { box-shadow: inset 3px 0 0 #e0a800; }
.w-msg.unacked.lvl-info { box-shadow: inset 3px 0 0 var(--accent); }
.w-msg.unacked .w-msg-text { font-weight: 600; }
.w-msg > .w-msg-ack { grid-column: 3; justify-self: start; margin-top: 3px; }
.w-msg-ack { padding: 3px 10px; font-size: 12px; }
.w-messages-ackbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600; }
.w-messages-ackbar[hidden] { display: none; }
.msg-rules { display: flex; flex-direction: column; gap: 8px; }
.msg-rule { display: flex; flex-direction: column; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; }
.msg-rule-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.msg-rule-tag { flex: 1 1 120px; font-weight: 600; overflow-wrap: anywhere; }
.field .msg-rule-line select { width: auto; flex: 0 1 auto; padding: 6px 8px; }
.field .msg-rule-line input.msg-rule-value { width: 90px; flex: 0 0 90px; padding: 6px 8px; }
.field .msg-rule-line input.msg-rule-value[hidden] { display: none; }
.field .msg-rule-line input.msg-rule-text { width: auto; flex: 1 1 180px; min-width: 0; padding: 6px 8px; }
.msg-rule-push { display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; font-size: 13px; }
.field .msg-rule-push input { width: auto; padding: 0; }
.push-actions { flex-wrap: wrap; justify-content: flex-start; }
.push-actions [hidden] { display: none; }
.push-levels { display: flex; gap: 14px; flex-wrap: wrap; }
.push-level { display: inline-flex; gap: 6px; align-items: center; }
.field .push-level input { width: auto; padding: 0; }
.msg-rule-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* Nachrichten */
.w-body.w-news { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 4px; padding: 6px 10px; overflow: hidden; height: 100%; min-height: 0; }
.w-news-note { color: var(--muted); font-size: 12px; }
.w-news-note[hidden] { display: none; }
.w-news-list { overflow-y: auto; min-height: 0; flex: 1; }
.w-news-item { padding: 6px 0; border-bottom: 1px solid var(--line); }
.w-news-item:last-child { border-bottom: 0; }
.w-news-meta { display: block; color: var(--muted); font-size: 11px; }
.w-news-title { font-size: 14px; font-weight: 600; color: inherit; text-decoration: none; }
a.w-news-title:hover { text-decoration: underline; }
.w-news-summary { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.w-news-ticker { overflow: hidden; flex: 1; display: flex; align-items: center; }
.w-news-run { display: flex; gap: 14px; white-space: nowrap; width: max-content; animation: w-news-run linear infinite; padding-left: 100%; }
.w-news-ticker:hover .w-news-run { animation-play-state: paused; }
.w-news-gap { color: var(--muted); }
@keyframes w-news-run { to { transform: translateX(-100%); } }
@media (prefers-reduced-motion: reduce) { .w-news-run { animation: none; padding-left: 0; } .w-news-ticker { overflow-x: auto; } }
.w-news-item.with-image { display: flex; gap: 10px; align-items: flex-start; }
.w-news-image { width: 92px; height: 62px; object-fit: cover; border-radius: 4px; flex: none; background: var(--line); }
.w-news-text { min-width: 0; flex: 1; }

/* Rollen: Wer nicht verwalten darf, sieht die Werkzeuge dazu nicht (der Server lehnt es ohnehin ab) */
body:is(.role-operator, .role-viewer) :is(#btn-edit, #btn-connections, #btn-add, .brand-edit, .auto-tab, .admin-only) { display: none !important; }
body:is(.role-operator, .role-viewer) #brand { cursor: default; }
/* Nur ansehen: Bedienelemente sehen nicht klickbar aus, Kamera-Knöpfe bleiben */
body.role-viewer .grid-stack-item-content .w-body:not(.w-camera-body) :is(button, input, select, label, .w-switch):not(.navigates) { cursor: not-allowed; }
/* Schieber lassen sich gar nicht erst greifen (sonst wandern sie bis zur Ablehnung mit); das Verbotszeichen zeigt die Umgebung */
body.role-viewer .grid-stack-item-content .w-body:not(.w-camera-body) input[type=range] { pointer-events: none; }
body.role-viewer .grid-stack-item-content .w-body:not(.w-camera-body) :has(> input[type=range]) { cursor: not-allowed; }
/* Bedienfeld der Lampe: ansehen ja, verstellen nein */
body.role-viewer .lamp-panel { cursor: not-allowed; }
body.role-viewer .lamp-panel :is(input, button, .lamp-wheel) { pointer-events: none; }
.users-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 12px; }
.user-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-row b { flex: 1 1 120px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.user-row select { width: auto; }
.user-add { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.user-add .field { margin: 0; }
@media (max-width: 700px) { .user-add { grid-template-columns: 1fr; } }

a.btn { text-decoration: none; color: inherit; }

/* PLCPrimeDashboard als Matter-Gerät (Brücke für Alexa, Apple Home, Google Home) */
.bridge-head { margin: 20px 0 8px; }
.bridge-status { margin: 4px 0 12px; }
.bridge-status .dlg-actions { flex-wrap: wrap; justify-content: flex-start; }
.bridge-error { color: var(--red); }
.bridge-pair { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; background: var(--panel-2); border-radius: 8px; padding: 12px; margin: 8px 0; }
.bridge-pair p { margin: 0 0 6px; }
.bridge-pair ol { margin: 6px 0; padding-left: 18px; }
.bridge-qr { width: 168px; height: 168px; flex: none; border-radius: 6px; background: #fff; }
.bridge-code { font: 600 22px/1.2 ui-monospace, Consolas, monospace; letter-spacing: 1px; user-select: all; }
.bridge-devices { display: flex; flex-direction: column; gap: 10px; }
.bridge-device { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.bridge-device-head { display: flex; gap: 8px; align-items: center; }
.bridge-device-head input { flex: 1 1 auto; min-width: 0; }
.bridge-device-head select { flex: 0 1 190px; min-width: 0; }
.bridge-role { display: flex; flex-direction: column; gap: 4px; }
.bridge-role .tag-line { display: flex; gap: 6px; align-items: center; }
.bridge-tag { flex: 1 1 auto; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bridge-device .check { margin: 0; }
@media (max-width: 520px) {
  .bridge-device-head { flex-wrap: wrap; }
  .bridge-device-head select { flex: 1 1 100%; order: 3; }
  .bridge-qr { width: 140px; height: 140px; }
}

/* Verschlüsselung im Dialog Zugriffsschutz */
.https-box { margin-top: 8px; }
.https-fp, .https-names { overflow-wrap: anywhere; word-break: break-all; }
.https-ca .btn { display: inline-block; margin: 4px 0; text-decoration: none; }


/* Energiefluss */
:root { --ef-solar: #f08c00; --ef-grid: #3b82f6; --ef-battery: #e64980; --ef-home: #2f9e44; }
.w-energy { display: flex; align-items: center; justify-content: center; min-height: 0; }
.energy-svg { width: 100%; height: 100%; max-height: 100%; overflow: visible; }
.energy-empty { padding: 12px; color: var(--muted); text-align: center; font-size: 0.9em; }
.ef-solar { --c: var(--ef-solar); }
.ef-grid { --c: var(--ef-grid); }
.ef-battery { --c: var(--ef-battery); }
.ef-home { --c: var(--ef-home); }
.ef-line { fill: none; stroke: var(--c); stroke-width: 2; opacity: 0.22; }
.ef-dots { fill: none; stroke: var(--c); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 0 14; opacity: 0; transition: opacity 0.4s; }
.ef-dots.on { opacity: 1; animation: ef-move var(--ef-dur, 2s) linear infinite; }
@keyframes ef-move { to { stroke-dashoffset: -140; } }
.ef-ring { fill: var(--panel, transparent); stroke: var(--c); stroke-width: 3; }
.w-transparent .ef-ring { fill: transparent; }
.ef-ring.with-level { stroke-opacity: 0.25; }
.ef-level { fill: none; stroke: var(--c); stroke-width: 4; transition: stroke-dasharray 0.6s; }
.ef-reserve-mark { stroke: var(--text); stroke-width: 2.5; stroke-linecap: round; }
.ef-reserve-mark[hidden] { display: none; }
.ef-battery.ef-low { --c: #e8590c; }
.ef-battery.ef-low .ef-label { fill: #e8590c; font-weight: 600; }
.ef-icon { fill: none; stroke: var(--c); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ef-value { font-size: 12.5px; font-weight: 600; fill: var(--text); }
.ef-label { font-size: 12px; fill: var(--muted); }
@media (prefers-reduced-motion: reduce) { .ef-dots.on { animation: none; opacity: 0.8; } }
/* Mehrere Datenpunkte mit Rolle (Einstellungen, z.B. Energiefluss) */
.tag-roles { display: flex; flex-direction: column; gap: 6px; }
.tag-role { display: grid; grid-template-columns: minmax(110px, 1fr) minmax(0, 1.4fr) auto auto; gap: 8px; align-items: center; }
.tag-role-name { font-size: 0.9em; }
.tag-role-tag { color: var(--muted); font-size: 0.85em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 520px) { .tag-role { grid-template-columns: 1fr auto auto; } .tag-role-tag { grid-column: 1 / -1; grid-row: 2; } }
/* Netatmo-Anmeldung */
.netatmo-steps { margin: 4px 0 10px; padding-left: 20px; font-size: 0.9em; }
.netatmo-steps li { margin: 3px 0; }
.netatmo-uri { overflow-wrap: anywhere; word-break: break-all; user-select: all; }
/* Bewegte Motive (Foto-Element, Hintergrund) */
.motion-bg { position: relative; width: 100%; height: 100%; min-height: 0; overflow: hidden; border-radius: inherit; flex: 1 1 auto; }
.motion-bg canvas { display: block; position: absolute; inset: 0; }
.w-image-body:has(.motion-bg) { padding: 0; }
/* Deckkraft des Elementhintergrunds (Einstellungen → Farben) */
.grid-stack-item-content.w-translucent { border-color: color-mix(in srgb, var(--line) var(--w-op, 100%), transparent); box-shadow: none; }
.grid-stack-item-content.w-glass { -webkit-backdrop-filter: blur(8px) saturate(1.15); backdrop-filter: blur(8px) saturate(1.15); }
body.editing .grid-stack-item-content.w-translucent { border: 1px dashed var(--line); }
/* Fernzugriff */
.remote-status { font-weight: 600; margin: 4px 0 12px; }
.remote-status.ok { color: var(--green); }
.remote-status.bad { color: var(--red); }
.remote-link { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.remote-link a { word-break: break-all; color: var(--accent); }
.remote-warn { color: var(--yellow); }
.remote-advanced > summary { cursor: pointer; margin-bottom: 8px; color: var(--muted); }
/* Fernzugriff: plcprime.io-Konto */
.remote-account { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 4px 0 12px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.remote-account[hidden] { display: none; }
.remote-account-head { font-weight: 600; }
.remote-code { font-size: 28px; font-weight: 700; letter-spacing: .12em; font-family: ui-monospace, Consolas, monospace; }
