:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --line: #dfe2e7;
  --text: #15171c;
  --muted: #6b7180;
  --accent: #e8913a;
  --accent-2: #ffb46b;
  --on: #f5b942;
  --ok: #2fa36b;
  --bad: #d64545;
  --then: #2f7de1;
  --else: #9257d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #181b21;
    --panel-2: #20242c;
    --line: #2b3039;
    --text: #eceef2;
    --muted: #8c93a3;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  display: flex; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Navigation ---------- */
#nav {
  width: 220px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 10px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 18px; }
.brand img { width: 30px; height: 30px; }
#tabs { display: flex; flex-direction: column; gap: 2px; flex: 1; }
#tabs a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--text); text-decoration: none;
}
#tabs a .ic { width: 20px; text-align: center; opacity: .8; }
#tabs a.active { background: var(--panel-2); font-weight: 600; }
#tabs a.active .ic { color: var(--accent); opacity: 1; }
#tabs .section { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 6px; }
#tabs a.back { color: var(--muted); }
.conn { font-size: 12px; color: var(--muted); padding: 8px 12px; }
.conn.ok::before { content: "● "; color: var(--ok); }
.conn.bad::before { content: "● "; color: var(--bad); }

main { flex: 1; min-width: 0; padding: 28px 32px 120px; max-width: 1200px; }
h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 28px 0 10px; }
h3 { font-size: 15px; margin: 0; }
.sub { color: var(--muted); margin: 0 0 20px; }
.head { display: flex; align-items: flex-end; gap: 12px; justify-content: space-between; flex-wrap: wrap; margin-bottom: 18px; }
.head .sub { margin: 0; }

@media (max-width: 760px) {
  body { flex-direction: column; }
  #nav {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; width: auto; height: auto; z-index: 20;
    flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line);
    overflow-x: auto;
  }
  .brand, .conn { display: none; }
  #tabs .section { display: none; }
  body[data-service="start"] #nav { display: none; }
  #tabs { flex-direction: row; gap: 0; }
  #tabs a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 9px; min-width: 62px; }
  #tabs a .ic { font-size: 18px; }
  main { padding: calc(16px + env(safe-area-inset-top)) 16px 110px; }
  h1 { font-size: 24px; }
}

