:root {
  color-scheme: light;
  --papier: #F2EDE3;
  --papier-2: #E8E1D3;
  --karte: #FBF8F2;
  --tinte: #1E1A15;
  --tinte-2: #5C5449;
  --tinte-3: #8A8174;
  --linie: #D3C9B7;
  --linie-2: #E2DACB;
  --rot: #C4381F;
  --rot-hell: #F4DDD5;
  --holz: #B9773A;
  --gruen: #3F6B4A;
  --schrift: "Familjen Grotesk", "Helvetica Neue", Arial, sans-serif;
  --mono: "Martian Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --leiste: 56px;
  --r: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--papier);
  color: var(--tinte);
  font: 400 15px/1.5 var(--schrift);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--rot); color: #fff; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--rot); outline-offset: 2px; }

/* Kopfleiste */
.leiste {
  position: sticky; top: 0; z-index: 20;
  height: var(--leiste);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--papier) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--linie);
}
.marke { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; min-width: 0; }
.marke svg { width: 24px; height: 24px; flex: none; }
.marke i { font-style: normal; color: var(--tinte-3); font-weight: 400; }
.marke em {
  font: 500 10px/1 var(--mono); font-style: normal; letter-spacing: 0.04em;
  padding: 5px 7px; border: 1px solid var(--linie); border-radius: 4px; color: var(--tinte-2);
}

