:root {
  --chart-line: #2a7fd4;
  --bg: #f3f6f5; --card: #ffffff; --text: #17242a; --muted: #62737a; --line: #dfe7e6;
  --accent: #0e8a7e; --accent-soft: #d8f1ed; --water: #2a7fd4; --water-soft: #ddebfa;
  --danger: #c8372d; --warn: #b87708; --ok: #1f9d55;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --chart-line: #4a95e3;
    --bg: #0f1a1f; --card: #172429; --text: #e5eeee; --muted: #8fa3a8; --line: #26383e;
    --accent: #2bb8a8; --accent-soft: #143a37; --water: #5aa7f0; --water-soft: #16304a;
    --danger: #ef5b4f; --warn: #e6a43a; --ok: #3cc277; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; margin: 0; }
h1 { margin: 0 0 4px; } h2 { font-size: 16px; margin: 22px 0 10px; }

/* Kopf + Navigation */
.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; }
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.dot.ok { background: var(--ok); } .dot.wait { background: var(--warn); }
.tabs { display: flex; gap: 4px; padding: 8px 12px; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); }
.tabs button { flex: 0 0 auto; border: 0; background: none; color: var(--muted); padding: 8px 12px; border-radius: 10px; font: inherit; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
@media (max-width: 700px) {
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; justify-content: space-around; border-top: 1px solid var(--line); border-bottom: 0; padding: 6px 2px calc(6px + env(safe-area-inset-bottom)); }
  .tabs button { flex-direction: column; gap: 0; font-size: 10px; padding: 4px 3px; }
  .tabs button span { font-size: 19px; }
  main { padding-bottom: 90px !important; }
}
main { max-width: 1000px; margin: 0 auto; padding: 16px; }

/* Bausteine */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 10px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.bar { display: flex; justify-content: space-between; align-items: center; }
.empty { color: var(--muted); padding: 14px; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.water { background: var(--water); border-color: var(--water); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: none; color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.right { margin-left: auto; }

/* Zonen */
.zone { display: flex; flex-direction: column; gap: 10px; }
.zone .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.zone .name { font-weight: 600; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--line); color: var(--muted); white-space: nowrap; }
.pill.on { background: var(--water-soft); color: var(--water); font-weight: 600; }
.pill.off { opacity: .8; }
.zone.on { border-color: var(--water); }
.zone .ctrl { display: flex; gap: 6px; align-items: center; }
.zone .ctrl input { width: 64px; }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.qbtn { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: var(--radius); padding: 16px 10px; font: inherit; font-weight: 600; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: var(--shadow); }
.qbtn span { font-size: 32px; }
.qbtn:active { transform: scale(.96); background: var(--accent-soft); }
.qbtn.busy { opacity: .6; }
.linkbox { display: flex; gap: 6px; }
.linkbox input { flex: 1; font-size: 12px; font-family: ui-monospace, monospace; }
.sensor .val { font-size: 26px; font-weight: 700; }
.sensor .unit { font-size: 14px; color: var(--muted); font-weight: 500; }

.run { border-color: var(--water); margin-top: 12px; }
.progress { height: 6px; background: var(--water-soft); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--water); transition: width 1s linear; }

