:root {
  --bg: #161616;
  --surface: #262626;
  --surface-2: #1d1d1d;
  --line: #393939;
  --line-2: #525252;
  --ink: #f4f4f4;
  --muted: #a8a8a8;
  --accent: #f1c21b;
  --danger: #da1e28;
  --danger-ink: #ff8389;
  --ok: #42be65;
  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font-body);
  padding: 0 clamp(16px, 3vw, 40px) 40px;
  max-width: 1600px;
  margin-inline: auto;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: #fddc69; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 16px; top: -60px; background: var(--accent); color: #161616; padding: 8px 12px; border-radius: 6px; z-index: 10; font-weight: 600; }
.skip:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  display: flex; gap: 24px; justify-content: space-between; align-items: flex-start;
  padding-block: 32px 24px;
}
.top-text { max-width: 820px; }
.eyebrow { font: 500 12px/1.4 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin: 0 0 10px; }
h1 { font: 700 clamp(28px, 4vw, 44px)/1.05 var(--font-display); letter-spacing: -.02em; margin: 0 0 14px; }
.lede { color: #c6c6c6; margin: 0 0 14px; max-width: 70ch; }
.lede strong { color: var(--accent); }
.honesty {
  margin: 0 0 14px; padding: 10px 14px; border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 0 8px 8px 0; color: var(--ink); font-size: 14px; max-width: 72ch;
}
.links { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 0; font-weight: 500; font-size: 14px; }
.top-status { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; flex-shrink: 0; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font: 500 13px var(--font-mono);
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(66,190,101,.2); }
body.alarm .status-pill { background: var(--danger); border-color: var(--danger); color: #fff; }
body.alarm .status-pill .dot { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.3); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 14px/1 var(--font-body); color: var(--ink); background: transparent;
  border: 1px solid var(--line-2); border-radius: 8px; padding: 11px 14px; min-height: 42px; cursor: pointer;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { background: #333; border-color: #6f6f6f; }
.btn.primary { background: var(--accent); color: #161616; border-color: var(--accent); }
.btn.primary:hover { background: #fddc69; }
.btn.ghost { background: var(--surface); border-color: var(--line); }
.btn.small { min-height: 34px; padding: 7px 12px; font-size: 13px; }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
#soundMute { display: inline; }
#soundWaves { display: none; }
.btn[aria-pressed="true"] #soundMute { display: none; }
.btn[aria-pressed="true"] #soundWaves { display: inline; }
.btn.active { border-color: var(--accent); color: var(--accent); }

/* ---------- language switch ---------- */
html.lang-pending body { visibility: hidden; }
.lang-switch { display: inline-flex; align-items: center; font: 500 13px/1 var(--font-mono); color: var(--muted); }
.lang-switch button {
  font: inherit; color: inherit; background: transparent; border: 0; border-radius: 4px;
  padding: 8px 6px; min-width: 32px; min-height: 32px; cursor: pointer; letter-spacing: .04em;
}
.lang-switch button:hover { color: var(--ink); }
.lang-switch button[aria-pressed="true"] { color: var(--ink); font-weight: 700; text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; text-decoration-color: var(--accent); }
.lang-sep { color: var(--line-2); }

/* ---------- grid ---------- */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: minmax(300px, 340px) minmax(0, 1fr) minmax(300px, 330px);
  grid-template-areas: "sensor flow app" "sensor log log";
  align-items: start;
}
.sensor { grid-area: sensor; }
.flow { grid-area: flow; }
.app { grid-area: app; }
.log { grid-area: log; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.panel-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.step { font: 700 12px/1 var(--font-mono); color: #161616; background: var(--accent); border-radius: 4px; padding: 5px 6px; margin-top: 3px; }
h2 { font: 600 19px/1.2 var(--font-display); margin: 0; letter-spacing: -.01em; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.label { font-size: 13px; color: var(--muted); }
.hint { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }

/* ---------- LCD ---------- */
.lcd {
  background: #1b1a12; border: 6px solid #0e3b1e; border-radius: 6px; padding: 10px 12px;
  box-shadow: inset 0 0 0 1px #000, 0 0 0 1px #2a5a34;
}
.lcd-row { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; }
.lcd-row + .lcd-row { margin-top: 3px; }
#lcdNote { margin-top: 6px; }
.lcd-row span {
  font: 600 17px/1.35 var(--font-mono); color: var(--accent); text-align: center;
  background: rgba(241,194,27,.06); border-radius: 1px; min-width: 0;
}

/* ---------- actuators ---------- */
.outputs { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.out {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 6px 8px;
  display: grid; justify-items: center; gap: 2px; text-align: center;
}
.out svg { width: 42px; height: 42px; margin-bottom: 2px; }
.out-name { font-size: 13px; font-weight: 600; }
.pin { font: 500 11px var(--font-mono); color: var(--muted); }
.state { font: 700 11px var(--font-mono); color: var(--muted); letter-spacing: .04em; }
.out.on { border-color: var(--danger); }
.out.on .state { color: var(--danger-ink); }
#outFan.on { border-color: var(--accent); }
#outFan.on .state { color: var(--accent); }

.led-glow { fill: var(--danger); opacity: 0; transition: opacity .2s; }
.led-body { fill: #5a2326; transition: fill .2s; }
.led-base { fill: #6f6f6f; }
#outLed.on .led-glow { opacity: .35; }
#outLed.on .led-body { fill: #ff4d57; }

.buzz-body { fill: #393939; stroke: #6f6f6f; }
.wave { fill: none; stroke: var(--danger-ink); stroke-width: 2.4; stroke-linecap: round; opacity: 0; }
#outBuzz.on .wave { opacity: 1; animation: blink .8s steps(1) infinite; }
#outBuzz.on .w2 { animation-delay: .1s; }
@keyframes blink { 50% { opacity: .15; } }

.fan-ring { fill: #1d1d1d; stroke: #6f6f6f; stroke-width: 2; }
.fan-blades path { fill: #8d8d8d; transition: fill .2s; }
.fan-hub { fill: #c6c6c6; }
.fan-blades { transform-origin: 20px 20px; transform-box: view-box; }
#outFan.on .fan-blades path { fill: var(--accent); }
#outFan.on .fan-blades { animation: spin .45s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- gas reading ---------- */
.reading { margin-top: 16px; }
.reading-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.reading-val { font-size: 30px; font-weight: 700; line-height: 1; transition: color .2s; }
body.alarm .reading-val { color: var(--danger-ink); }
.meter { position: relative; height: 10px; border-radius: 5px; background: #1d1d1d; border: 1px solid var(--line); margin-top: 10px; overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 14%; background: var(--accent); border-radius: 5px 0 0 5px; }
body.alarm .meter-fill { background: var(--danger); }
.tick { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }
.t300 { left: calc(300 / 1023 * 100%); }
.t700 { left: calc(700 / 1023 * 100%); background: var(--muted); }
.meter-legend { position: relative; height: 16px; font-size: 10.5px; color: var(--muted); margin-top: 4px; }
.meter-legend span { position: absolute; white-space: nowrap; }
.lg300 { left: calc(300 / 1023 * 100%); transform: translateX(-50%); }
.lg700 { right: 0; }

/* ---------- sliders ---------- */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 6px 0 0; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: #525252; border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 4px; background: #525252; border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); border: 3px solid var(--bg); margin-top: -8px; box-shadow: 0 0 0 1px #8d8d8d; }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--ink); border: 3px solid var(--bg); box-shadow: 0 0 0 1px #8d8d8d; }
#gas::-webkit-slider-thumb { background: var(--accent); }
#gas::-moz-range-thumb { background: var(--accent); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .primary { grid-column: 1 / -1; }

.env { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 12px; margin: 16px 0 0; }
.env legend { font-size: 12px; color: var(--muted); padding: 0 6px; }
.field { display: grid; grid-template-columns: 1fr auto; align-items: baseline; margin-top: 6px; }
.field label { font-size: 13.5px; font-weight: 500; }
.field .unit { color: var(--muted); font-weight: 400; font-size: 12px; }
.field output { font-size: 14px; font-weight: 600; }
.field input { grid-column: 1 / -1; }
.field.zone { grid-template-columns: 1fr; gap: 6px; margin-top: 10px; }
select {
  width: 100%; font: 500 14px var(--font-body); color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 10px; min-height: 40px;
}

/* ---------- flow ---------- */
.flow-canvas {
  position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background-color: #1b1b1b;
  background-image: linear-gradient(#242424 1px, transparent 1px), linear-gradient(90deg, #242424 1px, transparent 1px);
  background-size: 20px 20px;
}
.flow-tab {
  display: inline-block; font: 500 12px var(--font-body); color: var(--ink); background: #262626;
  border: 1px solid var(--line); border-top: 0; border-left: 0; border-radius: 0 0 6px 0; padding: 6px 14px;
}
.flow-scroll { overflow-x: auto; padding: 4px 8px 10px; }
#flowSvg { display: block; width: 100%; height: auto; }
.wire { fill: none; stroke: #6f6f6f; stroke-width: 2; transition: stroke .3s; }
.wire.hot { stroke: #c6c6c6; }
.wire.alert { stroke: var(--danger); stroke-width: 2.5; }
.wire.idle { stroke: #444; stroke-dasharray: 4 4; }
.node-rect { stroke: rgba(0,0,0,.35); stroke-width: 1; }
.node-icon { fill: rgba(0,0,0,.14); }
.node-label { font: 500 12px var(--font-body); fill: #161616; }
.node-label.light { fill: #fff; }
.node-status { font: 500 10.5px var(--font-body); fill: var(--muted); }
.node-status.alert { fill: var(--danger-ink); font-weight: 700; }
.node-status.ok { fill: #6fdc8c; }
.status-dot { fill: #6fdc8c; }
.status-dot.alert { fill: var(--danger); }
.status-dot.idle { fill: #6f6f6f; }
.port { fill: #d0d0d0; stroke: #6f6f6f; }
.node.flash .node-rect { stroke: var(--ink); stroke-width: 2; }
.node.alert .node-rect { stroke: var(--danger); stroke-width: 2.5; }
.packet { fill: var(--accent); stroke: #161616; stroke-width: 1.5; }
.packet.red { fill: var(--danger); stroke: #fff; }
.packet.loc { fill: #78a9ff; }

.payload { margin-top: 14px; }
.payload-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.payload pre {
  margin: 6px 0 0; padding: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; color: #c6c6c6; min-height: 86px;
}
.payload pre .k { color: var(--muted); }
.payload pre .v { color: var(--accent); }
.payload pre .r { color: var(--danger-ink); }

/* ---------- phone ---------- */
.phone {
  width: 100%; max-width: 300px; margin: 0 auto; background: #0b0b0b; border-radius: 34px;
  padding: 14px 10px 10px; border: 1px solid #3a3a3a; box-shadow: 0 0 0 5px #1f1f1f, 0 20px 40px rgba(0,0,0,.45);
  position: relative; transition: box-shadow .3s;
}
body.dash-alert .phone { box-shadow: 0 0 0 5px var(--danger), 0 20px 40px rgba(218,30,40,.25); }
.phone-notch { width: 70px; height: 6px; border-radius: 3px; background: #262626; margin: 0 auto 10px; }
.screen { background: #121212; border-radius: 6px; overflow: hidden; position: relative; min-height: 460px; display: flex; flex-direction: column; }
.statusbar { display: flex; justify-content: space-between; padding: 6px 12px; font-size: 11px; background: #000; color: #e0e0e0; }
.appbar { background: #5a5a5a; color: #fff; padding: 9px 12px; font-size: 13px; font-weight: 500; transition: background .3s; }
body.dash-alert .appbar { background: var(--danger); }

.evac {
  display: flex; align-items: center; gap: 8px; background: var(--danger); color: #fff;
  font: 700 13px var(--font-display); letter-spacing: .05em; padding: 8px 12px;
  animation: evac 1s steps(1) infinite;
}
@keyframes evac { 50% { background: #a2191f; } }

.rows { margin: 0; padding: 10px; display: grid; gap: 8px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; align-items: center; gap: 8px; background: #262626; border: 2px solid #3d3d3d; border-radius: 3px; padding: 8px 8px 8px 10px; transition: border-color .3s, background .3s; }
.row dt { font: italic 700 17px/1.1 var(--font-body); }
.row dd { margin: 0; background: #f4f4f4; color: #161616; border-radius: 3px; padding: 8px 6px; text-align: center; font-size: 15px; font-weight: 500; transition: background .3s, color .3s; }
html[lang="de"] .row dt { font-size: 15px; } /* longer German labels (Luftfeuchtigkeit, Gaskonzentration) */
.r-temp dt { color: #78a9ff; }
.r-hum dt { color: #3ddbd9; }
.r-pres dt { color: #ff8389; }
.r-gas dt { color: #d4bbff; }
.row.bump dd { background: #fddc69; }
body.dash-alert .r-gas { border-color: var(--danger); background: #3a1a1c; }
body.dash-alert .r-gas dd { background: var(--danger); color: #fff; font-weight: 700; }

.sms {
  position: absolute; left: 8px; right: 8px; top: 30px; z-index: 3;
  background: rgba(40,40,40,.97); border: 1px solid #525252; border-left: 4px solid var(--danger);
  border-radius: 12px; padding: 10px 30px 10px 12px; box-shadow: 0 10px 24px rgba(0,0,0,.6);
  animation: drop .35s cubic-bezier(.2,.8,.2,1);
}
@keyframes drop { from { transform: translateY(-120%); opacity: 0; } }
.sms-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.sms-from { margin: 4px 0 2px; font-weight: 600; font-size: 13px; }
.sms-body { margin: 0; font-size: 13px; line-height: 1.4; }
.sms-body strong { color: var(--danger-ink); }
.sms-close { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border: 0; background: transparent; color: var(--ink); font-size: 20px; line-height: 1; border-radius: 6px; cursor: pointer; }
.sms-close:hover { background: #393939; }

.loc { margin: auto 10px 10px; border: 1px solid #3d3d3d; border-radius: 8px; overflow: hidden; background: #1d1d1d; }
.loc-map svg { display: block; width: 100%; height: 76px; }
.map-pin path { fill: #6f6f6f; transition: fill .3s; }
.pin-pulse { fill: var(--danger); opacity: 0; }
.loc.live .map-pin path { fill: var(--danger); }
.loc.live .pin-pulse { animation: pulse 1.4s ease-out infinite; transform-origin: 128px 36px; transform-box: view-box; }
@keyframes pulse { from { opacity: .6; transform: scale(.4); } to { opacity: 0; transform: scale(1.8); } }
.loc-text { padding: 8px 10px 10px; }
.loc-title { margin: 0; font-size: 12px; font-weight: 600; }
.loc-coords { margin: 2px 0; font-size: 12px; color: var(--muted); }
.loc.live .loc-coords { color: var(--ink); }
.loc-state { margin: 0; font-size: 11.5px; color: var(--muted); }
.loc.live .loc-state { color: var(--danger-ink); font-weight: 600; }
.phone-nav { display: flex; justify-content: space-around; color: #8d8d8d; padding: 8px 20px 2px; font-size: 16px; }

/* ---------- log ---------- */
.log-head { align-items: center; }
.log-head > div { flex: 1; }
.log-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; font-size: 12.5px; border-top: 1px solid var(--line); }
.log-list li { display: grid; grid-template-columns: 96px 76px minmax(0, 1fr); gap: 10px; padding: 6px 2px; border-bottom: 1px solid #303030; }
.log-list .t { color: var(--muted); }
.log-list .tag { font-weight: 700; }
.log-list .msg { overflow-wrap: anywhere; color: #d0d0d0; }
.tag-FW { color: var(--accent); }
.tag-MQTT { color: #78a9ff; }
.tag-NODE-RED { color: #ff9f5a; }
.tag-GSM { color: var(--danger-ink); }
.tag-APP { color: #3ddbd9; }
.tag-USER { color: var(--muted); }
.log-list li.alert .msg { color: var(--danger-ink); font-weight: 600; }
.log-list li.clear .msg { color: #6fdc8c; font-weight: 600; }

/* ---------- refs ---------- */
.refs { margin-top: 32px; }
.refs h2 { font-size: 17px; }
.ref-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.ref-grid figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ref-grid a { display: block; height: 150px; background: #fff; }
.ref-grid img { width: 100%; height: 100%; object-fit: cover; object-position: top center; opacity: .92; transition: opacity .2s; }
.ref-grid a:hover img { opacity: 1; }
.ref-grid figcaption { font-size: 12.5px; color: var(--muted); padding: 8px 10px; }
.foot { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.foot p { margin: 0; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "sensor app" "flow flow" "log log"; }
}
@media (max-width: 760px) {
  .top { flex-direction: column; }
  .top-status { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "sensor" "flow" "app" "log"; }
  .ref-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .log-list li { grid-template-columns: 1fr; gap: 0; }
  .log-list .t, .log-list .tag { display: inline; }
  .log-list li { display: block; }
  .log-list .tag { margin-left: 8px; }
  .log-list .msg { display: block; }
  .panel { padding: 14px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #outBuzz.on .wave { opacity: 1; }
  .loc.live .pin-pulse { opacity: .35; }
}
