/* Wärmepur Rechnungen – Arbeitsfläche nach HERO-Vorbild, Belegblatt in der Schrift des freigegebenen PDF. */
@font-face { font-family: "Vera"; src: url("/assets/fonts/Vera.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vera"; src: url("/assets/fonts/VeraBd.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --side: #1b2125; --side-2: #232b30; --side-3: #2c353b; --side-line: #343e44; --side-ink: #d4dade; --side-dim: #8c979e;
  --ground: #eceff1; --sheet: #ffffff; --panel: #f6f7f8; --line: #d8dde1; --line-2: #b9c1c7; --line-3: #e7eaec;
  --ink: #161b1f; --ink-2: #434d54; --ink-3: #5f6a72;
  --red: #dd1217; --red-dark: #b30d12; --pdf-accent: #cd423b;
  --green: #1d6f47; --green-wash: #e5f1ea;
  --amber: #8a5300; --amber-wash: #fbf1dc; --amber-band: #e9a63a;
  --crimson: #b1232b; --crimson-wash: #fbeaea;
  --focus: #1f5fd6;
  --chrome: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --doc: "Vera", "DejaVu Sans", Verdana, sans-serif;
  --radius: 4px;
  --shadow-sheet: 0 1px 2px rgba(22, 27, 31, .05), 0 12px 28px -18px rgba(22, 27, 31, .28);
  --shadow-pop: 0 2px 6px rgba(22, 27, 31, .08), 0 18px 40px -16px rgba(22, 27, 31, .35);
  font-family: var(--chrome); font-size: 14px; line-height: 1.45; color: var(--ink); background: var(--ground);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--ground); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
.num, td.num, .amount { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 8px; background: var(--ink); color: #fff; padding: 8px 12px; z-index: 50; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { padding: 48px; color: var(--ink-3); }

/* ---------------------------------------------------------------- Rahmen */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; padding: 14px 10px 14px; scrollbar-width: thin; scrollbar-color: var(--side-3) transparent; }
.plate {
  position: relative;
  background: linear-gradient(180deg, #ffffff 0%, #f5f7f9 100%);
  border-radius: 6px;
  padding: 15px 16px 14px;
  margin: 2px 4px 16px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-top: 3px solid var(--red);
  box-shadow: 0 8px 20px -10px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .92);
}
.plate img { display: block; width: 146px; height: auto; margin: 0 auto; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav-item > a, .nav-item > span { display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 10px;
  min-height: 32px; padding: 5px 10px; border-radius: 3px; text-decoration: none; font-size: 13.5px; color: var(--side-ink); }
.nav-item > a:hover { background: var(--side-2); color: #fff; }
.nav-item svg { color: var(--side-dim); }
.nav-item.active > a { background: var(--side-3); color: #fff; }
.nav-item.active > a svg { color: #ff5a5e; }
.nav-item.later > span { color: #8a959c; cursor: default; }
.nav-item.later svg { color: #6f7b82; }
.nav-later { font-size: 11.5px; color: var(--side-dim); font-style: normal; }
.subnav { list-style: none; margin: 2px 0 6px 19px; padding: 0 0 0 10px; border-left: 1px solid var(--side-line); }
.subnav a, .subnav span { display: flex; justify-content: space-between; padding: 4px 8px; font-size: 12.5px; border-radius: 3px; text-decoration: none; color: #b3bcc2; }
.subnav a:hover { color: #fff; background: var(--side-2); }
.subnav a.active { color: #fff; background: var(--side-2); }
.subnav span { color: #8a959c; }
.side-foot { margin-top: auto; padding: 14px 10px 0; font-size: 11.5px; color: var(--side-dim); line-height: 1.5; border-top: 1px solid var(--side-line); }
.side-foot b { color: var(--side-ink); font-weight: 600; }

.work { min-width: 0; display: flex; flex-direction: column; }
.testband { height: 6px; background: repeating-linear-gradient(-45deg, var(--amber-band) 0 10px, #2a3135 10px 20px); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; height: 56px; padding: 0 24px;
  background: #fff; border-bottom: 1px solid var(--line); }
.topbar .menu-toggle { display: none; }
.crumbs { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs b { color: var(--ink); font-weight: 600; }
.search { flex: 1; max-width: 420px; margin-left: auto; position: relative; }
.search input { width: 100%; height: 34px; padding: 0 12px 0 34px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.search input:focus { background: #fff; border-color: var(--line-2); }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--ink-3); }
.area-flag { display: flex; align-items: center; gap: 9px; line-height: 1.2; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.area-flag b { font-size: 12.5px; color: var(--ink); }
.area-flag .swatch-test { width: 16px; height: 26px; }
.new-wrap { position: relative; }
.main { padding: 26px 28px 64px; max-width: 1480px; width: 100%; }
.main:focus { outline: none; }
/* Gewählte Ansicht lädt noch: die bisherige tritt zurück und ist nicht mehr bedienbar (erst nach kurzer Zeit, damit schnelle Wechsel nicht flackern). */
.app[aria-busy="true"] .main { opacity: .5; pointer-events: none; transition: opacity .15s ease .25s; }

/* ---------------------------------------------------------- Bausteine */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line-2); background: #fff; color: var(--ink); font-weight: 550; font-size: 13.5px; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.btn:hover { border-color: #8e989f; background: #fafbfb; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn.dark { background: var(--side); border-color: var(--side); color: #fff; }
.btn.dark:hover { background: #2b3338; }
.btn.quiet { border-color: transparent; background: transparent; padding: 0 8px; color: var(--ink-2); }
.btn.quiet:hover { background: rgba(22, 27, 31, .05); }
.btn.danger { color: var(--crimson); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.busy { pointer-events: none; }
.btn svg { flex: none; }
.coil { width: 30px; height: 14px; }
.coil path { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: 60; animation: coil 1.1s ease-in-out infinite; }
@keyframes coil { 0% { stroke-dashoffset: 60; } 60% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -60; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.page-head .sub { color: var(--ink-3); margin-top: 3px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section-title { font-size: 14.5px; font-weight: 650; margin: 0 0 10px; display: flex; align-items: baseline; gap: 10px; }
.section-title .meta { font-weight: 400; color: var(--ink-3); font-size: 12.5px; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.panel-pad { padding: 16px 18px; }
.panel + .panel { margin-top: 16px; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.hint { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.notice { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--panel); font-size: 13px; }
.notice.warn { background: var(--amber-wash); border-color: #ecd3a3; color: #5d3b00; }
.notice.error { background: var(--crimson-wash); border-color: #efc1c3; color: #7d161c; }
.notice.ok { background: var(--green-wash); border-color: #bcdcc8; color: #154f33; }

/* Tabellen */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.list th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--ink-2); background: var(--panel);
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line-3); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr.row-link { cursor: pointer; }
table.list tbody tr.row-link:hover td { background: #f7f9fa; }
table.list tbody tr.selected td { background: #eef1f3; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
table.list th.num { text-align: right; }
table.list a.cell-link { text-decoration: none; font-weight: 600; }
table.list a.cell-link:hover { text-decoration: underline; }
.empty { padding: 26px 18px; color: var(--ink-3); }
.empty b { color: var(--ink); display: block; margin-bottom: 4px; }

/* Zustände: Text mit kleinem Quadrat, keine Pillen */
.state { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.state::before { content: ""; width: 7px; height: 7px; background: currentColor; }
.state.s-entwurf { color: var(--ink-3); } .state.s-entwurf::before { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }
.state.s-offen { color: var(--ink); }
.state.s-teilbezahlt { color: var(--amber); }
.state.s-bezahlt { color: var(--green); }
.state.s-ueberfaellig { color: var(--crimson); }
.state.s-storniert, .state.s-verrechnet { color: var(--ink-3); }
.state.s-erstattung_offen { color: var(--crimson); }
.state.s-ausgestellt { color: var(--ink-2); }
.state.s-ausgestellt::before { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; border-radius: 0; }
.struck { text-decoration: line-through; color: var(--ink-3); }

/* Filterleiste */
.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius); overflow-x: auto; max-width: 100%; background: #fff; scrollbar-width: none; }
.seg button { flex: none; }
.seg button { border: 0; background: transparent; padding: 0 12px; height: 32px; font-size: 13px; cursor: pointer; color: var(--ink-2);
  border-right: 1px solid var(--line); display: inline-flex; gap: 6px; align-items: center; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--panel); }
.seg button[aria-pressed="true"] { background: var(--side); color: #fff; }
.seg .count { font-size: 11.5px; opacity: .75; font-variant-numeric: tabular-nums; }
.filter-search { position: relative; }
.filter-search input { height: 32px; width: 260px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: var(--radius); background: #fff; }
.op-filters { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(180px, 1.5fr) minmax(180px, 1.5fr); gap: 12px 16px; margin-bottom: 22px; }
.op-filters .actions { grid-column: 1 / -1; }
.op-table td:first-child { overflow-wrap: anywhere; min-width: 160px; }
#op-list { container-type: inline-size; }
/* Entscheidend ist die verfügbare Listenbreite, auch wenn die Seitenleiste wieder einblendet. */
@container (max-width: 850px) {
  table.op-table.stack thead { display: none; }
  table.op-table.stack, table.op-table.stack tbody, table.op-table.stack tr, table.op-table.stack td { display: block; width: 100%; }
  table.op-table.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--line-3); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 14px; }
  table.op-table.stack td, table.op-table.stack td.num { border: 0; padding: 1px 0; text-align: left; }
  table.op-table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; }
  table.op-table.stack td:first-child { grid-column: 1 / -1; min-width: 0; }
}
@media (max-width: 720px) {
  .op-filters { grid-template-columns: minmax(0, 1fr); }
  table.op-table.stack td:first-child { grid-column: 1 / -1; min-width: 0; }
}

/* Formulare */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .opt { font-weight: 400; color: var(--ink-3); }
.input, .field input[type="text"], .field input[type="password"], .field input[type="date"], .field input[type="email"], .field input[type="tel"], .field select, .field textarea,
.cell-input { height: 34px; padding: 0 10px; border: 1px solid #c9d0d5; border-radius: 3px; background: #fff; min-width: 0; width: 100%; }
.field textarea, textarea.cell-input { height: auto; padding: 7px 10px; resize: vertical; line-height: 1.45; }
.field select { padding-right: 28px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.invalid, .field .invalid { border-color: var(--crimson) !important; background: #fff8f8; }
.needs { border-color: #d8a144 !important; background: #fffcf5; }
.err { font-size: 12px; color: var(--crimson); font-weight: 550; }
.need-msg { font-size: 12px; color: var(--amber); }
.check { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; font-size: 13.5px; }
.check input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--side); flex: none; }
.grid { display: grid; gap: 14px 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .span4 { grid-column: 1 / -1; }
fieldset.group { border: 0; border-top: 1px solid var(--line); padding: 16px 0 6px; margin: 0; }
fieldset.group:first-of-type { border-top: 0; padding-top: 0; }
fieldset.group > legend { font-size: 14px; font-weight: 650; padding: 0; margin-bottom: 10px; float: left; width: 100%; }
fieldset.group > legend + * { clear: both; }
.radio-row { display: flex; gap: 6px 18px; flex-wrap: wrap; }
.radio-row label { display: inline-flex; gap: 7px; align-items: center; cursor: pointer; font-size: 13.5px; }
.radio-row input { accent-color: var(--side); width: 16px; height: 16px; margin: 0; }
.form-foot { display: flex; gap: 8px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--line); margin-top: 18px; }

/* ----------------------------------------------------------- Übersicht */
.ledger { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 0; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); }
.ledger > div { display: flex; justify-content: flex-start; align-items: baseline; gap: 12px; padding: 13px 20px; border-left: 1px solid var(--line); }
.ledger > div:first-child { border-left: 0; }
.ledger dt { font-size: 13px; color: var(--ink-2); }
.ledger dd { margin: 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ledger dd.alert { color: var(--crimson); }
.ledger-note { font-size: 12px; color: var(--ink-3); margin: 6px 2px 18px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.area-strip { margin-top: 18px; display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.area-strip > div { padding: 14px 18px; }
.area-strip > div + div { border-left: 1px solid var(--line); }
.area-strip h3 { font-size: 13.5px; font-weight: 650; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.area-strip dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; margin: 0; font-size: 13px; }
.area-strip dt { color: var(--ink-3); } .area-strip dd { margin: 0; font-variant-numeric: tabular-nums; }
.swatch-test { width: 22px; height: 10px; background: repeating-linear-gradient(-45deg, var(--amber-band) 0 4px, #2a3135 4px 8px); display: inline-block; }

/* ------------------------------------------------------------- Editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 288px; gap: 18px; align-items: start; }
.editor > *, .master > *, .two-col > * { min-width: 0; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .title { display: flex; flex-direction: column; }
.toolbar h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.save-state { font-size: 12.5px; color: var(--ink-3); }
.save-state.dirty { color: var(--amber); font-weight: 600; }
.sheet { background: var(--sheet); border: 1px solid var(--line); border-radius: 2px; box-shadow: var(--shadow-sheet);
  padding: 28px 30px 34px; font-family: var(--doc); font-size: 13px; color: #171717; max-width: 1060px; }
.sheet .field > label, .sheet .field > .label, .sheet .btn, .sheet .icon-btn, .sheet .radio-row label, .sheet .check,
.sheet .hint, .sheet a, .sheet .need-msg, .sheet .err, .sheet .meta-grid .k { font-family: var(--chrome); }
.sheet.issued .meta-grid .k, .sheet.issued .line-sub, .sheet.issued .ref-note { font-family: var(--doc); }
.sheet.issued .meta-grid .k { font-size: 12px; }
.inline-icon svg { vertical-align: -2px; margin-right: 3px; }
.sheet.issued { border: 1.5px solid var(--ink); }
.sheet.issued.storno { border-color: var(--crimson); }
.letterhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 14px; border-bottom: 1px solid var(--pdf-accent); margin: 0 -8px 16px; }
.letterhead img { width: 150px; height: auto; display: block; }
.letterhead address { font-style: normal; text-align: right; font-size: 11.5px; line-height: 1.5; color: #222; }
.letterhead address b { font-size: 12.5px; }
.sender-line { font-size: 10.5px; color: #444; margin: 0 0 12px; }
.head-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(250px, 300px); gap: 26px; margin-bottom: 20px; }
.recipient-box { min-height: 112px; }
.addr { font-size: 13.5px; line-height: 1.5; margin-top: 8px; }
.addr b { font-size: 14px; }
.addr .missing { color: var(--amber); font-family: var(--chrome); font-size: 12.5px; }
.meta-grid { display: grid; grid-template-columns: 104px 1fr; gap: 8px 10px; align-items: center; font-size: 12.5px; }
.meta-grid .k { color: #444; font-family: var(--chrome); font-size: 12.5px; }
.meta-grid .v { font-variant-numeric: tabular-nums; }
.inline-pair { display: flex; align-items: center; gap: 6px; }
.inline-pair { flex-wrap: nowrap; gap: 5px; font-size: 12.5px; }
.inline-pair input { width: 52px !important; text-align: right; padding: 0 7px; flex: none; }
.pair-gap { margin-left: 8px; }
.derived { font-size: 12px; color: var(--ink-2); font-family: var(--chrome); font-variant-numeric: tabular-nums; }
.site-box { border-top: 1px dashed var(--line); padding-top: 12px; margin-top: 12px; }
.doc-title { font-family: var(--doc); font-weight: 700; font-size: 19px; letter-spacing: .01em; margin: 10px 0 10px; }
.doc-title small { font-size: 12px; font-weight: 400; color: #555; margin-left: 10px; letter-spacing: 0; font-family: var(--chrome); }
.subject input { font-family: var(--doc); font-weight: 700; font-size: 14.5px; height: 38px; }
.lines-table { width: 100%; border-collapse: collapse; margin: 14px 0 6px; font-size: 12.5px; table-layout: fixed; }
.lines-table th { background: #ebebeb; text-align: left; font-weight: 700; font-size: 11px; padding: 7px 4px 7px 3px; border-bottom: 1px solid #c4c4c4; white-space: nowrap; }
.lines-table th.num { text-align: right; }
.lines-table td { padding: 7px 4px 7px 3px; border-bottom: 1px solid #dcdcdc; vertical-align: top; }
.lines-table td, .lines-table th { padding-left: 3px; padding-right: 4px; }
.lines-table th.col-vat, .lines-table td[data-label="USt."] { padding-left: 8px; }
.lines-table td.num { padding-top: 14px; }
.lines-table .pos { font-variant-numeric: tabular-nums; font-weight: 700; }
.lines-table col.w-pos { width: 68px; } .lines-table col.w-qty { width: 48px; } .lines-table col.w-unit { width: 62px; }
.lines-table col.w-price { width: 78px; } .lines-table col.w-markup { width: 70px; } .lines-table col.w-disc { width: 66px; } .lines-table col.w-vat { width: 64px; } .lines-table col.w-net { width: 84px; }
.lines-table td.c-pos { overflow: hidden; }
.c-pos .line-tools { display: flex; gap: 0; margin: 6px 0 0 -6px; }
.c-pos .icon-btn { width: 22px; height: 22px; }
.lines-table .kind { display: block; font-family: var(--chrome); font-size: 10px; line-height: 1.25; color: var(--ink-3); margin-top: 3px; overflow-wrap: anywhere; word-break: break-word; }
.lines-table .cell-input { height: 32px; padding: 0 5px; font-family: var(--doc); font-size: 12.5px; }
.lines-table textarea.cell-input { min-height: 32px; padding: 6px 7px; }
.lines-table .cell-input.right { text-align: right; font-variant-numeric: tabular-nums; }
.lines-table select.cell-input { padding: 0 2px 0 4px; }

.icon-btn { width: 28px; height: 28px; display: inline-grid; place-items: center; border: 1px solid transparent; background: transparent;
  border-radius: 3px; cursor: pointer; color: var(--ink-3); }
.icon-btn:hover { background: var(--panel); border-color: var(--line); color: var(--ink); }
.icon-btn[disabled] { opacity: .35; cursor: default; }
.line-sub { font-family: var(--chrome); font-size: 11.5px; color: var(--ink-3); margin-top: 4px; white-space: normal; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 18px; }
.sums { margin-left: auto; width: min(420px, 100%); font-size: 13px; }
.sums div { display: flex; justify-content: space-between; gap: 18px; padding: 5px 10px; font-variant-numeric: tabular-nums; }
.sums .tax { color: #444; font-size: 12px; }
.sums .total { background: #ebebeb; border-top: 1px solid #171717; font-weight: 700; font-size: 13.5px; padding: 7px 10px; }
.sums .skonto { font-size: 12px; color: var(--ink-2); font-family: var(--chrome); }
.texts { display: grid; gap: 12px; margin-top: 18px; }
.scope { margin-top: 18px; padding: 12px 14px; border: 1px solid var(--line); background: #fafbfb; border-radius: 3px; font-family: var(--chrome); }
/* Steuerfall: zwei Zeilen zur Wahl, Bescheinigungsstand als Text mit Quadrat (Quadrat-Regel), Bestätigung darunter */
.scope .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.tax-cases { display: flex; flex-direction: column; gap: 8px; margin: 7px 0 10px; }
.tax-cases label { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; font-size: 13.5px; line-height: 1.4; }
.tax-cases small { display: block; font-size: 12.5px; color: var(--ink-3); }
.nb { white-space: nowrap; }
.tax-cases input { accent-color: var(--side); width: 16px; height: 16px; margin: 2px 0 0; flex: none; }
.scope-state { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; color: var(--amber); margin: 0 0 8px 25px; }
.scope-state::before { content: ""; width: 7px; height: 7px; flex: none; box-shadow: inset 0 0 0 1.5px currentColor; }
.scope-state.ok { color: var(--ink-2); }
.scope-state.ok::before { background: currentColor; box-shadow: none; }
.scope .check.rc-extra { margin: 0 0 10px 25px; }
.scope .check.confirm { padding-top: 10px; border-top: 1px solid var(--line-3); }
.vat-none { display: inline-block; padding-top: 7px; font-family: var(--chrome); font-size: 12px; color: var(--ink-3); }
.sums .rc-note { justify-content: flex-start; padding-top: 9px; font-weight: 700; font-size: 12.5px; }
/* Auftrag: Schlussrechnung mit Abzügen, Folgebeleg mit Bezug */
.sums .total.sub { background: none; border-top: 1px solid var(--line-2); font-size: 13px; }
.sums .deduct { font-size: 12px; color: #444; }
.sums .deduct a { color: inherit; }
.sums .deduct-detail { font-size: 11.5px; color: var(--ink-3); padding-top: 0; }
.sums .deduct-note { font-family: var(--chrome); font-size: 12px; color: var(--amber); justify-content: flex-start; padding-top: 8px; }
.sums div > :last-child:not(:first-child) { white-space: nowrap; }   /* Beträge nie vor dem € umbrechen */
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.rail-list { padding: 4px 8px 0; font-size: 12.5px; }
.kv-head { margin: 12px 0 0; font-size: 11.5px; font-weight: 600; color: var(--ink-3); }
.chain-note { margin-top: 8px; }
.lines-table tr.fixed td { padding-top: 10px; padding-bottom: 10px; }
.order-balance { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line-3); }
.upgrade { max-width: 720px; display: grid; gap: 10px; justify-items: start; }

/* Prüfleiste */
.rail { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 14px; overflow-x: clip; }
.rail .panel h2 { font-size: 13.5px; font-weight: 650; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: baseline; }
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.checklist button { text-align: left; width: 100%; background: none; border: 0; padding: 6px 8px; border-radius: 3px; cursor: pointer;
  display: grid; grid-template-columns: 10px 1fr; gap: 8px; font-size: 12.5px; line-height: 1.4; color: var(--ink); }
.checklist button:hover { background: var(--panel); }
.checklist button::before { content: ""; width: 7px; height: 7px; margin-top: 5px; background: var(--amber-band); }
.checklist .scope-company::before { background: var(--crimson); }
.checklist .grp { font-size: 11.5px; color: var(--ink-3); padding: 8px 8px 2px; }
.rail-grp { margin: 12px 0 0; padding: 0 8px; font-size: 11.5px; color: var(--ink-3); }
.rail .hint.stale { color: var(--amber); }
.rail-note { display: grid; grid-template-columns: 10px 1fr; gap: 8px; margin: 10px 0 0; padding: 0 8px; font-size: 12.5px; line-height: 1.4; color: var(--ink-2); }
.rail-note::before { content: ""; width: 7px; height: 7px; margin-top: 5px; box-shadow: inset 0 0 0 1.5px var(--amber-band); }
.ready { display: flex; gap: 10px; align-items: flex-start; }
.ready svg { color: var(--green); flex: none; margin-top: 1px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12.5px; margin: 0; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.kv dd.left { text-align: left; }
.states { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; font-size: 12.5px; }
.states dt { color: var(--ink-3); } .states dd { margin: 0; }

/* Ausgestellte Belege */
.stamp { border: 1.5px solid var(--ink); border-radius: 3px; padding: 10px 12px; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px;
  align-items: center; font-family: var(--doc); }
.stamp svg { grid-row: span 2; color: var(--ink); }
.stamp .no { font-size: 17px; font-weight: 700; letter-spacing: .02em; }
.stamp .when { font-size: 11px; color: #444; font-family: var(--chrome); }
.stamp.storno { border-color: var(--crimson); color: var(--crimson); }
.stamp.storno svg { color: var(--crimson); }
.stamp.fresh { animation: stamp .42s cubic-bezier(.2, .9, .25, 1) both; }
@keyframes stamp { 0% { transform: scale(1.18) rotate(-2.5deg); opacity: 0; } 55% { opacity: 1; } 100% { transform: none; opacity: 1; } }
.paybar { display: flex; height: 8px; background: #fff; border: 1px solid var(--line-2); margin: 10px 0 8px; }
.paybar span { display: block; height: 100%; }
.paybar .paid { background: var(--green); }

.lines-read { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 12px 0 4px; }
.lines-read th { background: #ebebeb; text-align: left; font-size: 11.5px; padding: 7px 6px; border-bottom: 1px solid #c4c4c4; }
.lines-read th.num { text-align: right; }
.lines-read td { padding: 7px 6px; border-bottom: 1px solid #dcdcdc; vertical-align: top; }
.payments td .rev { color: var(--ink-3); font-size: 12px; }
.payments tr.reversed td { color: var(--ink-3); }
/* Engere Innenabstände und Silbentrennung im Vermerk, damit „Gegenbuchen …“ auch neben der rechten Leiste ganz sichtbar bleibt */
table.payments th, table.payments td { padding-left: 8px; padding-right: 8px; }
table.payments td:nth-child(3) { -webkit-hyphens: auto; hyphens: auto; }
table.payments td a { white-space: nowrap; }   /* Belegnummern nie umbrechen */
table.payments th:first-child, table.payments td:first-child { padding-left: 12px; }
table.payments th:last-child, table.payments td:last-child { padding-right: 12px; }
#form-msg .notice { margin-bottom: 14px; }
.history { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.history li { display: grid; grid-template-columns: 128px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line-3); }
.history li:last-child { border-bottom: 0; }
.history time { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ref-note { font-family: var(--chrome); font-size: 12.5px; margin: 0 0 10px; }

/* Katalog / Kunden */
.master { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.form-panel { position: sticky; top: 76px; }
.form-panel h2 { font-size: 15px; font-weight: 650; margin-bottom: 12px; }
.sites { display: flex; flex-direction: column; gap: 10px; }
.site-row { display: grid; grid-template-columns: 1.1fr 1.5fr 1.2fr .6fr 1fr auto; gap: 8px; align-items: end; padding: 10px; border: 1px solid var(--line-3); background: #fafbfb; border-radius: 3px; }
.picker-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 3px; }
.picker-list button { width: 100%; text-align: left; display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; padding: 9px 12px; border: 0;
  border-bottom: 1px solid var(--line-3); background: #fff; cursor: pointer; font-size: 13px; }
.picker-list li:last-child button { border-bottom: 0; }
.picker-list button:hover, .picker-list button:focus-visible { background: var(--panel); }
.picker-list .no { color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* Dialog */
.dialog { border: 0; padding: 0; border-radius: 6px; box-shadow: var(--shadow-pop); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); color: var(--ink); }
.dialog.wide { width: min(1100px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(18, 23, 26, .48); }
.dialog[open] { animation: rise .2s cubic-bezier(.2, .8, .3, 1); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 16px; font-weight: 650; }
.dlg-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; max-height: calc(100vh - 170px); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel); border-radius: 0 0 6px 6px; }
.issue-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; }
.pdf-frame { display: block; width: 100%; height: min(70vh, 760px); border: 1px solid var(--line); background: #e9ecee; border-radius: 3px; }
.pdf-fallback { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 24px;
  background: var(--panel); color: var(--ink-2); }

/* Meldung */
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; padding: 11px 14px; border-radius: 4px; background: var(--side); color: #fff;
  font-size: 13px; box-shadow: var(--shadow-pop); transform: translateY(14px); opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 60; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #7d161c; }
.toast.warn { background: var(--amber); }
.menu { position: absolute; right: 0; top: 40px; background: #fff; border: 1px solid var(--line); border-radius: 4px; box-shadow: var(--shadow-pop);
  min-width: 220px; padding: 6px; z-index: 30; display: none; }
.menu.open { display: block; }
.menu a { display: grid; grid-template-columns: 18px 1fr; gap: 9px; align-items: center; padding: 8px 10px; border-radius: 3px; text-decoration: none; font-size: 13.5px; }
.menu a:hover, .menu a:focus-visible { background: var(--panel); }
.menu small { display: block; color: var(--ink-3); font-size: 11.5px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Positionen als Blöcke, sobald die Tabelle schmaler als 760 px würde (Blatt neben der Prüfleiste bis rund 1430 px,
   ohne Prüfleiste bis rund 1125 px bzw. 825 px): neben den festen Zahlenspalten bliebe der Beschreibung sonst zu wenig
   Platz. Breite Blätter behalten die Tabelle; das Telefon (bis 720 px) behält seine zwei Spalten weiter unten. */
.lines-wrap { container: lines / inline-size; margin-top: 14px; }
.lines-wrap .lines-table { margin: 0 0 6px; }
@media (min-width: 721px) {
  @container lines (max-width: 759px) {
    .lines-table, .lines-table tbody, .lines-table tr, .lines-table td { display: block; width: 100%; }
    .lines-table thead { display: none; }
    .lines-table tr { border: 1px solid #dcdcdc; border-radius: 3px; padding: 6px 10px 10px; margin-bottom: 10px; display: grid;
      grid-template-columns: repeat(6, minmax(0, 1fr)) minmax(0, 1.2fr); gap: 0 6px; }
    .lines-table td, .lines-table td.num, .lines-table tr.fixed td, .lines-table td[data-label="USt."] { border: 0; padding: 3px 0; }
    .lines-table td[data-label]::before { content: attr(data-label); display: block; font-family: var(--chrome); font-size: 11px; color: var(--ink-3);
      margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .lines-table td.c-pos, .lines-table td.c-desc, .lines-table td.empty { grid-column: 1 / -1; }
    .lines-table td.c-pos { display: flex; gap: 8px; align-items: baseline; }
    /* Positionssumme wie in der Tabelle rechtsbündig, Wert auf der Linie der Feldwerte (Feldhöhe 32 px) */
    .lines-table td.c-net { text-align: right; }
    .lines-table td.c-net > [data-out^="net-"] { display: block; line-height: 32px; }
    /* Feste Abschlagszeile: Werte wie die Beschriftungen linksbündig, leerer Rabatt als Strich */
    .lines-table tr.fixed td.num:not(.c-net) { text-align: left; }
    .lines-table tr.fixed td:empty::after { content: "–"; }
    .lines-table td[data-label="Einzelpreis netto"]::before { content: "EP netto"; }   /* wie im Tabellenkopf, passt in die Spalte */
    .lines-table td[data-label="Aufschlag %"]::before { content: "Aufschl. %"; }
    .c-pos .line-tools { margin: 0 0 0 auto; }
  }
}

/* ------------------------------------------------------- Breakpoints */
@media (max-width: 1240px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); order: -1; }
  .master { grid-template-columns: minmax(0, 1fr); }
  .form-panel { position: static; }
  .two-col { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 272px; transform: translateX(-100%); transition: transform .22s ease; }
  .app.nav-open .side { transform: none; box-shadow: var(--shadow-pop); }
  .topbar .menu-toggle { display: inline-grid; }
  .topbar { padding: 0 14px; gap: 10px; }
  .main { padding: 18px 16px 56px; }
  .sheet { padding: 20px 16px 24px; }
  .letterhead { margin: 0 0 14px; }
  .issue-grid { grid-template-columns: minmax(0, 1fr); }
  .area-strip { grid-template-columns: 1fr; }
  .area-strip > div + div { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 720px) {
  .vat-none { padding-top: 0; }
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
  .search { display: none; }
  .crumbs { display: none; }
  .area-flag { margin-left: auto; }
  .head-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .letterhead address { display: none; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3 { grid-column: auto; }
  .site-row { grid-template-columns: 1fr 1fr; }
  .filter-search input { width: 100%; }
  .seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; overflow: visible; }
  .seg button { justify-content: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .seg button:nth-child(3n) { border-right: 0; }
  .seg button:nth-last-child(-n+3) { border-bottom: 0; }
  .filter-search { flex: 1 1 100%; }
  .ledger { grid-template-columns: minmax(0, 1fr); }
  .ledger > div { border-left: 0; border-top: 1px solid var(--line-3); justify-content: space-between; padding: 12px 16px; }
  .ledger > div:first-child { border-top: 0; }
  /* Positionen als gestapelte Blöcke mit sichtbaren Beschriftungen */
  .lines-table, .lines-table tbody, .lines-table tr, .lines-table td { display: block; width: 100%; }
  .lines-table thead { display: none; }
  .lines-table tr { border: 1px solid #d6d6d6; border-radius: 3px; padding: 8px 10px 4px; margin-bottom: 10px; display: grid;
    grid-template-columns: 1fr 1fr; gap: 0 10px; }
  .lines-table td, .lines-table td[data-label="USt."] { border: 0; padding: 4px 0; }
  .lines-table td[data-label]::before { content: attr(data-label); display: block; font-family: var(--chrome); font-size: 11px; color: var(--ink-3); margin-bottom: 2px; }
  .lines-table td.c-pos { grid-column: 1 / -1; display: flex; gap: 8px; align-items: baseline; }
  .lines-table td.empty { grid-column: 1 / -1; }
  .lines-table td.c-desc { grid-column: 1 / -1; }
  .lines-table td.c-net { grid-column: 1 / -1; text-align: left; padding-top: 4px; }
  .c-pos .line-tools { margin: 0 0 0 auto; }
  .lines-read thead { display: none; }
  .lines-read, .lines-read tbody { display: block; width: 100%; }
  .lines-read tr { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px 10px; padding: 9px 0; border-bottom: 1px solid #dcdcdc; }
  .lines-read td { display: block; border: 0; padding: 0; }
  .lines-read td.c-pos { grid-column: 1 / 2; font-weight: 700; }
  .lines-read td.c-desc { grid-column: 2 / -1; }
  .lines-read td.num { text-align: left; }
  .lines-read td.c-net { grid-column: 1 / -1; text-align: right; font-weight: 700; }
  .lines-read td[data-label]::before { content: attr(data-label); display: block; font-family: var(--chrome); font-size: 10.5px; font-weight: 400; color: var(--ink-3); }
  .lines-read td.c-net::before { display: inline; margin-right: 8px; }
  table.list.stack thead { display: none; }
  table.list.stack, table.list.stack tbody, table.list.stack tr, table.list.stack td { display: block; width: 100%; }
  table.list.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--line-3); display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
  table.list.stack td { border: 0; padding: 1px 0; text-align: left; }
  table.list.stack td.num { text-align: left; }
  table.list.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; }
  table.list.stack td.hide-s { display: none; }
  .stamp.fresh { animation-name: stamp-narrow; }
}
@keyframes stamp-narrow { 0% { transform: scale(1.03); opacity: 0; } 55% { opacity: 1; } 100% { transform: none; opacity: 1; } }

/* Rechnungsliste (#list-body): bei mittleren Breiten zuerst Betreff ausblenden, ab 900 px Listenbreite stapeln (N3). */
#list-body { container-type: inline-size; }
@container (max-width: 1120px) {
  #list-body table.list .hide-s { display: none; }
}
@container (max-width: 900px) {
  #list-body table.list.stack thead { display: none; }
  #list-body table.list.stack, #list-body table.list.stack tbody, #list-body table.list.stack tr, #list-body table.list.stack td { display: block; width: 100%; }
  #list-body table.list.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--line-3); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 14px; }
  #list-body table.list.stack td, #list-body table.list.stack td.num { border: 0; padding: 1px 0; text-align: left; }
  #list-body table.list.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; }
  #list-body table.list.stack td:first-child, #list-body table.list.stack td:nth-child(2) { grid-column: 1 / -1; min-width: 0; }
  #list-body table.list.stack td.hide-s { display: none; }
}

/* Teilkorrektur: Position und Menge bleiben im Belegzusammenhang. */
.correction-line {display:grid;grid-template-columns:minmax(0,1fr) 165px;gap:16px;padding:14px 0;border-bottom:1px solid var(--line);align-items:start}
.correction-line b {overflow-wrap:anywhere}
@media(max-width:600px){.correction-line{grid-template-columns:1fr;gap:8px}.correction-line .field{max-width:220px}}

/* Mahnwesen: Forderung, Frist und unveränderlicher Beleg statt zusätzlicher Kennzahlenkarten. */
.dunning-table {table-layout:fixed}
.dunning-table th:first-child {width:25%}
.dunning-table td {overflow-wrap:anywhere}
.dunning-documents,.dunning-events {list-style:none;padding:0;margin:0}
.dunning-documents li {display:flex;justify-content:space-between;gap:20px;padding:14px 0;border-top:1px solid var(--line);overflow-wrap:anywhere}
.dunning-documents li>div:last-child {text-align:right;flex-shrink:0}
.dunning-events li {padding:12px 0;border-top:1px solid var(--line)}
.dunning-events p {margin:4px 0;overflow-wrap:anywhere}
.pre-wrap {white-space:pre-wrap;overflow-wrap:anywhere}
.dunning-config-head {display:flex;align-items:center;gap:26px;margin-bottom:10px;flex-wrap:wrap}
.dunning-config-head .field {max-width:180px}
.dunning-preview {border-top:1px solid var(--line);padding-top:18px;margin-top:18px}
.dunning-document {max-width:960px;font-family:var(--doc);overflow-wrap:anywhere}
.dunning-letterhead {display:flex;justify-content:space-between;align-items:center;gap:20px;padding-bottom:16px;border-bottom:2px solid var(--pdf-accent);margin-bottom:30px}
.dunning-letterhead img {object-fit:contain}
.dunning-amounts {max-width:480px;margin:24px 0 24px auto;border-top:1px solid var(--line);padding-top:12px}
@media(max-width:720px){
  .dunning-documents li {display:block}
  .dunning-documents li>div:last-child {text-align:left;margin-top:8px}
  .dunning-letterhead {align-items:flex-start;gap:12px}
  .dunning-letterhead img {width:110px;height:auto}
  .dunning-letterhead>div {font-size:12px}
  .dunning-table tr td:first-child,.dunning-table tr td:last-child {grid-column:1/-1}
}

@media(max-width:600px){
  .dunning-dialog .dlg-foot {flex-wrap:wrap}
  .dunning-dialog .dlg-foot .btn {flex:1 1 auto}
  .dunning-dialog .dlg-body {max-height:calc(100vh - 240px)}
}

/* Belegsalden nutzen dieselbe Containerdarstellung wie die offenen Posten. */
.balance-list { container-type: inline-size; }
.balance-table { table-layout: fixed; }
.balance-table td { overflow-wrap: anywhere; }
#offer-list .balance-table th:first-child { width: 14%; }
#offer-list .balance-table th:nth-child(2) { width: 18%; }
#offer-list .balance-table th:nth-child(3) { width: 8%; }
#offer-list .balance-table th:nth-child(n+4) { width: 12%; }
.alert { color: var(--crimson); }
@container (max-width: 1200px) {
  table.balance-table.stack thead { display: none; }
  table.balance-table.stack, table.balance-table.stack tbody, table.balance-table.stack tr, table.balance-table.stack td { display: block; width: 100%; }
  table.balance-table.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--line-3); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 14px; }
  table.balance-table.stack td, table.balance-table.stack td.num { border: 0; padding: 1px 0; text-align: left; }
  table.balance-table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; }
  table.balance-table.stack td:first-child, #offer-list table.balance-table.stack td:nth-child(2) { grid-column: 1 / -1; min-width: 0; }
}

/* Lange Formulare scrollen nur in den Feldern; Ergebnis und Aktionen bleiben sichtbar. */
.dialog[open] { display: flex; flex-direction: column; overflow: hidden; }
.dlg-head, .dlg-foot { flex-shrink: 0; }
.dlg-body { min-height: 0; flex: 1 1 auto; }
.dlg-body > * { flex-shrink: 0; }
.dunning-config-dialog .dlg-foot, .correction-dialog .dlg-foot { flex-direction: column; align-items: stretch; }
.dunning-config-dialog .dlg-foot .actions, .correction-dialog .dlg-foot .actions { justify-content: flex-end; flex-wrap: wrap; }
.correction-dialog .dlg-foot .btn { flex-shrink: 0; min-height: 34px; }
.correction-dialog #corr-preview { align-self: flex-start; }
.correction-dialog #corr-summary .kv { margin-top: 0 !important; }
.correction-dialog #corr-summary .check { margin-top: 8px; }
.dunning-case > .panel + .panel { margin-top: 0; }
.dunning-case .actions { margin-top: 12px; }
.lines-table tr.fixed td[data-label="Einzelpreis netto"] { white-space: nowrap; }
@media (min-width: 721px) {
  @container lines (max-width: 759px) {
    .lines-table tr.fixed { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  }
}
@media (max-width: 720px) {
  .lines-table tr.fixed td[data-label="Einzelpreis netto"] { grid-column: 1 / -1; }
}

/* Echtbetrieb: Hinweis vor der ersten Rechnung (Übersicht) und Datensicherung (Firmeneinstellungen). */
.setup-note { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) auto; gap: 12px 24px; align-items: center; margin-bottom: 16px;
  padding: 14px 18px; border: 1px solid #ecd3a3; border-radius: var(--radius); background: var(--amber-wash); color: #5d3b00; }
.setup-note h2 { font-size: 14.5px; font-weight: 650; margin: 0 0 4px; color: var(--ink); }
.setup-note p { margin: 0; font-size: 13px; }
.setup-note dl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; margin: 0; font-size: 13px; color: var(--ink); }
.setup-note dd { margin: 0; }
.backup-kv { grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; font-size: 13px; margin-bottom: 12px; }
.backup-kv code, .backup-kv .small { overflow-wrap: anywhere; }

/* Webbetrieb: Anmeldung, Passwortwechsel und Benutzersteuerung */
.app.auth-view { display: block; }
.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
  background-color: #161b1f;
  background-image:
    linear-gradient(180deg, rgba(22, 27, 31, .44) 0%, rgba(22, 27, 31, .30) 48%, rgba(22, 27, 31, .60) 100%),
    url("/assets/login-bg.jpg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}
.auth-card {
  width: min(440px, 100%);
  background: rgba(255, 255, 255, .97);
  border: 1px solid rgba(255, 255, 255, .6);
  border-top: 3px solid var(--red);
  border-radius: 6px;
  box-shadow: 0 24px 56px -18px rgba(10, 14, 18, .68), 0 4px 14px rgba(10, 14, 18, .22);
  padding: 26px 26px 22px;
  backdrop-filter: blur(8px);
}
.auth-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.auth-head img { display: block; width: 132px; height: auto; }
.auth-head-meta { font-size: 11.5px; color: var(--ink-3); text-align: right; line-height: 1.35; }
.auth-card h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; margin: 0 0 6px; }
.auth-sub { font-size: 13px; color: var(--ink-2); margin: 0 0 16px; line-height: 1.5; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-turnstile { min-height: 65px; display: flex; justify-content: center; align-items: center; margin: 2px 0; }
.auth-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.auth-actions .btn.primary { width: 100%; justify-content: center; height: 38px; }
.auth-actions.auth-actions-split .btn.primary { flex: 1 1 auto; width: auto; }
.auth-actions.auth-actions-split .btn.quiet { flex: none; height: 38px; }
.auth-note { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-3); font-size: 12px; color: var(--ink-3); line-height: 1.45; }

.side-mode { margin-bottom: 6px; font-size: 11px; color: var(--amber-band); letter-spacing: .01em; }
.side-user { margin-top: 2px; color: var(--side-ink); overflow-wrap: anywhere; }
.side-role { color: var(--side-dim); font-size: 11px; }
.side-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.side-btn { appearance: none; border: 1px solid var(--side-line); background: var(--side-2); color: var(--side-ink); border-radius: 3px; padding: 4px 8px; font-size: 11.5px; cursor: pointer; font-family: inherit; }
.side-btn:hover { background: var(--side-3); color: #fff; border-color: #4b575f; }
.role-table td, .users-table td, .report-table td { overflow-wrap: anywhere; }
.report-presets { margin-bottom: 14px; }
.report-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 12px 16px; align-items: end; margin-bottom: 18px; }
.report-filters .actions { align-self: end; }
.account-sessions { list-style: none; margin: 0 0 12px; padding: 0; }
.account-sessions li { padding: 10px 0; border-top: 1px solid var(--line-3); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.account-sessions li:first-child { border-top: 0; padding-top: 0; }
@media (max-width: 720px) {
  .auth-card { padding: 18px 16px; }
  .auth-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .auth-head-meta { text-align: left; }
  .report-filters { grid-template-columns: minmax(0, 1fr); }
  .report-presets .seg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
#backup-panel .actions { margin-bottom: 10px; }
.company-extra > .panel + .panel { margin-top: 0; }    /* nebeneinander bündig; der Rasterabstand trennt auch untereinander */
.area-strip .strip-link { margin: 8px 0 0; }
@media (max-width: 1240px) {
  .setup-note { grid-template-columns: minmax(0, 1fr); }
  .setup-note .btn { justify-self: start; }
}
@media (max-width: 720px) {
  /* Ohne Testkennzeichnung bleibt „Neu“ rechts, wie im Testbestand neben dem Musterfeld. */
  .topbar.echt .new-wrap { margin-left: auto; }
}

/* Hauskatalog: Produktbilder */
.cat-img-box { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.cat-thumb-wrap { width: 76px; height: 76px; flex: none; background: var(--sheet); border: 1px solid var(--line); border-radius: 3px; display: grid; place-items: center; overflow: hidden; }
.cat-thumb { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.cat-thumb-empty { min-height: 32px; display: flex; align-items: center; }
.cat-img-controls { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.cat-img-controls .b-file-box { width: 100%; min-width: 0; }
.cat-img-readonly { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.cat-img-readonly .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.cat-img-tag { display: inline-flex; align-items: center; gap: 3px; margin-left: 6px; padding: 1px 5px; font-size: 11px; color: var(--ink-2); background: var(--panel); border: 1px solid var(--line); border-radius: 2px; vertical-align: middle; }

/* Großhandel (Collin) & Entwurfs-Auswahldialog */
.gh-picker-bar { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(180px, 1fr); gap: 10px 12px; align-items: end; }
.gh-picker-list button { grid-template-columns: minmax(84px, auto) minmax(0, 1fr) auto; align-items: center; }
.gh-picker-list .num .small { white-space: normal; }
.gh-pager { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 12px; padding: 10px 14px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius); }
.gh-kv { margin-top: 0; padding-top: 0; border-top: 0; }
.gh-copy-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.gh-longtext-wrap { display: flex; flex-direction: column; gap: 4px; }
.gh-longtext { padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 200px; overflow-y: auto; }
.gh-adopt-box { display: flex; flex-direction: column; gap: 12px; background: var(--panel); }
.gh-price-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 16px; font-variant-numeric: tabular-nums; }
.gh-adopt-form { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; padding-top: 10px; border-top: 1px solid var(--line); }
.gh-adopt-form .field { width: 140px; }

/* Position-Metadaten, interne Kalkulation & Marktanalyse */
.line-meta { font-family: var(--chrome); font-size: 11.5px; line-height: 1.35; color: var(--ink-3); margin-top: 5px; display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; overflow-wrap: anywhere; }
.line-meta-collin { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.line-meta-market { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-variant-numeric: tabular-nums; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: inherit; color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font-weight: 550; }
.link-btn:hover { color: var(--ink); }
.calc-internal { margin: 12px 0 0 auto; width: min(440px, 100%); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 9px 12px; font-family: var(--chrome); font-size: 12.5px; }
.calc-internal:empty { display: none; }
.calc-internal-head { font-size: 11.5px; font-weight: 650; color: var(--ink-2); padding-bottom: 5px; margin-bottom: 5px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.calc-internal-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.calc-internal-row > :last-child { text-align: right; white-space: nowrap; }
.calc-internal-row .ok { color: var(--green); }
.calc-internal-row .alert { color: var(--crimson); }
.mkt-head { display: flex; flex-direction: column; gap: 8px; }
.mkt-title { font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.mkt-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-variant-numeric: tabular-nums; }
.mkt-metrics > div { background: var(--sheet); padding: 9px 12px; min-width: 0; }
.mkt-metrics .small.muted { display: block; margin-bottom: 2px; }
.mkt-summary { margin: 0; color: var(--ink-2); line-height: 1.5; }
.mkt-sources { display: flex; flex-direction: column; gap: 4px; }
.mkt-sources ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; }
.mkt-sources a { color: var(--ink); overflow-wrap: anywhere; }
.mkt-links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mkt-calc { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.mkt-calc h3 { font-size: 13.5px; font-weight: 650; margin: 0; }
.mkt-calc-row { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-end; }
.mkt-calc-row .field { width: min(260px, 100%); }
.mkt-calc-preview { flex: 1 1 100%; line-height: 1.4; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mkt-calc-actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 720px) {
  .gh-picker-bar { grid-template-columns: minmax(0, 1fr); }
  .gh-picker-list button { grid-template-columns: minmax(0, 1fr) auto; }
  .gh-picker-list button .no { grid-column: 1 / -1; font-size: 11.5px; }
  .gh-picker-list .num { white-space: normal; }
  .gh-price-row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .gh-adopt-form .field { width: 100%; }
  .gh-adopt-form .btn { width: 100%; justify-content: center; }
  .cat-img-controls { flex-basis: 100%; }
  .calc-internal-row { flex-wrap: wrap; }
  .calc-internal-row > :last-child { white-space: normal; }
  .mkt-calc-row .field { width: 100%; }
  .mkt-calc-actions .btn { width: 100%; justify-content: center; }
}