.item { display: flex; align-items: center; gap: 12px; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.item.disabled { opacity: .55; }

/* Formulare */
.form { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .two { grid-template-columns: 1fr; } }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; }
.row-form input { flex: 1 1 160px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { flex-direction: row; }
.days input { display: none; }
.days span { display: inline-block; width: 38px; text-align: center; padding: 7px 0; border-radius: 9px; border: 1px solid var(--line); cursor: pointer; color: var(--text); }
.days input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.rowline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rowline > * { flex: 1 1 90px; }
.rowline .x { flex: 0 0 auto; }
.fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.fieldset > .lbl { font-size: 13px; color: var(--muted); font-weight: 600; }

dialog { border: 0; border-radius: 18px; padding: 18px; width: min(560px, 94vw); max-height: 90vh; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin-top: 0; }
#dlgBody { display: flex; flex-direction: column; gap: 10px; }

.log { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); max-height: 380px; overflow: auto; font-size: 13px; }
.log div { padding: 6px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.log time { color: var(--muted); flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.log .fehler { color: var(--danger); } .log .warnung { color: var(--warn); }
.log .zeitplan { color: var(--water); } .log .regel { color: var(--accent); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; margin-top: 8px; }
.mono b { color: var(--accent); font-weight: 600; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card label { text-align: left; }
.logo { font-size: 44px; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* Tank-Balken */
.sensor { position: relative; }
.tank { position: absolute; right: 14px; top: 14px; bottom: 14px; width: 34px; border: 2px solid var(--water); border-radius: 8px; overflow: hidden; background: var(--water-soft); }
.tank > div { position: absolute; left: 0; right: 0; bottom: 0; background: var(--water); transition: height .6s; }
.tank > span { position: absolute; inset: auto 0 2px; text-align: center; font-size: 10px; font-weight: 700; color: #fff; mix-blend-mode: difference; }
.tank.warn { border-color: var(--danger); } .tank.warn > div { background: var(--danger); }

/* ---------- Ablauf-Editor ---------- */
.fe { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; }
.fe-top { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--card); border-bottom: 1px solid var(--line); }
.fe-name { flex: 1; font-weight: 600; }
.fe-en { white-space: nowrap; }
.fe-body { flex: 1; display: flex; min-height: 0; position: relative; }
.fe-pal { width: 190px; overflow-y: auto; background: var(--card); border-right: 1px solid var(--line); padding: 8px; }
.pcat { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 4px 4px; font-weight: 700; }
.pnode { display: flex; gap: 8px; align-items: center; padding: 7px 9px; margin: 4px 0; border-radius: 9px; border: 1px solid var(--line); border-left: 4px solid var(--c); cursor: grab; font-size: 13px; background: var(--bg); user-select: none; }
.pnode:active { cursor: grabbing; }
.fe-canvas { flex: 1; position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 20px 20px; }
.fe-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.fe-wires { position: absolute; left: 0; top: 0; overflow: visible; }
.wire { fill: none; stroke: var(--muted); stroke-width: 2.5; pointer-events: none; }
.wire.alt { stroke-dasharray: 6 4; }
.wire.sel { stroke: var(--danger); stroke-width: 3.5; }
.wire.temp { stroke: var(--accent); stroke-dasharray: 5 5; }
.wire-hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; }
.fnode { position: absolute; width: 170px; height: 70px; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12); cursor: move; font-size: 12px; }
.fnode.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.fnode.target { outline: 2px dashed var(--accent); }
.fhead { display: flex; gap: 6px; align-items: center; padding: 3px 8px 0; height: 22px; }
.fhead b { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fsum, .fstat { padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; height: 18px; line-height: 18px; color: var(--muted); }
.fstat { font-size: 11px; display: flex; align-items: center; gap: 5px; }
.fstat .dot { width: 7px; height: 7px; flex: 0 0 auto; }
.dot.green { background: var(--ok); } .dot.yellow { background: var(--warn); } .dot.blue { background: var(--water); } .dot.grey { background: var(--muted); } .dot.red { background: var(--danger); }
.finject { border: 0; background: var(--accent); color: #fff; border-radius: 6px; padding: 1px 7px; font-size: 11px; cursor: pointer; }
.port { position: absolute; width: 16px; height: 16px; border-radius: 50%; background: var(--card); border: 2px solid var(--c); top: calc(50% - 8px); }
.port.in { left: -9px; }
.port.out { right: -9px; margin-top: -8px; cursor: crosshair; }
.port.out::after { content: ''; position: absolute; inset: -10px; } /* größere Trefferfläche für Finger */
.port.out.active { background: var(--accent); }
.port em { position: absolute; left: 18px; top: -1px; font-style: normal; font-size: 10px; color: var(--muted); white-space: nowrap; pointer-events: none; }
.fe-hint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); font-size: 13px; color: var(--muted); background: var(--card); border-radius: 8px; padding: 0 10px; pointer-events: none; max-width: 90%; text-align: center; }
.fe-hint:empty { display: none; }
.fe-ctrl { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; gap: 6px; align-items: center; pointer-events: none; }
.fe-ctrl > *, .fe-ctrl button { pointer-events: auto; }
.fe-ctrl span { display: flex; gap: 6px; }
.fe-debug { background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.fe-dbar { display: flex; padding: 6px 10px; }
.fe-debug .log { display: none; max-height: 30vh; border-radius: 0; border: 0; border-top: 1px solid var(--line); margin: 0; }
.fe-debug.open .log { display: block; }
#feSave.pulse { box-shadow: 0 0 0 3px var(--accent-soft); }
@media (max-width: 800px) {
  .fe-pal { position: absolute; z-index: 5; left: 0; top: 0; bottom: 0; width: 230px; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .fe-pal.open { transform: none; }
  .fe-en { font-size: 12px; }
}
@media (min-width: 801px) { #feAdd { display: none; } }

/* Kategorien */
.catbar { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.catbar::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: 99px; padding: 6px 13px; font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--cc); border-color: var(--cc); color: #fff; font-weight: 600; }
.chip.ghost { background: none; }
.cathead { display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: 15px; margin: 20px 0 10px; padding: 2px 0 2px 10px; border-left: 4px solid var(--cc); }
.cathead span { font-size: 18px; }
.list > .cathead:first-child, #dash > .catgroup:first-child .cathead { margin-top: 14px; }
.fe-cat { max-width: 130px; }
@media (max-width: 520px) { .fe-cat { max-width: 90px; font-size: 13px; padding: 6px; } }
.zone select.dur { flex: 1; min-width: 0; }

/* Verlauf */
.sensor.clickable { cursor: pointer; }
.sensor.clickable:hover { border-color: var(--chart-line); }
.sensor.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hist-ico { font-size: 11px; opacity: .7; }
.spark { display: block; width: 100%; height: 26px; margin: 6px 0 2px; overflow: visible; }
.spark.with-bar { width: calc(100% - 46px); }
.spark path { fill: none; stroke: var(--chart-line); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.hist-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.hist-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.hstat { background: var(--bg); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; }
.hstat b { font-size: 17px; font-variant-numeric: tabular-nums; }
.hstat span { font-size: 12px; color: var(--muted); }
@media (max-width: 480px) { .hist-stats { grid-template-columns: repeat(2, 1fr); } }
.hist-chart { position: relative; transition: opacity .2s; min-height: 230px; }
.hchart { display: block; touch-action: pan-y; }
.hchart .grid { stroke: var(--line); stroke-width: 1; }
.hchart .baseline { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.hchart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.hchart .line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.hchart .band { fill: var(--chart-line); opacity: .14; }
.hchart .pt { fill: var(--chart-line); }
.hchart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.hchart .dot { fill: var(--chart-line); stroke: var(--card); stroke-width: 2; }
.hchart .hit:focus { outline: none; }
.htip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.15); font-size: 12px; white-space: nowrap; }
.htip b { font-size: 15px; font-variant-numeric: tabular-nums; }
.hist-table summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.hist-table > div { max-height: 240px; overflow: auto; margin-top: 6px; }
.hist-table table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.hist-table th, .hist-table td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.hist-table th:first-child, .hist-table td:first-child { text-align: left; }