.knopf {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--tinte);
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s, transform .15s;
}
.knopf svg { width: 18px; height: 18px; }
.knopf:active { transform: translateY(1px); }
.knopf-hell { background: transparent; }
.knopf-hell:hover { background: var(--tinte); color: var(--papier); }
.knopf-rot { background: var(--rot); border-color: var(--rot); color: #fff; }
.knopf-rot:hover { background: #A92E17; }
.knopf[disabled] { opacity: .45; cursor: default; }

/* Arbeitsfläche */
.flaeche {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(400px, 540px);
  height: calc(100vh - var(--leiste));
  height: calc(100dvh - var(--leiste));
}

.buehne {
  position: relative; overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 40%, #F7F3EB 0%, var(--papier) 55%, var(--papier-2) 100%);
  border-right: 1px solid var(--linie);
}
.buehne-raster {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(30, 26, 21, .045) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(30, 26, 21, .045) 1px, transparent 1px),
    linear-gradient(to right, rgba(30, 26, 21, .03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(30, 26, 21, .03) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  mask-image: radial-gradient(80% 70% at 50% 55%, #000 30%, transparent 100%);
}
#leinwand { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; display: block; touch-action: none; }

.lader {
  position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(320px, 80%); text-align: center;
}
.lader-strich { height: 2px; background: var(--linie); overflow: hidden; border-radius: 2px; }
.lader-strich span { display: block; height: 100%; width: 0; background: var(--rot); transition: width .3s ease; }
.lader p { margin: 12px 0 0; font: 400 11px/1.4 var(--mono); color: var(--tinte-2); letter-spacing: .02em; }
.lader.fehler p { color: var(--rot); }

.kennung {
  position: absolute; z-index: 2; top: 16px; left: 16px;
  display: flex; flex-direction: column; gap: 3px;
  font: 400 10.5px/1.35 var(--mono); color: var(--tinte-2);
  pointer-events: none;
}
.kennung span:first-child { color: var(--tinte); font-weight: 500; }

.steuerung {
  position: absolute; z-index: 2; left: 16px; bottom: 16px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.segmente {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--karte); border: 1px solid var(--linie); border-radius: 9px;
}
.segmente button, .schalter {
  border: 0; background: transparent; cursor: pointer;
  min-height: 32px; padding: 0 11px; border-radius: 6px;
  font-weight: 500; font-size: 13px; color: var(--tinte-2);
}
.segmente button[aria-pressed="true"] { background: var(--tinte); color: var(--papier); }
.segmente button:hover:not([aria-pressed="true"]) { color: var(--tinte); background: var(--papier-2); }
.schalter { background: var(--karte); border: 1px solid var(--linie); min-height: 38px; border-radius: 9px; }
.schalter:hover { color: var(--tinte); border-color: var(--tinte-3); }
.schalter[aria-pressed="true"] { background: var(--tinte); border-color: var(--tinte); color: var(--papier); }
.schalter.rund { width: 38px; padding: 0; display: inline-grid; place-items: center; }
.schalter svg { width: 18px; height: 18px; }

.hinweis-maus {
  position: absolute; z-index: 2; right: 16px; top: 16px; margin: 0;
  font: 400 10.5px/1.4 var(--mono); color: var(--tinte-3); pointer-events: none;
}

.karte {
  position: absolute; z-index: 4; right: 16px; bottom: 16px;
  width: min(320px, calc(100% - 32px));
  background: var(--karte); border: 1px solid var(--linie); border-radius: var(--r);
  box-shadow: 0 18px 40px -18px rgba(30, 26, 21, .35);
  padding: 16px 18px 14px;
  animation: auf .22s ease both;
}
.karte-zu {
  position: absolute; top: 8px; right: 8px; width: 32px; height: 32px;
  border: 0; background: transparent; border-radius: 6px; cursor: pointer; color: var(--tinte-3);
  display: grid; place-items: center;
}
.karte-zu:hover { background: var(--papier-2); color: var(--tinte); }
.karte-zu svg { width: 16px; height: 16px; }
.karte-kat { margin: 0; font: 500 10.5px/1.3 var(--mono); color: var(--rot); display: flex; align-items: center; gap: 7px; }
.karte h3 { margin: 4px 36px 10px 0; font-size: 18px; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.karte dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13px; }
.karte dt { color: var(--tinte-3); }
.karte dd { margin: 0; overflow-wrap: anywhere; }
.karte .zahl { font-family: var(--mono); font-size: 12px; }
.karte-pos { margin: 12px 0 0; padding-top: 10px; border-top: 1px dashed var(--linie); font-size: 13px; color: var(--tinte-2); }
.karte-pos b { color: var(--tinte); font-weight: 600; }

/* rechte Spalte */
.spalte { overflow-y: auto; padding: 32px 32px 40px; scroll-behavior: smooth; }
.kopf h1 { margin: 0; font-size: 34px; line-height: 1.05; letter-spacing: -0.025em; font-weight: 700; }
.kopf p { margin: 12px 0 0; color: var(--tinte-2); max-width: 46ch; }

.schritte { list-style: none; margin: 28px 0 0; padding: 0; display: grid; gap: 14px; }
.schritt {
  background: var(--karte); border: 1px solid var(--linie-2); border-radius: var(--r);
  padding: 18px 18px 16px;
  opacity: 0; transform: translateY(8px);
  transition: opacity .5s ease, transform .5s ease;
}
.schritt.da { opacity: 1; transform: none; }
.schritt > header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.schritt h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.nr {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font: 500 11px/1 var(--mono); border: 1.5px solid var(--tinte);
}
.schritt.da .nr { background: var(--tinte); color: var(--papier); }
.zeit { margin-left: auto; font: 400 10.5px/1.3 var(--mono); color: var(--tinte-3); }
.status {
  margin-left: auto; font: 500 10.5px/1 var(--mono); padding: 6px 8px; border-radius: 4px;
  background: var(--papier-2); color: var(--tinte-2);
}
.status.frei { background: var(--rot); color: #fff; }

/* Schriftfeld wie im Planstempel */
.schriftfeld { display: grid; grid-template-columns: 1fr 1fr 1fr; border: 1px solid var(--tinte); border-radius: 4px; overflow: hidden; }
.schriftfeld div { padding: 8px 10px 9px; border-right: 1px solid var(--linie); border-bottom: 1px solid var(--linie); min-width: 0; }
.schriftfeld div:nth-child(3n) { border-right: 0; }
.schriftfeld div.breit { grid-column: 1 / -1; border-right: 0; }
.schriftfeld div:nth-last-child(-n+3):not(.breit) { border-bottom: 0; }
.schriftfeld small { display: block; font: 400 9.5px/1.3 var(--mono); color: var(--tinte-3); letter-spacing: .02em; }
.schriftfeld strong { display: block; margin-top: 3px; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.schriftfeld strong.gross { font-size: 22px; letter-spacing: -0.02em; line-height: 1.1; }

/* Mengen */
.mengen { display: grid; border-top: 1px solid var(--linie-2); }
.zeile {
  display: grid; grid-template-columns: 14px minmax(0, 1fr) auto auto; align-items: center; gap: 12px;
  padding: 10px 8px; border: 0; border-bottom: 1px solid var(--linie-2); background: transparent;
  text-align: left; cursor: pointer; width: 100%; position: relative;
  transition: background .12s;
}
.zeile:hover { background: var(--papier); }
.zeile[aria-expanded="true"] { background: var(--rot-hell); }
.zeile[aria-expanded="true"]::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--rot); }
.muster { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(30, 26, 21, .35); }
.zeile .was { min-width: 0; }
.zeile .was b { display: block; font-weight: 600; font-size: 14.5px; }
.zeile .was small { display: block; font: 400 10px/1.3 var(--mono); color: var(--tinte-3); margin-top: 2px; }
.zeile .stk { font: 400 12px/1 var(--mono); color: var(--tinte-2); }
.zeile .wert { font: 500 13px/1 var(--mono); text-align: right; min-width: 104px; }
.zeile.aus { opacity: .55; }
.liste { margin: 0; padding: 6px 8px 10px 34px; list-style: none; background: var(--papier); border-bottom: 1px solid var(--linie-2); max-height: 220px; overflow-y: auto; }
.liste li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 12.5px; border-bottom: 1px dotted var(--linie); }
.liste li:last-child { border-bottom: 0; }
.liste li span:last-child { font: 400 11px/1.4 var(--mono); color: var(--tinte-2); white-space: nowrap; }
.liste button { all: unset; cursor: pointer; overflow-wrap: anywhere; }
.liste button:hover { color: var(--rot); text-decoration: underline; }
.fuss { margin: 12px 0 0; font-size: 12.5px; color: var(--tinte-3); }
.warn { color: var(--rot); font-style: normal; font-weight: 500; }
.liste li.warn button { color: var(--rot); }
.fuss b { color: var(--tinte-2); font-weight: 600; }

/* Angebot */
.tabelle-huelle { overflow: hidden; }
.angebot { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.angebot th { font: 400 9.5px/1.3 var(--mono); color: var(--tinte-3); text-align: left; padding: 0 6px 8px; border-bottom: 1px solid var(--tinte); }
.angebot td { padding: 9px 6px; border-bottom: 1px solid var(--linie-2); vertical-align: top; }
.angebot .r { text-align: right; }
.angebot .pos { font: 400 11px/1.6 var(--mono); color: var(--tinte-3); width: 30px; }
.angebot .text { line-height: 1.35; }
.angebot .text small { display: block; color: var(--tinte-3); font-size: 11.5px; margin-top: 2px; }
.angebot .zahl { font: 400 12px/1.6 var(--mono); white-space: nowrap; }
.angebot input {
  width: 74px; text-align: right; font: 400 12px/1.4 var(--mono);
  border: 0; border-bottom: 1px dashed var(--tinte-3); background: transparent; padding: 1px 2px;
}
.angebot input:focus { outline: none; border-bottom: 1.5px solid var(--rot); background: var(--rot-hell); }
.angebot input:disabled { border-bottom-color: transparent; }
.angebot tr.geaendert input { color: var(--rot); }
.angebot tr.bauseits td { color: var(--tinte-3); }
.angebot tr.bauseits .zahl { text-decoration: line-through; }
.angebot tr { transition: background .12s; }
.angebot tbody tr:hover { background: var(--papier); }
.umschalter { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 11.5px; color: var(--tinte-2); cursor: pointer; }
.umschalter input { width: auto; accent-color: var(--rot); }

.summen { margin: 14px 0 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; }
.summen dt { text-align: right; color: var(--tinte-2); font-size: 13.5px; }
.summen dd { margin: 0; text-align: right; font: 400 13px/1.6 var(--mono); min-width: 120px; }
.summen dt.brutto { color: var(--tinte); font-weight: 600; font-size: 15px; padding-top: 8px; border-top: 1px solid var(--tinte); }
.summen dd.brutto { font-weight: 500; font-size: 17px; padding-top: 8px; border-top: 1px solid var(--tinte); }

/* Freigabe */
.freigabe { display: flex; flex-wrap: wrap; gap: 10px; }
.stempel {
  display: inline-block; margin: 16px 0 2px; padding: 8px 14px;
  font: 500 12px/1.4 var(--mono); color: var(--rot);
  border: 2px solid var(--rot); border-radius: 6px; transform: rotate(-2.5deg);
  animation: stempel .35s cubic-bezier(.2, 1.6, .4, 1) both;
}
.stempel b { display: block; font-size: 15px; letter-spacing: .06em; }
.protokoll-titel { margin: 18px 0 6px; font: 400 9.5px/1.3 var(--mono); color: var(--tinte-3); font-weight: 400; }
.protokoll { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.protokoll li { display: grid; grid-template-columns: 66px 1fr; gap: 8px; padding: 5px 0; border-top: 1px dotted var(--linie); animation: auf .25s ease both; }
.protokoll time { font: 400 11px/1.5 var(--mono); color: var(--tinte-3); }
.protokoll li.rot span { color: var(--rot); font-weight: 600; }

.herkunft { margin-top: 26px; font-size: 12.5px; color: var(--tinte-2); }
.herkunft p { margin: 0 0 8px; }
.herkunft b { color: var(--tinte); font-weight: 600; }
.unterschrift { margin-top: 14px !important; font: 400 10.5px/1.4 var(--mono); color: var(--tinte-3); }

.ablage {
  position: fixed; inset: 10px; z-index: 50; border-radius: 16px;
  border: 2px dashed var(--rot); background: rgba(242, 237, 227, .88);
  display: grid; place-items: center; pointer-events: none;
}
.ablage p { font-size: 24px; font-weight: 600; color: var(--rot); }

@keyframes auf { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes stempel { from { opacity: 0; transform: rotate(-2.5deg) scale(1.6); } to { opacity: 1; transform: rotate(-2.5deg) scale(1); } }

/* Tablet und Handy */
@media (max-width: 980px) {
  .flaeche { display: block; height: auto; }
  .buehne { height: 62vh; height: 62svh; min-height: 380px; border-right: 0; border-bottom: 1px solid var(--linie); }
  .spalte { overflow: visible; padding: 26px 16px 36px; }
  .hinweis-maus { display: none; }
}
@media (max-width: 560px) {
  .leiste { padding: 0 12px; }
  .marke span { font-size: 14px; }
  .marke em { display: none; }
  #datei-knopf { padding: 0 12px; }
  #datei-knopf span { font-size: 13px; }
  .kopf h1 { font-size: 28px; }
  .schritt { padding: 16px 14px 14px; }
  .schriftfeld { grid-template-columns: 1fr 1fr; }
  .schriftfeld div:nth-child(3n) { border-right: 1px solid var(--linie); }
  .schriftfeld div:nth-child(2n) { border-right: 0; }
  .schriftfeld div:nth-last-child(-n+3):not(.breit) { border-bottom: 1px solid var(--linie); }
  .schriftfeld div:nth-last-child(-n+2):not(.breit) { border-bottom: 0; }
  .zeile { grid-template-columns: 14px minmax(0, 1fr) auto; }
  .zeile .stk { display: none; }
  .zeile .wert { min-width: 0; }
  .angebot thead { display: none; }
  .angebot, .angebot tbody { display: block; }
  .angebot tr { display: grid; grid-template-columns: 30px 1fr auto auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--linie-2); }
  .angebot td { display: block; padding: 0; border: 0; }
  .angebot td.text { grid-column: 2 / -1; }
  .angebot td.menge { grid-column: 2; text-align: left; }
  .steuerung { left: 10px; bottom: 10px; right: 10px; }
  .kennung { top: 10px; left: 10px; }
  .karte { right: 10px; left: 10px; bottom: 58px; width: auto; max-height: 52%; overflow-y: auto; padding: 12px 14px 10px; }
  .karte h3 { font-size: 16px; margin-bottom: 6px; }
  .karte .neben { display: none; }
  .karte-pos { margin-top: 8px; padding-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .schritt { opacity: 1; transform: none; }
}