/* ---------- Startseite (Dienste) ---------- */
.services { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.svc {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px; min-height: 160px;
  display: flex; flex-direction: column; gap: 8px; color: var(--text); text-decoration: none; box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.svc:hover { border-color: var(--accent); }
.svc:active { transform: scale(.98); }
.svc .ico { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); font-size: 22px; }
.svc .name { font-weight: 700; font-size: 20px; margin-top: auto; }
.svc.soon { opacity: .6; }
.svc-frame { width: 100%; height: calc(100dvh - 150px); border: 0; border-radius: 12px; background: #0d1012; }
@media (max-width: 760px) { .svc-frame { height: calc(100dvh - 200px - env(safe-area-inset-bottom)); } }

/* ---------- Bausteine ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 10px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.item .t { font-weight: 600; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.pill.on { background: color-mix(in srgb, var(--on) 22%, transparent); color: #a8700a; }
@media (prefers-color-scheme: dark) { .pill.on { color: var(--on); } }
.empty { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f > span { font-weight: 500; }
input[type=text], input[type=number], input[type=password], input[type=time], input[type=date], select, textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; min-width: 0; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 0; }
textarea { width: 100%; min-height: 240px; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* Schalter */
.sw { position: relative; width: 44px; height: 26px; flex: none; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; cursor: pointer; }
.sw span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.sw input:checked + span { background: var(--ok); }
.sw input:checked + span::after { transform: translateX(18px); }

/* ---------- Übersicht ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 7px 14px; cursor: pointer; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px; min-height: 120px; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; user-select: none; position: relative; overflow: hidden; transition: background .2s;
}
.tile .ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); font-size: 17px; }
.tile.on { background: #fff8ea; border-color: #f2d9a4; }
@media (prefers-color-scheme: dark) { .tile.on { background: #2c2617; border-color: #5a4a22; } }
.tile .name { font-weight: 600; margin-top: auto; line-height: 1.2; }
.tile .tval { font-size: 13px; color: var(--muted); }
.tile .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--on); transition: width .15s; }
.tile .fade-dot { position: absolute; top: 12px; right: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .2; } }

/* Sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet.hidden { display: none; }
.sheet-body { background: var(--panel); border-radius: 20px; padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
@media (max-width: 760px) {
  .sheet { align-items: flex-end; padding: 0; }
  .sheet-body { border-radius: 20px 20px 0 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}
.slider { width: 100%; accent-color: var(--accent); }
.big-slider { -webkit-appearance: none; appearance: none; width: 100%; height: 46px; border-radius: 14px; background: var(--panel-2); overflow: hidden; }
.big-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 4px; height: 46px; background: #fff; box-shadow: -600px 0 0 600px var(--on); }
.hue-slider { background: linear-gradient(90deg, red, #ff0, lime, cyan, blue, #f0f, red); }
.hue-slider::-webkit-slider-thumb { box-shadow: none; width: 8px; border: 2px solid #fff; background: transparent; }
.ct-slider { background: linear-gradient(90deg, #cfe3ff, #fff, #ffd9a0, #ffa94d); }
.ct-slider::-webkit-slider-thumb { box-shadow: none; width: 8px; border: 2px solid #333; background: transparent; }
.sat-slider::-webkit-slider-thumb { box-shadow: none; width: 8px; border: 2px solid #fff; background: transparent; }

/* ---------- Regel-Editor ---------- */
.block { border-radius: var(--radius); padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); background: var(--panel); }
.block > .lbl { font-size: 12px; font-weight: 800; letter-spacing: .08em; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.block.when > .lbl { color: var(--accent); }
.block.if > .lbl { color: var(--ok); }
.block.then > .lbl { color: var(--then); }
.block.else > .lbl { color: var(--else); }
.block.when { border-left: 4px solid var(--accent); }
.block.if { border-left: 4px solid var(--ok); }
.block.then { border-left: 4px solid var(--then); }
.block.else { border-left: 4px solid var(--else); }
.ed-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 8px; border-radius: 10px; background: var(--panel-2); margin-bottom: 6px; }
.ed-row > select:first-child { font-weight: 600; }
.ed-row .x { margin-left: auto; }
.ed-group { border: 1px dashed var(--line); border-radius: 12px; padding: 8px; margin-bottom: 6px; }
.ed-group .ed-row { background: var(--panel); }
.nested { width: 100%; padding-left: 14px; border-left: 2px solid var(--line); margin: 4px 0 2px; }
.nested .tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--muted); margin: 6px 0 4px; }
.ed-row input[type=number] { width: 84px; }
.ed-row input.tm { width: 110px; }
.vals { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.val { display: flex; align-items: center; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px 6px; }
.val.off { opacity: .45; }
.days { display: inline-flex; gap: 2px; }
.days button { width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 12px; padding: 0; }
.days button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.live { font-size: 12px; }

/* Profile */
.curve { width: 100%; height: 160px; background: var(--panel-2); border-radius: 12px; }
.curve path { fill: none; stroke: var(--accent); stroke-width: 2; }
.curve .now { stroke: var(--then); stroke-dasharray: 3 3; }
.curve text { fill: var(--muted); font-size: 10px; }

/* DMX-Monitor */
.dmx { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 3px; }
.dmx div { font: 10px ui-monospace, monospace; text-align: center; padding: 3px 0; border-radius: 4px; background: var(--panel-2); position: relative; overflow: hidden; }
.dmx div i { position: absolute; left: 0; bottom: 0; right: 0; background: color-mix(in srgb, var(--accent) 45%, transparent); }
.dmx div b { position: relative; font-weight: 500; }

/* Log */
.log { font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.log div { padding: 2px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.log .ts { color: var(--muted); flex: none; }
.log .warn { color: #c98a14; }
.log .error { color: var(--bad); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; background: #222; color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 60; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.toast.hidden { display: none; }
.qr svg { width: 220px; height: 220px; border-radius: 12px; }
.pin { font: 700 28px ui-monospace, monospace; letter-spacing: .08em; }
.tile .more { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; padding: 2px 8px; border-radius: 8px; }
.tile .more:hover { background: var(--panel-2); }

/* Patch */
.banner { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 40; background: var(--bad); color: #fff;
  padding: 8px 16px; border-radius: 99px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-weight: 600; }
.banner a { color: #fff; text-decoration: none; }
.banner.hidden { display: none; }
@media (max-width: 760px) { .banner { top: calc(8px + env(safe-area-inset-top)); width: max-content; max-width: 92vw; } }
table.patch { width: 100%; border-collapse: collapse; font-size: 14px; }
table.patch th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); }
table.patch td { padding: 9px 14px; border-bottom: 1px solid var(--line); }
table.patch tr:last-child td { border-bottom: 0; }
