:root {
  --hintergrund: #f6f4f0;
  --flaeche: #ffffff;
  --text: #22201c;
  --text-leise: #6b655c;
  --linie: #e2ddd4;
  --akzent: #8a5a2b;
  --akzent-dunkel: #6e4620;
  --akzent-hell: #f3e8dc;
  --gut: #2f7a4a;
  --gut-hell: #e3f1e7;
  --warnung: #9a6a00;
  --warnung-hell: #fbf0d6;
  --fehler: #b3261e;
  --fehler-hell: #fbe4e2;
  --radius: 8px;
  --schatten: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--hintergrund); color: var(--text); line-height: 1.45; }
a { color: var(--akzent); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.leise { color: var(--text-leise); }
.rechts { text-align: right; }
.zahl { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------------------- Kopf */
.kopf {
  display: flex; align-items: center; gap: 1.5rem; padding: 0 1.5rem;
  background: var(--flaeche); border-bottom: 1px solid var(--linie); position: sticky; top: 0; z-index: 5;
  flex-wrap: wrap;
}
.marke { font-weight: 700; padding: .9rem 0; white-space: nowrap; }
.navigation { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.navigation a {
  padding: .9rem .6rem; text-decoration: none; color: var(--text-leise); border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.navigation a:hover { color: var(--text); }
@media (max-width: 1360px) {   /* elf Bereiche passen nicht neben Firmenname und Benutzer: eigene Zeile */
  .marke { flex: 1; }
  .navigation { order: 3; flex-basis: 100%; margin-top: -.5rem; }
  .navigation a { padding-top: .5rem; }
}
.navigation a.aktiv { color: var(--akzent); border-bottom-color: var(--akzent); font-weight: 600; }
.benutzer { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--text-leise); }
.benutzer[hidden], body.abgemeldet .navigation { display: none; }
.anmeldung { max-width: 360px; margin: 4rem auto; }
.anmeldung .feld { margin-bottom: .75rem; }
.anmeldung input { width: 100%; }

.inhalt { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.titelzeile { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.titelzeile .aktionen { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Flächen */
.karte { background: var(--flaeche); border: 1px solid var(--linie); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--schatten); margin-bottom: 1.25rem; }
.raster { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kennzahlen { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 1.25rem; }
.kennzahl { background: var(--flaeche); border: 1px solid var(--linie); border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--schatten); text-decoration: none; color: inherit; display: block; }
a.kennzahl:hover { border-color: var(--akzent); }
.kennzahl .wert { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kennzahl .bezeichnung { color: var(--text-leise); font-size: .85rem; }
.kennzahl .zusatz { font-size: .85rem; margin-top: .25rem; }
.leer { color: var(--text-leise); padding: 1rem 0; }

/* ---------------------------------------------------------------- Tabellen */
.tabelle-huelle { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--linie); text-align: left; vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-leise); font-weight: 600; }
tbody tr.klickbar { cursor: pointer; }
tbody tr.klickbar:hover { background: var(--akzent-hell); }
tfoot td { font-weight: 600; border-bottom: none; }

/* ---------------------------------------------------------------- Formulare */
input, select, textarea {
  font: inherit; padding: .45rem .6rem; border: 1px solid var(--linie); border-radius: 6px; background: #fff; color: inherit; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--akzent); outline-offset: -1px; border-color: var(--akzent); }
label.feld { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--text-leise); }
label.feld > input, label.feld > select, label.feld > textarea { color: var(--text); font-size: .95rem; }
label.haken { display: flex; align-items: center; gap: .5rem; }
.felder { display: grid; gap: .75rem 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.felder .breit { grid-column: 1 / -1; }
.positionen input { width: 100%; }
.positionen td { padding: .3rem; }
.positionen .menge { width: 6rem; }
.positionen .einheit { width: 7.5rem; }
.positionen .preis { width: 8rem; }
.positionen .art { width: 9rem; }
.positionen .satz { width: 5rem; }

button, .knopf {
  font: inherit; padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--linie); background: var(--flaeche);
  color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap;
}
button:hover, .knopf:hover { border-color: var(--akzent); }
button.haupt, .knopf.haupt { background: var(--akzent); border-color: var(--akzent); color: #fff; }
button.haupt:hover, .knopf.haupt:hover { background: var(--akzent-dunkel); }
button.gefahr { color: var(--fehler); }
button.klein { padding: .25rem .55rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
.knopfzeile { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------------------------------------------------------------- Status */
.marke-status { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; background: var(--linie); color: var(--text); }
.marke-status.gut { background: var(--gut-hell); color: var(--gut); }
.marke-status.warnung { background: var(--warnung-hell); color: var(--warnung); }
.marke-status.fehler { background: var(--fehler-hell); color: var(--fehler); }
.marke-status.akzent { background: var(--akzent-hell); color: var(--akzent-dunkel); }

.kette { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.kette .glied { padding: .35rem .6rem; border: 1px solid var(--linie); border-radius: 6px; font-size: .85rem; background: #fff; }
.kette .glied b { display: block; }
.kette .pfeil { color: var(--text-leise); }

.hinweis { background: var(--akzent-hell); border-radius: 6px; padding: .6rem .8rem; font-size: .9rem; }

/* ---------------------------------------------------------------- Upload */
.ablage {
  display: block; border: 2px dashed var(--linie); border-radius: var(--radius); padding: 1.5rem; text-align: center; color: var(--text-leise); cursor: pointer; background: var(--flaeche);
}
.ablage.ueber { border-color: var(--akzent); background: var(--akzent-hell); }

/* ---------------------------------------------------------------- Dialog */
dialog { border: none; border-radius: var(--radius); padding: 0; width: min(720px, 94vw); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog.weit { width: min(1150px, 96vw); }
dialog::backdrop { background: rgba(30, 25, 20, .45); }
dialog form, dialog .dialog-inhalt { padding: 1.25rem 1.5rem; }
dialog .dialog-fuss { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.pruefung { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.vorschau { border: 1px solid var(--linie); border-radius: 6px; min-height: 420px; background: #fafafa; overflow: auto; max-height: 70vh; }
.vorschau iframe, .vorschau img { width: 100%; border: 0; display: block; }
.vorschau iframe { height: 68vh; }
.vorschau pre { margin: 0; padding: .75rem; white-space: pre-wrap; font-size: .8rem; }
@media (max-width: 800px) { .pruefung { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- Meldungen */
.meldungen { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.meldung { background: var(--text); color: #fff; padding: .65rem 1rem; border-radius: 6px; max-width: 420px; box-shadow: var(--schatten); }
.meldung.fehler { background: var(--fehler); }
.meldung.gut { background: var(--gut); }

/* ---------------------------------------------------------------- Druckansicht (Angebot, Rechnung) */
.druck { display: none; }
.blatt { background: #fff; color: #000; padding: 2rem 2.5rem; font-size: 10.5pt; max-width: 800px; margin: 0 auto; }
.blatt .absenderzeile { font-size: 8pt; text-decoration: underline; color: #444; }
.blatt .briefkopf { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 2.5rem; }
.blatt .firma { text-align: right; font-size: 9pt; }
.blatt .firma b { font-size: 13pt; }
.blatt .empfaenger { margin-top: 1.5rem; }
.blatt h1 { font-size: 15pt; margin-bottom: .25rem; }
.blatt .meta { display: grid; grid-template-columns: auto auto; gap: 0 1rem; font-size: 9.5pt; margin-bottom: 1.5rem; justify-content: start; }
.blatt table th { color: #000; font-size: 8.5pt; border-bottom: 1.5px solid #000; }
.blatt table td { border-bottom: 1px solid #ddd; }
.blatt .summen { width: 55%; margin-left: auto; margin-top: 1rem; }
.blatt .summen td { border: none; padding: .2rem .6rem; }
.blatt .summen .gesamt td { border-top: 1.5px solid #000; font-weight: 700; }
.blatt .hinweise { margin-top: 1.5rem; font-size: 9pt; }
.blatt .fusszeile { margin-top: 2.5rem; padding-top: .5rem; border-top: 1px solid #ccc; font-size: 8pt; color: #444; display: flex; gap: 2rem; flex-wrap: wrap; }
.vorschau-blatt { border: 1px solid var(--linie); border-radius: var(--radius); box-shadow: var(--schatten); }

@media print {
  body { background: #fff; }
  body.drucken .kopf, body.drucken .inhalt, body.drucken .meldungen, body.drucken dialog { display: none !important; }
  body.drucken .druck { display: block; }
  .blatt { padding: 0; max-width: none; }
  @page { size: A4; margin: 18mm 18mm 15mm 22mm; }
}

@media (max-width: 700px) {
  .kopf { padding: 0 1rem; gap: .5rem; }
  .inhalt { padding: 1rem; }
  .benutzer span { display: none; }
  .marke { flex: 1; }
  .navigation { order: 3; flex-basis: 100%; }
  .navigation a { padding: .6rem .5rem; }
}

/* ---------------------------------------------------------------- Verwaltung */
.navigation a[hidden] { display: none; }
.matrix th, .matrix td.mitte { text-align: center; }
.matrix th:first-child { text-align: left; }
.matrix tr.gruppe td { background: var(--hintergrund); font-weight: 600; font-size: .85rem; }
.klein-text { font-size: .75rem; font-weight: 400; text-transform: none; letter-spacing: 0; }

/* Durch eine Korrektur ersetzter Beleg: bleibt sichtbar, gilt aber nicht mehr */
tr.ersetzt td { color: var(--text-leise); }
tr.ersetzt td:not(:first-child):not(.rechts) { text-decoration: line-through; }
.lohnimport { padding: .75rem 0; border-bottom: 1px solid var(--linie); }
.lohnimport .titelzeile { margin-bottom: .25rem; }
.lohnimport.ersetzt td { color: var(--text-leise); text-decoration: line-through; }

/* Standardbausteine */
.feld[hidden], tr[hidden] { display: none; }
.baustein-suche { min-width: min(100%, 360px); }
#bausteinzeilen td:first-child { white-space: nowrap; }

/* ---------------------------------------------------------------- Version und Hilfe */
.version { padding: .05rem .45rem; border: 1px solid var(--linie); border-radius: 999px; font-size: .75rem; font-variant-numeric: tabular-nums; }
.hilfe-knopf { width: 1.75rem; height: 1.75rem; padding: 0; border-radius: 50%; font-weight: 700; }
.hilfe h2 { font-size: 1.2rem; }
.hilfe h3 { font-size: .95rem; margin: 1rem 0 .35rem; }
.hilfe ol, .hilfe ul { margin: 0; padding-left: 1.25rem; }
.hilfe li { margin-bottom: .3rem; }
.hilfeseite .inhalt { max-width: 820px; }
.hilfeseite h1 { margin-bottom: .5rem; }
.hilfe-inhalt { line-height: 1.9; }
@media (max-width: 700px) { .benutzer span.version { display: inline; } }
