/* TOR Messwesen Konfigurator – Design. Hell/Dunkel automatisch, mobil nutzbar, druckfreundlich. */
:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --border: #d9dfe6;
  --text: #17202a;
  --muted: #5b6672;
  --primary: #0b6fa4;
  --primary-dark: #0f3d5c;
  --primary-soft: #e6f1f8;
  --hzp: #0b6fa4;
  --sz: #4f9a3a;
  --ap: #d49a00;
  --ok: #2e7d32;      --ok-bg: #e8f5ee;
  --info: #0b6fa4;    --info-bg: #eaf2fb;
  --warn: #b3261e;    --warn-bg: #fdeceb;
  --amber-bg: #fff6dc;
  --shadow: 0 1px 2px rgba(15,61,92,.07), 0 6px 20px rgba(15,61,92,.06);
  --radius: 14px;
  --focus: 0 0 0 3px rgba(11,111,164,.28);
  --diag-bg: #fbfcfe;
  --net-fill: #eef1f5;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161d; --card: #17202a; --card-2: #1c2733; --border: #2c3a49;
    --text: #e6edf3; --muted: #9aa8b6;
    --primary: #4aa8dc; --primary-dark: #0d2a3f; --primary-soft: #16303f;
    --hzp: #4aa8dc; --sz: #7bc467; --ap: #f0b72f;
    --ok: #6fcf7a; --ok-bg: #163222; --info: #6bb9e8; --info-bg: #15293a;
    --warn: #ff8a80; --warn-bg: #3a1b1a; --amber-bg: #3a3014;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
    --diag-bg: #131c26; --net-fill: #202c39;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
code { background: var(--card-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

/* ---------- Kopfzeile ---------- */
.topbar { background: var(--primary-dark); color: #fff; padding: 12px 28px; display: flex; align-items: center;
  justify-content: space-between; gap: 16px; position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 36px; height: 36px; flex: none; }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: .1px; }
.topbar .sub { font-size: 12px; opacity: .8; margin-top: 1px; }
.topbar nav { display: flex; gap: 6px; flex: none; }
.topbar nav a { color: #fff; padding: 7px 14px; border-radius: 8px; font-size: 13.5px; background: rgba(255,255,255,.1); }
.topbar nav a.active { background: rgba(255,255,255,.26); font-weight: 600; }
.topbar nav a:hover { text-decoration: none; background: rgba(255,255,255,.2); }

main { max-width: 1280px; margin: 22px auto 64px; padding: 0 24px; }

/* ---------- Karten ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 24px; margin-bottom: 20px; }
.card > h2, .card-h { margin: 0 0 14px; font-size: 16px; font-weight: 650; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card h3 { font-size: 14px; margin: 18px 0 8px; }
.card h4 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }
.badge { font-size: 11.5px; font-weight: 600; background: var(--primary-soft); color: var(--primary); padding: 2px 9px; border-radius: 999px; }
.notice { background: var(--info-bg); border-left: 4px solid var(--info); border-radius: 8px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 14px; }

/* ---------- Hauptlayout ---------- */
.layout { display: grid; grid-template-columns: minmax(320px, 440px) 1fr; gap: 20px; align-items: start; }
.layout > .card { margin-bottom: 0; }
.result-col { position: sticky; top: 84px; }
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } .result-col { position: static; } main { padding: 0 14px; } .topbar { padding: 10px 14px; } .topbar .sub { display: none; } }

/* ---------- Eingaben ---------- */
.group { margin-bottom: 6px; }
.group-title { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700;
  margin: 18px 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--border); }
