:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --border: #e3dfd7;
  --text: #1c1917;
  --muted: #6b645c;
  --accent: #0f766e;
  --accent-soft: #e6f2f0;
  --ok: #15803d;
  --ok-soft: #e8f5ec;
  --warn: #b45309;
  --warn-soft: #fdf3e4;
  --err: #b91c1c;
  --err-soft: #fdecec;
  --paper: #ffffff;
  --paper-border: #e3dfd7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.06), 0 2px 8px rgba(28, 25, 23, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --surface: #211f1c;
    --surface-2: #1b1a18;
    --border: #36322d;
    --text: #ece8e2;
    --muted: #a39b91;
    --accent: #2bb5a6;
    --accent-soft: #15302d;
    --ok: #4ade80;
    --ok-soft: #14291b;
    --warn: #f59e0b;
    --warn-soft: #2e2312;
    --err: #f87171;
    --err-soft: #331a1a;
    --paper-border: #3c3732;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #171614;
  --surface: #211f1c;
  --surface-2: #1b1a18;
  --border: #36322d;
  --text: #ece8e2;
  --muted: #a39b91;
  --accent: #2bb5a6;
  --accent-soft: #15302d;
  --ok: #4ade80;
  --ok-soft: #14291b;
  --warn: #f59e0b;
  --warn-soft: #2e2312;
  --err: #f87171;
  --err-soft: #331a1a;
  --paper-border: #3c3732;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

var { font-style: italic; font-family: Georgia, "Times New Roman", serif; font-size: 1.05em; }
sub { font-size: 0.72em; line-height: 0; }
var + sub { margin-left: 0.05em; }
.chip var, .chip sub { font-weight: 500; }

h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: 0.01em; }

/* ---------- Kopf ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; flex: none; }
.brand-home { display: flex; border-radius: 8px; }
.brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.brand-mark rect { fill: var(--accent); }
.brand-mark .b { fill: #f4e8d0; }
.brand-mark .s { fill: #ecdcbb; }
.brand h1 { margin: 0; font-size: 19px; letter-spacing: 0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12.5px; }
.actions { display: flex; gap: 8px; flex: none; }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { width: 100%; background: transparent; color: var(--muted); font-weight: 500; }

/* ---------- Raster ---------- */

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px 40px;
  max-width: 1600px;
  margin: 0 auto;
}

main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }

.panel {
  position: sticky;
  top: 86px;
  align-self: start;
  max-height: calc(100vh - 106px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px 16px 16px;
}

/* ---------- Eingaben ---------- */

fieldset {
  border: 0;
  border-bottom: 1px solid var(--border);
  margin: 0;
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
legend {
  float: left;
  width: 100%;
  padding: 0;
  margin-bottom: 4px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
legend + * { clear: both; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row > label, .lbl { color: var(--text); }
.sub { display: flex; flex-direction: column; gap: 8px; padding-left: 2px; }
.sub.disabled { opacity: 0.45; pointer-events: none; }

.field {
  display: flex;
  align-items: center;
  width: 112px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.field input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 6px 4px 6px 8px;
  outline: none;
}
.field .unit { color: var(--muted); padding-right: 9px; min-width: 14px; font-size: 12.5px; }
.field .spin {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  border-left: 1px solid var(--border);
}
.field .spin button {
  flex: 1;
  width: 24px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.field .spin button + button { border-top: 1px solid var(--border); }
.field .spin button:first-child { border-top-right-radius: 6px; }
.field .spin button:last-child { border-bottom-right-radius: 6px; }
.field .spin button:hover { background: var(--accent-soft); color: var(--accent); }
.field .spin button:active { background: var(--accent); color: #fff; }
.field .spin svg { width: 10px; height: 6px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.field:has(.spin) { width: 128px; }
.field:has(.spin) .unit { padding-right: 10px; flex: none; }
#view-overview svg { touch-action: none; user-select: none; }
#view-overview .rot-hint path { transition: stroke-width 120ms; }
#view-overview.hover-strut .rot-hint path[fill="none"] { stroke-width: 3.6px; }
.field.invalid { border-color: var(--err); box-shadow: 0 0 0 2px var(--err-soft); }
.field input:disabled { color: var(--muted); }

select, input.text {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  width: 150px;
  flex: none;
}
select:focus, input.text:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0 0; }

.seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.seg label { flex: 1; position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  text-align: center;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg label.disabled { opacity: 0.4; pointer-events: none; }
.seg-sm { width: 150px; flex: none; }
.seg-sm span { padding: 3px 6px; font-size: 12.5px; }

.hint { color: var(--muted); font-size: 12.5px; margin: 0; }

/* ---------- Status ---------- */

.status { display: flex; flex-direction: column; gap: 10px; }
.status:empty { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
}
.chip b { font-weight: 650; }
.chip.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.chip.fail { background: var(--err-soft); border-color: transparent; color: var(--err); }
.chip.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }

.msgs { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.msgs li { padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.msgs .error { background: var(--err-soft); color: var(--err); }
.msgs .warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Karten und Zeichnungen ---------- */

.card {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

.view figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 650;
  margin-bottom: 10px;
}
.badge {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}

.paper {
  background: var(--paper);
  border: 1px solid var(--paper-border);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  justify-content: center;
}
.paper svg { display: block; width: 100%; height: auto; max-height: 64vh; }
.paper.scroll { overflow-x: auto; justify-content: flex-start; -webkit-overflow-scrolling: touch; }
.paper.scroll svg { flex: none; max-height: none; }

.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }

/* ---------- Tabellen ---------- */

table.vals { width: 100%; border-collapse: collapse; font-size: 13px; }
table.vals th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 14px 0 6px;
  border-bottom: 1px solid var(--border);
}
table.vals tr:first-child th { padding-top: 0; }
table.vals td { padding: 6px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
table.vals td.v { text-align: right; font-weight: 600; white-space: nowrap; padding-left: 12px; }
table.vals td .note { display: block; color: var(--muted); font-size: 12px; }

.check-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.check-item:first-child { padding-top: 0; }
.check-item:last-child { border-bottom: 0; padding-bottom: 0; }
.check-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.check-head h3 { font-size: 14px; margin: 0; }
.check-head .ref { color: var(--muted); font-size: 12px; }
.check-rows { width: 100%; border-collapse: collapse; margin: 6px 0 8px; font-size: 12.5px; }
.check-rows td { padding: 2px 0; }
.check-rows td.f { color: var(--muted); }
.check-rows td.v { text-align: right; white-space: nowrap; font-weight: 600; }
.eta { display: flex; align-items: center; gap: 10px; }
.eta-bar { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.eta-bar i { display: block; height: 100%; border-radius: 4px; }
.eta-val { font-weight: 700; white-space: nowrap; min-width: 92px; text-align: right; }
.eta.ok i { background: var(--ok); } .eta.ok .eta-val { color: var(--ok); }
.eta.fail i { background: var(--err); } .eta.fail .eta-val { color: var(--err); }
.eta.warn i { background: var(--warn); } .eta.warn .eta-val { color: var(--warn); }
.check-hint { margin: 6px 0 0; font-size: 12.5px; color: var(--err); }
.muted { color: var(--muted); }

.notes ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 6px; }

.print-only { display: none; }

/* ---------- Modus ---------- */

body[data-mode="simple"] .full-only,
body[data-mode="full"] .simple-only { display: none !important; }

ol.steps { margin: 0; padding-left: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; }
ol.steps li { counter-increment: step; position: relative; padding-left: 34px; }
ol.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -1px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 12.5px;
  display: grid;
  place-items: center;
}
ol.steps li.h {
  counter-increment: none;
  padding-left: 0;
  margin: 6px 0 -2px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}
ol.steps li.h:first-child { margin-top: 0; }
ol.steps li.h::before { display: none; }
.pt {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  vertical-align: 1px;
}

/* ---------- Schmale Bildschirme ---------- */

@media (max-width: 1100px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 16px; }
  .panel { position: static; max-height: none; overflow: visible; }
  .app-header { padding: 12px 16px; position: static; }
}

@media (max-width: 560px) {
  .app-header { flex-direction: column; align-items: stretch; }
  .actions .btn { flex: 1; }
  .brand p { font-size: 12px; }
  .card { padding: 12px; }
  .paper { padding: 4px; }
  select, input.text { width: 140px; }
}

/* ---------- Druck: Planblatt A4 quer, danach Nachweise ---------- */

@page { size: A4 landscape; margin: 12mm 16mm; }
@page sheet { size: A4 landscape; margin: 0; }

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #1c1917; font-size: 9pt; }
  .app { display: none; }
  .print-only { display: block; }
  #print-sheet { page: sheet; }
  #print-sheet svg { display: block; width: 297mm; height: 210mm; }
  .print-page { break-before: page; }
  .print-page h2 { font-size: 12pt; margin-bottom: 6pt; }
  .print-page .cols { columns: 2; column-gap: 12mm; }
  .print-page .check-item { break-inside: avoid; padding: 7pt 0; }
  .print-page table.vals td { padding: 3pt 0; }
  .print-page table.vals tr,
  .print-page ol.steps li { break-inside: avoid; }
  .eta-bar { border-color: #ccc; }
}
