/*
  One stylesheet for the whole site: landing page, Impressum and handbook.
  Mobile first (360 px), light theme only (the Optima logo is black on
  transparent), system fonts only — the site makes no third-party requests.
*/

:root {
  --ink: #1b1f23;
  --ink-muted: #59636e;
  --paper: #ffffff;
  --surface: #f4f6f8;
  --line: #d6dbe0;
  --accent: #c2410c;
  --accent-soft: #fff1e6;
  --warning: #b91c1c;
  --warning-soft: #fdecec;
  --led-green: #22a55b;
  --led-red: #dc2626;
  --led-yellow: #eab308;
  --led-off: #c9ced4;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --gutter: 16px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  overflow-wrap: break-word;
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.6rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.25rem; margin: 2rem 0 0.6rem; padding-top: 0.25rem; }
h3 { font-size: 1.05rem; margin: 1.5rem 0 0.4rem; }

code, kbd { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--surface); padding: 0.05em 0.3em; border-radius: 3px; }

img, svg { max-width: 100%; height: auto; }

ul, ol { padding-left: 1.3rem; }
li + li { margin-top: 0.25rem; }

/* Anchor targets should not hide under the top edge when deep-linked. */
[id] { scroll-margin-top: 1rem; }


/* ---- Landing page and Impressum ---- */