.group:first-of-type .group-title { margin-top: 4px; }
.field { margin: 0 0 14px; }
.field > label, .field > .lbl { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
select, input[type=text], input[type=number], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 11px; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.seg { position: relative; display: inline-flex; background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 6px 16px; border-radius: 7px; cursor: pointer; font-size: 14px; color: var(--muted); user-select: none; }
.seg label:hover { color: var(--text); }
.seg input:checked + label { background: var(--primary); color: #fff; font-weight: 600; }
.seg input:focus-visible + label { box-shadow: var(--focus); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper input { width: 80px; text-align: center; }
.stepper button { width: 34px; height: 34px; padding: 0; font-size: 18px; line-height: 1; }
.sub-fields { border-left: 3px solid var(--primary-soft); padding-left: 14px; margin-left: 4px; }

/* ---------- Ergebnis ---------- */
.res-head { display: flex; align-items: center; gap: 16px; margin-bottom: 4px; }
.code-badge { font-size: 30px; font-weight: 800; background: var(--primary-dark); color: #fff; border-radius: 12px;
  padding: 6px 18px; letter-spacing: .5px; min-width: 76px; text-align: center; }
.code-badge.sonder { background: var(--warn); }
.res-head .kat { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.res-head .kurz { font-size: 14.5px; font-weight: 500; }
.banner { border-radius: 10px; padding: 11px 14px; margin: 14px 0; font-size: 14px; border-left: 4px solid; }
.banner.ok { background: var(--ok-bg); border-color: var(--ok); }
.banner.info { background: var(--info-bg); border-color: var(--info); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn); font-weight: 500; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.kpi { background: var(--card-2); border: 1px solid var(--border); border-top: 4px solid var(--c, var(--primary)); border-radius: 10px; padding: 10px 12px; }
.kpi .v { font-size: 30px; font-weight: 750; line-height: 1.1; }
.kpi .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hzp { --c: var(--hzp); } .kpi.sz { --c: var(--sz); } .kpi.ap { --c: var(--ap); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--c); color: var(--text); background: transparent; white-space: nowrap; }
.chip.hzp { --c: var(--hzp); } .chip.sz { --c: var(--sz); } .chip.ap { --c: var(--ap); }
.chip.calc { border-style: dashed; }
.chip.more { border-color: var(--border); color: var(--muted); }
.list-line { margin: 8px 0; font-size: 13px; }
.list-line > b { display: inline-block; min-width: 130px; color: var(--muted); font-weight: 600; }

.methods { display: grid; gap: 8px; margin: 12px 0; }
.mcard { text-align: left; font: inherit; color: var(--text); background: var(--card-2); border: 2px solid var(--border); border-radius: 11px;
  padding: 10px 14px; cursor: pointer; display: grid; gap: 2px; }
.mcard:hover:not(.locked) { border-color: var(--primary); }
.mcard.active { border-color: var(--primary); background: var(--primary-soft); }
.mcard .mn { font-weight: 650; display: flex; justify-content: space-between; gap: 8px; }
.mcard .mi { font-size: 12.5px; color: var(--muted); }
.mcard .mc { font-size: 12px; color: var(--muted); }
.mcard.locked { opacity: .6; cursor: not-allowed; background: transparent; border-style: dashed; }
.mcard.locked .mn::after { content: "gesperrt"; font-size: 11px; color: var(--warn); font-weight: 700; text-transform: uppercase; }
.mcard .why { font-size: 12.5px; color: var(--warn); font-weight: 500; }
.single-method { background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin: 12px 0; }
.single-method .mn { font-weight: 650; }
.single-method .mi { font-size: 12.5px; color: var(--muted); }
dl.facts { margin: 14px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; }
dl.facts dt { color: var(--muted); font-weight: 600; }
dl.facts dd { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* ---------- Schaltbild ---------- */
.diagram-wrap { background: var(--diag-bg); border: 1px solid var(--border); border-radius: 12px; padding: 8px; overflow-x: auto; }
.diagram-wrap svg { width: 100%; height: auto; min-width: 640px; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.legend .sw { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 2px solid var(--c); background: var(--f, transparent); }
.d-net    { fill: var(--net-fill); stroke: var(--border); stroke-width: 1.5; }
.d-anlage { fill: none; stroke: var(--sz); stroke-width: 2; stroke-dasharray: 7 5; }
.d-box    { fill: var(--card); stroke: var(--muted); stroke-width: 1.5; }
.d-hzp    { fill: var(--hzp); }
.d-sz     { fill: var(--card); stroke: var(--sz); stroke-width: 2.5; }
.d-ap     { fill: var(--card); stroke: var(--ap); stroke-width: 2.5; }
.d-ap.calc, .d-sz.calc { stroke-dasharray: 5 3; }
.d-t   { fill: var(--text); font-size: 12px; font-family: inherit; }
.d-t.b { font-weight: 650; }
.d-t.s { font-size: 10.5px; fill: var(--muted); }
.d-t.w { fill: #fff; }
.d-lineE { stroke: var(--sz); stroke-width: 2.4; fill: none; }
.d-lineB { stroke: var(--hzp); stroke-width: 2.4; fill: none; }
.d-lineN { stroke: var(--muted); stroke-width: 2; fill: none; }
.d-lineS { stroke: var(--border); stroke-width: 1.6; fill: none; }
.d-arrE { fill: var(--sz); } .d-arrB { fill: var(--hzp); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table.dt { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.dt th, table.dt td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.dt th { background: var(--card-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); position: sticky; top: 0; }
table.dt tbody tr:last-child td { border-bottom: 0; }
table.dt tbody tr.highlight-current { background: var(--amber-bg); }
table.dt tbody tr.highlight-current td:first-child { box-shadow: inset 4px 0 0 var(--ap); font-weight: 700; }
table.dt td.cell-hit { background: var(--amber-bg); font-weight: 700; }
table.dt input, table.dt textarea { min-width: 110px; }
table.dt textarea { min-height: 52px; resize: vertical; }
table.dt .row-actions { white-space: nowrap; }
details.card > summary { cursor: pointer; font-size: 16px; font-weight: 650; list-style: none; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.card > .body { margin-top: 14px; }

/* ---------- Buttons ---------- */
button, .btn { font: inherit; font-size: 14px; cursor: pointer; border: 1px solid var(--primary); background: var(--primary); color: #fff;
  border-radius: 9px; padding: 8px 16px; font-weight: 600; }
button:hover { filter: brightness(1.1); }
button:focus-visible { outline: none; box-shadow: var(--focus); }
button.secondary { background: transparent; color: var(--primary); }
button.secondary:hover { background: var(--primary-soft); filter: none; }
button.danger { background: var(--warn); border-color: var(--warn); color: #fff; }
button.small { padding: 4px 10px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Konfig-Seite ---------- */
.row-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.row-tabs button { background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
.row-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 650; }
.row-tabs button.dirty::after { content: " ●"; color: var(--ap); }
.config-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); align-items: center; }
.config-actions .status { margin-left: auto; color: var(--muted); font-size: 13px; }
.config-actions .status.dirty { color: var(--ap); font-weight: 600; }
.edit-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.edit-row .idx { width: 120px; flex: none; color: var(--muted); font-size: 12.5px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); background: #17202a; color: #fff; padding: 10px 20px;
  border-radius: 10px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: 90vw; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--warn); }

/* ---------- Druck ---------- */
@media print {
  .topbar, .actions, .seg, .stepper button, details.card:not([open]) { display: none !important; }
  html, body { background: #fff; color: #000; }
  .card { box-shadow: none; break-inside: avoid; }
  .layout { grid-template-columns: 1fr; } .result-col { position: static; }
  .mcard.locked { display: none; }
}

/* ---------- Kleine Bildschirme ---------- */
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; }
  .topbar nav { width: 100%; flex-wrap: wrap; }
  .topbar nav a { padding: 6px 10px; font-size: 13px; }
  .topbar h1 { font-size: 16px; }
  .card { padding: 16px 14px; }
  .kpis { gap: 6px; }
  .kpi .v { font-size: 24px; }
  dl.facts { grid-template-columns: 1fr; gap: 0; }
  dl.facts dd { margin-bottom: 8px; }
  .list-line > b { display: block; min-width: 0; }
}
