:root {
  --bg: #f6f5f2; --panel: #fff; --ink: #1f2328; --muted: #6b7280; --line: #e3e1db; --soft: #f0efeb;
  --accent: #0f766e; --accent-ink: #fff; --accent-soft: #e0f2ef; --warn: #b45309; --warn-soft: #fef3c7;
  --err: #b91c1c; --err-soft: #fee2e2; --ok: #15803d; --ok-soft: #dcfce7; --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { display: inline-block; width: .7em; height: .7em; border-radius: 50%; background: var(--accent); margin-right: .45em; }

/* Kopfzeile */
.top { position: sticky; top: env(safe-area-inset-top, 0); z-index: 10; display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem; background: #1f2a2e; color: #fff; flex-wrap: wrap; }
.top .brand { color: #fff; font-weight: 650; white-space: nowrap; }
.top nav { display: flex; gap: .15rem; overflow-x: auto; flex: 1; }
.top nav a { color: #cbd5d1; padding: .35rem .65rem; border-radius: 6px; white-space: nowrap; }
.top nav a.on, .top nav a:hover { background: #33454a; color: #fff; text-decoration: none; }
.top .logout { margin: 0; }
.top .link { color: #cbd5d1; }

main { max-width: 1240px; margin: 0 auto; padding: 1.2rem 16px 4rem; }
.pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.crumbs a { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.panel > h2:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid2 { display: grid; gap: 1rem; grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; }
.kpi .v { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .82rem; }
.kpi.accent { border-color: var(--accent); background: var(--accent-soft); }

/* Tabellen */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--soft); }
tr.sum td { font-weight: 650; border-top: 2px solid var(--ink); border-bottom: none; }
tr.group td { background: var(--soft); font-weight: 650; }
tr.sub td { color: var(--muted); font-size: .88rem; }
td.pos { width: 3.2rem; color: var(--muted); }
.pre { white-space: pre-line; }

/* Formulare */
form { margin: 0; }
label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .4rem; color: var(--ink); font-size: .95rem; }
input, select, textarea { font: inherit; color: var(--ink); border: 1px solid #cfccc4; border-radius: 6px; padding: .45rem .55rem; background: #fff; min-width: 0; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; }
textarea { min-height: 4.5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.fields { display: grid; gap: .65rem .9rem; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: .75rem; }
.fields .wide { grid-column: 1 / -1; }
.inline { display: flex; flex-wrap: wrap; gap: .45rem; align-items: flex-end; }
.inline input, .inline select { max-width: 100%; }
.inline input.s { width: 6.5rem; }
.inline input.xs { width: 4.2rem; }
td input.s { width: 6rem; text-align: right; }
td input.xs { width: 4rem; text-align: right; }
td textarea { width: 100%; min-height: 3rem; }

button, .btn { font: inherit; cursor: pointer; border-radius: 6px; padding: .45rem .85rem; border: 1px solid #cfccc4; background: #fff; color: var(--ink);
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
button:hover, .btn:hover { background: var(--soft); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--err); border-color: #f0c4c4; }
button.small, .btn.small { padding: .2rem .5rem; font-size: .85rem; }
button.link { border: none; background: none; padding: 0; color: var(--accent); }
button.link.danger { color: var(--err); }

.flash { background: var(--accent-soft); border: 1px solid #b6e0d9; padding: .6rem .85rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash.err { background: var(--err-soft); border-color: #f5c2c2; color: var(--err); }
.warn { background: var(--warn-soft); border: 1px solid #fcd98a; color: #78350f; padding: .6rem .85rem; border-radius: var(--radius); margin-bottom: 1rem; }
.warn ul { margin: .3rem 0 0; padding-left: 1.2rem; }

.badge { display: inline-block; padding: .08rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.entwurf { background: #eef2ff; color: #3730a3; }
.badge.versendet, .badge.in_arbeit, .badge.gestellt, .badge.offen { background: #e0f2fe; color: #075985; }
.badge.angenommen, .badge.freigegeben, .badge.bezahlt, .badge.abgerechnet, .badge.abgeschlossen { background: var(--ok-soft); color: var(--ok); }
.badge.abgelehnt, .badge.storniert, .badge.ueberfaellig { background: var(--err-soft); color: var(--err); }
.badge.teilbezahlt { background: var(--warn-soft); color: var(--warn); }
.badge.ersetzt { text-decoration: line-through; }
.tag { display: inline-block; font-size: .75rem; padding: 0 .4rem; border-radius: 4px; background: var(--soft); color: var(--muted); margin-left: .25rem; }
.tag.usdz { background: #ede9fe; color: #5b21b6; }
.tag.grundriss { background: #e0f2fe; color: #075985; }
.tag.sonder { background: var(--warn-soft); color: var(--warn); }

/* Flächenkarten */
.flaeche { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .75rem; background: #fff; }
.flaeche > header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; padding: .55rem .8rem; background: var(--soft); border-radius: var(--radius) var(--radius) 0 0; }
.flaeche > header b { font-size: 1rem; }
.flaeche .body { padding: .7rem .8rem; display: grid; gap: .8rem; }
.mengen { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; font-size: .9rem; }
.mengen span b { font-variant-numeric: tabular-nums; }
details > summary { cursor: pointer; color: var(--accent); font-size: .9rem; margin: .2rem 0; }
details[open] > summary { margin-bottom: .5rem; }

/* Grundriss */
svg.plan { width: 100%; max-height: 360px; background: #fbfaf7; border: 1px solid var(--line); border-radius: var(--radius); }
svg.plan .floor { fill: #efe6d2; stroke: none; }
svg.plan line { stroke-linecap: round; }
svg.plan .w { stroke: #374151; stroke-width: .09; }
svg.plan .o-fenster { stroke: #3b82f6; stroke-width: .16; }
svg.plan .o-tuer { stroke: #c2410c; stroke-width: .16; }
svg.plan .o-durchgang { stroke: #9ca3af; stroke-width: .16; stroke-dasharray: .12 .08; }
svg.plan text { font-size: .32px; fill: #111827; text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: #fbfaf7; stroke-width: .08px; }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin-top: .35rem; flex-wrap: wrap; }
.legend i { display: inline-block; width: 1.2rem; height: .25rem; vertical-align: middle; margin-right: .3rem; border-radius: 2px; }

.planwrap { position: relative; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; max-height: 75vh; }
.planwrap img { display: block; max-width: none; }
.planwrap canvas { position: absolute; left: 0; top: 0; cursor: crosshair; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.thumb { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; font-size: .8rem; }
.thumb img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: var(--soft); }
.thumb .file { aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center; background: var(--soft); color: var(--muted); font-weight: 650; }
.thumb .cap { padding: .35rem .45rem; display: flex; justify-content: space-between; gap: .3rem; align-items: center; }
.thumb .cap span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: .88rem; max-height: 340px; overflow: auto; }
.timeline li { padding: .35rem 0; border-bottom: 1px dashed var(--line); }
.timeline time { color: var(--muted); font-size: .8rem; margin-right: .4rem; }

.login { max-width: 360px; margin: 12vh auto 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 1.6rem; }
.login form { display: grid; gap: .8rem; margin-top: 1rem; }

.totals { margin-left: auto; max-width: 340px; }
.totals td { border: none; padding: .2rem .5rem; }
.totals tr.big td { font-size: 1.1rem; font-weight: 700; border-top: 2px solid var(--ink); }

.empty { color: var(--muted); padding: .8rem 0; }
hr { border: none; border-top: 1px solid var(--line); margin: 1rem 0; }