.plain-page {
  max-width: 40rem;
  margin: 0 auto;
  padding: 3rem var(--gutter);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.plain-page main { flex: 1; }

.plain-page footer {
  margin-top: 3rem;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.landing main {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.landing h1 { font-size: 1.9rem; }
.landing p { color: var(--ink-muted); font-size: 1.1rem; margin: 0; }

.imprint dl { margin: 0; }
.imprint dt { font-weight: 600; margin-top: 0.9rem; }
.imprint dd { margin: 0; }


/* ---- Handbook layout ---- */

.handbook-header {
  border-bottom: 1px solid var(--line);
  padding: 0.6rem var(--gutter);
}

.handbook-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.handbook-brand img { width: 64px; height: auto; }

.handbook-layout {
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.chapter-nav { padding: 0.75rem 0; border-bottom: 1px solid var(--line); }

.chapter-nav ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chapter-nav li + li { margin-top: 0; }

.chapter-nav a {
  display: block;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
}

.chapter-nav a[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chapter-nav .print-link { margin: 0.6rem 0 0; font-size: 0.9rem; }
.chapter-nav .print-link a { display: inline-block; }

.handbook-content { padding: 1.25rem 0 2rem; min-width: 0; }

.lead { font-size: 1.08rem; color: var(--ink-muted); }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.pager a { text-decoration: none; }
.pager .next { margin-left: auto; text-align: right; }

.handbook-footer {
  border-top: 1px solid var(--line);
  padding: 1rem var(--gutter);
  color: var(--ink-muted);
  font-size: 0.85rem;
}

@media (min-width: 900px) {
  .handbook-layout {
    display: grid;
    grid-template-columns: 14rem minmax(0, 1fr);
    gap: 2.5rem;
  }

  .chapter-nav {
    border-bottom: 0;
    padding-top: 1.5rem;
    position: sticky;
    top: 0;
    align-self: start;
  }

  .chapter-nav ol { flex-direction: column; gap: 0.15rem; }
  .chapter-nav a { border: 0; border-radius: 6px; font-size: 0.95rem; }
  .handbook-content { padding-top: 1.5rem; max-width: 46rem; }
}


/* ---- Content blocks ---- */

.note, .warning {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 0.7rem 0.9rem;
  margin: 1rem 0;
  border-radius: 0 6px 6px 0;
}

.warning { border-left-color: var(--warning); background: var(--warning-soft); }
.note > :first-child, .warning > :first-child { margin-top: 0; }
.note > :last-child, .warning > :last-child { margin-bottom: 0; }
.warning strong:first-child { color: var(--warning); }

figure { margin: 1.25rem 0; }
figcaption { color: var(--ink-muted); font-size: 0.9rem; margin-top: 0.4rem; }

.steps { counter-reset: step; list-style: none; padding-left: 0; }
.steps > li {
  counter-increment: step;
  position: relative;
  padding-left: 2.2rem;
  margin-top: 0.8rem;
}
.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.6rem;
}


button {
  font: inherit;
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:disabled { opacity: 0.5; cursor: default; }


/* ---- Tables ---- */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0 1.25rem;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
}

thead th { background: var(--surface); font-weight: 600; }

/* Two-column key/value tables (Technische Daten). */
.spec th { width: 45%; font-weight: 500; color: var(--ink-muted); }

/*
  Tables with more than two columns turn into stacked cards on phones:
  every cell shows its column name from data-label.
*/
@media (max-width: 640px) {
  .cards thead { display: none; }
  .cards, .cards tbody, .cards tr, .cards td { display: block; width: 100%; }
  .cards tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 0.75rem;
    padding: 0.35rem 0;
  }
  .cards td { border-bottom: 0; padding: 0.3rem 0.75rem; }
  .cards td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--ink-muted);
  }
}


/* ---- LED indicators ---- */

.led-states { list-style: none; padding: 0; margin: 0; }
.led-states li { display: flex; align-items: center; gap: 0.45rem; margin: 0.15rem 0; }

.led {
  flex: none;
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--led-off);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.led.green { --lit: var(--led-green); }
.led.red { --lit: var(--led-red); }
.led.yellow { --lit: var(--led-yellow); }

.led.on { background: var(--lit); }

/*
  Blink animations mirror the gateway's patterns: a pulse is 150 ms on and
  150 ms off, followed by a 1.35 s pause (BlinkPattern.MultiplePulsesPattern).
  steps(1, end) holds each keyframe's colour until the next keyframe.
*/
.led.pulse-1, .led.pulse-2, .led.pulse-3, .led.flicker, .led.flashing {
  animation-timing-function: steps(1, end);
  animation-iteration-count: infinite;
}

.led.pulse-1 { animation-name: pulse-1; animation-duration: 1650ms; }
.led.pulse-2 { animation-name: pulse-2; animation-duration: 1950ms; }
.led.pulse-3 { animation-name: pulse-3; animation-duration: 2250ms; }
.led.flicker { animation-name: flicker; animation-duration: 1400ms; }
.led.flashing { animation-name: flashing; animation-duration: 1000ms; }

@keyframes pulse-1 {
  0% { background: var(--lit); }
  9.09% { background: var(--led-off); }
}

@keyframes pulse-2 {
  0% { background: var(--lit); }
  7.69% { background: var(--led-off); }
  15.38% { background: var(--lit); }
  23.08% { background: var(--led-off); }
}

@keyframes pulse-3 {
  0% { background: var(--lit); }
  6.67% { background: var(--led-off); }
  13.33% { background: var(--lit); }
  20% { background: var(--led-off); }
  26.67% { background: var(--lit); }
  33.33% { background: var(--led-off); }
}

/* Irregular, like flash-memory access. */
@keyframes flicker {
  0% { background: var(--lit); }
  5% { background: var(--led-off); }
  12% { background: var(--lit); }
  15% { background: var(--led-off); }
  45% { background: var(--lit); }
  49% { background: var(--led-off); }
  80% { background: var(--lit); }
  86% { background: var(--led-off); }
}

@keyframes flashing {
  0% { background: var(--lit); }
  50% { background: var(--led-off); }
}

@media (prefers-reduced-motion: reduce) {
  .led { animation: none !important; }
  .led.pulse-1, .led.pulse-2, .led.pulse-3, .led.flicker, .led.flashing { background: var(--lit); }
}


/* ---- Wiring drawings (inline SVG) ---- */

.drawing { display: block; width: 100%; max-width: 34rem; }
.drawing text { font-family: var(--font); fill: var(--ink); }
.drawing .block-name { font-size: 11px; font-weight: 600; text-anchor: middle; }
.drawing .pin-name { font-size: 10.5px; text-anchor: middle; dominant-baseline: central; }
.drawing .port-name { font-size: 10.5px; text-anchor: middle; dominant-baseline: central; }
.drawing .outline { fill: none; stroke: var(--ink-muted); stroke-width: 1; }
.drawing .cell { fill: var(--paper); stroke: var(--ink); stroke-width: 1; }
.drawing .cell.ground { fill: #e5e7eb; }
.drawing .cell.supply { fill: #fde2e2; }
.drawing .port { fill: var(--surface); stroke: var(--ink); stroke-width: 1; }
.drawing .highlight { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.drawing .wire { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.drawing .wire.bus { stroke: var(--accent); stroke-width: 2; }
.drawing .device { fill: var(--surface); stroke: var(--ink); stroke-width: 1; }
.drawing .wire.supply { stroke: #c0392b; }
.drawing .junction { fill: var(--ink); }

/* ---- Product rendering and dimension drawings (raster) ---- */

.photo { display: block; width: 100%; max-width: 34rem; height: auto; }

/* Front and side view sit next to each other when there is room and stack on phones. */
.dimension-views { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem 2rem; }
.dimension-views img { display: block; height: auto; min-width: 0; }
.dimension-views .front { flex: 1 1 16rem; max-width: 24rem; }
.dimension-views .side { flex: 0 1 9rem; max-width: 11rem; }

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.88rem; color: var(--ink-muted); }
.legend span::before {
  content: "";
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-right: 0.35rem;
  vertical-align: -0.1rem;
  border: 1px solid var(--ink);
}
.legend .ground::before { background: #e5e7eb; }
.legend .supply::before { background: #fde2e2; }


/* ---- Print: clean offline copy ---- */

@media print {
  :root { --gutter: 0; }

  @page { size: A4; margin: 16mm 14mm; }

  body { font-size: 10.5pt; line-height: 1.45; }

  .chapter-nav, .pager, .no-print { display: none !important; }

  .handbook-layout { display: block; max-width: none; padding: 0; }
  .handbook-content { padding: 0; max-width: none; }
  .handbook-header { padding: 0 0 4mm; }
  .handbook-footer { padding: 4mm 0 0; }

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

  h2, h3 { break-after: avoid; }
  table, figure, .note, .warning, tr, .steps > li { break-inside: avoid; }

  /* In the combined print page every chapter starts on a new sheet. */
  .print-book > article + article { break-before: page; }

  .led { animation: none !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .led.pulse-1, .led.pulse-2, .led.pulse-3, .led.flicker, .led.flashing { background: var(--lit); }
  .cell, .note, .warning, thead th, .steps > li::before {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
