/* Werkkontor – Oberfläche
   Ruhige Betonflächen, Tinte als Text, eine Akzentfarbe je Betrieb (Standard: Verkehrsblau).
   Maße und Beträge immer in Tabellenziffern. */
:root {
  --bg: #F3F4F2;
  --panel: #FFFFFF;
  --panel-2: #F8F9F7;
  --ink: #1E2328;
  --ink-2: #4E555C;
  --ink-3: #80878E;
  --line: #DCDFDA;
  --line-2: #ECEEEA;
  --accent: #0E518D;
  --accent-ink: #FFFFFF;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, transparent);
  --ok: #2E7D4F;
  --warn: #B26B00;
  --bad: #B23A2A;
  --ruler: #E8B923;
  --radius: 6px;
  --shadow: 0 1px 0 rgba(30,35,40,.04), 0 2px 8px rgba(30,35,40,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181B; --panel: #1C2024; --panel-2: #22272C; --ink: #E8EAEC; --ink-2: #B4BAC0; --ink-3: #848B92;
    --line: #2F353B; --line-2: #262B30; --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15181B; --panel: #1C2024; --panel-2: #22272C; --ink: #E8EAEC; --ink-2: #B4BAC0; --ink-3: #848B92;
  --line: #2F353B; --line-2: #262B30; --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; font-weight: 650; }
h2 { font-size: 1.12rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .8em; }
.num, td.num, .money { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- Gerüst ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: var(--ink); font-weight: 700; }
.brand img { max-height: 34px; max-width: 150px; }
.brand-mark { width: 30px; height: 30px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); color: var(--ink-2); font-weight: 500; position: relative; }
.nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.nav a.on::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav .sep { height: 1px; background: var(--line-2); margin: 10px 6px; }
.side-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--line-2); font-size: .85rem; color: var(--ink-3); }
.side-foot .who { color: var(--ink); font-weight: 600; }
.main { min-width: 0; }
.topbar { display: none; }
.content { padding: 26px 32px 60px; max-width: 1240px; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.pagehead h1 { margin: 0; }
.pagehead .sub { color: var(--ink-3); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.impersonate { background: var(--ruler); color: #1E2328; padding: 6px 32px; font-size: .9rem; }
.impersonate a { color: #1E2328; font-weight: 600; text-decoration: underline; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
  .topbar button { background: none; border: 0; padding: 6px; color: var(--ink); }
  .content { padding: 18px 16px 60px; }
  .impersonate { padding: 6px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Flächen ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.panel-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.panel-h h2 { margin: 0; font-size: 1rem; }
.panel-b { padding: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .g2, .g3, .g-side { grid-template-columns: 1fr; } }

/* Kennzahlen: eine Leiste statt Kartenstapel */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 18px; }
.stat { padding: 14px 18px; border-left: 1px solid var(--line-2); }
.stat:first-child { border-left: 0; }
.stat .v { font-size: 1.45rem; font-weight: 680; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--ink-3); font-size: .86rem; }
.stat.bad .v { color: var(--bad); }
@media (max-width: 700px) { .stats { grid-template-columns: 1fr 1fr; } .stat:nth-child(3) { border-left: 0; } .stat { border-top: 1px solid var(--line-2); } .stat:nth-child(-n+2) { border-top: 0; } }

/* Projekt-Pipeline */
.pipeline { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); margin-bottom: 18px; }
.pipeline a { flex: 1; padding: 10px 12px; color: var(--ink-2); border-left: 1px solid var(--line-2); min-width: 0; }
.pipeline a:first-child { border-left: 0; }
.pipeline a:hover { background: var(--panel-2); text-decoration: none; }
.pipeline a.on { background: var(--accent-soft); color: var(--ink); box-shadow: inset 0 -3px 0 var(--accent); }
.pipeline b { display: block; font-size: 1.2rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.pipeline span { font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
@media (max-width: 800px) { .pipeline { overflow-x: auto; } .pipeline a { min-width: 105px; } }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-weight: 600; font-size: .82rem; color: var(--ink-3); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: var(--panel-2); }
table.t tr.click { cursor: pointer; }
table.t td .sub { color: var(--ink-3); font-size: .85rem; }
table.t tfoot td { font-weight: 650; border-top: 1px solid var(--line); }
.empty { padding: 34px 20px; text-align: center; color: var(--ink-3); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------- Status ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.st-entwurf { background: transparent; border: 1px dashed var(--line); }
.st-offen, .st-versendet, .st-angebot, .st-anfrage { background: #E7EEF7; color: #1D4F86; }
.st-angenommen, .st-bezahlt, .st-auftrag, .st-abgeschlossen, .st-behoben { background: #E3F1E8; color: #23663F; }
.st-ausfuehrung, .st-teilbezahlt, .st-abrechnung { background: #FBF0D9; color: #8A5300; }
.st-abgelehnt, .st-storniert, .st-verloren, .st-ueberfaellig { background: #F7E4E0; color: #96301F; }
:root[data-theme="dark"] .badge:not(.st-entwurf) { filter: brightness(.85) saturate(1.2); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ink-3); }

/* ---------- Formulare ---------- */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.f { margin-bottom: 14px; }
.f .hint { font-size: .8rem; color: var(--ink-3); margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); font: inherit; min-height: 40px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=color] { width: 56px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.row-2-1 { display: grid; gap: 12px; grid-template-columns: 2fr 1fr; }
.row-1-2 { display: grid; gap: 12px; grid-template-columns: 1fr 2fr; }
@media (max-width: 600px) { .row-2-1, .row-1-2 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.check input { width: 18px; height: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 38px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: .86rem; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.menu { position: relative; display: inline-block; }
.menu > div { display: none; position: absolute; right: 0; top: calc(100% + 4px); min-width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.12); z-index: 30; padding: 5px; }
.menu.open > div { display: block; }
.menu > div a, .menu > div button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 5px; color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; }
.menu > div a:hover, .menu > div button:hover { background: var(--panel-2); text-decoration: none; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: #E9F4EC; border-color: #BFDCC8; color: #1F5C37; }
.flash.err { background: #FBEAE6; border-color: #EDC3BA; color: #8A2B1C; }
.flash.info { background: #EAF0F8; border-color: #C7D6EA; color: #1D4F86; }
:root[data-theme="dark"] .flash { filter: brightness(.75); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); border-color: var(--accent); font-weight: 600; }
.tabs a .c { color: var(--ink-3); font-weight: 500; margin-left: 4px; font-size: .85rem; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[type=search] { max-width: 280px; }
.chip { padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line); color: var(--ink-2); font-size: .86rem; background: var(--panel); }
.chip.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.chip:hover { text-decoration: none; }

dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--ink-3); font-size: .88rem; }
dl.kv dd { margin: 0; }

/* Logbuch */
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 14px 1fr; gap: 10px; padding: 8px 0; position: relative; }
.log li::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-top: 6px; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); }
.log li.dokument::before { background: var(--accent); }
.log li.zahlung::before { background: var(--ok); }
.log li.mangel::before { background: var(--bad); }
.log li.aufmass::before { background: var(--ruler); }
.log .when { color: var(--ink-3); font-size: .8rem; }

/* Aufgaben */
.todo { list-style: none; margin: 0; padding: 0; }
.todo li { display: flex; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line-2); }
.todo li.done span { text-decoration: line-through; color: var(--ink-3); }
.todo input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }

/* Fotoraster */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photos figure { margin: 0; position: relative; background: var(--panel-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line-2); }
.photos img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.photos figcaption { font-size: .78rem; padding: 5px 8px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Dokumenteditor ---------- */
.doc-pos { width: 100%; border-collapse: collapse; }
.doc-pos th { font-size: .78rem; color: var(--ink-3); font-weight: 600; text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); }
.doc-pos td { padding: 6px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.doc-pos input, .doc-pos select, .doc-pos textarea { min-height: 34px; padding: 6px 8px; }
.doc-pos textarea { min-height: 34px; height: 34px; font-size: .88rem; margin-top: 4px; }
.doc-pos .w-menge { width: 92px; } .doc-pos .w-einheit { width: 78px; } .doc-pos .w-preis { width: 110px; } .doc-pos .w-rabatt { width: 70px; } .doc-pos .w-ust { width: 74px; } .doc-pos .w-gesamt { width: 110px; } .doc-pos .w-act { width: 76px; }
.doc-pos tr.titel td { background: var(--panel-2); }
.doc-pos tr.titel input { font-weight: 700; }
.doc-pos .handle { cursor: grab; color: var(--ink-3); padding: 0 4px; user-select: none; }
.doc-pos tr.dragging { opacity: .4; }
.totals { margin-left: auto; width: min(360px, 100%); }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-weight: 700; font-size: 1.1rem; }
@media (max-width: 900px) {
  .doc-pos thead { display: none; }
  .doc-pos, .doc-pos tbody, .doc-pos tr, .doc-pos td { display: block; width: 100%; }
  .doc-pos tr { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; padding: 6px; }
  .doc-pos td { border: 0; display: inline-block; width: auto; }
  .doc-pos td.bez { display: block; }
}
.search-pop { position: absolute; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.14); max-height: 300px; overflow-y: auto; width: min(520px, 92vw); }
.search-pop button { display: flex; justify-content: space-between; gap: 12px; width: 100%; padding: 8px 12px; background: none; border: 0; border-bottom: 1px solid var(--line-2); text-align: left; font: inherit; color: var(--ink); cursor: pointer; }
.search-pop button:hover, .search-pop button.sel { background: var(--accent-soft); }

/* ---------- Anmeldung ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  linear-gradient(var(--bg), var(--bg)) padding-box; }
.auth-box { width: min(400px, 100%); }
.auth-box .panel-b { padding: 26px; }
.auth h1 { font-size: 1.3rem; }
.ruler { height: 10px; margin: 0 0 22px; background:
  repeating-linear-gradient(90deg, var(--ink-3) 0 1px, transparent 1px 10px) bottom/100% 5px no-repeat,
  repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 50px) bottom/100% 10px no-repeat;
  opacity: .5; }

/* ---------- Modal ---------- */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--panel); color: var(--ink); width: min(520px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,24,28,.45); }
dialog form > header { padding: 14px 18px; border-bottom: 1px solid var(--line-2); font-weight: 650; }
dialog form > .body { padding: 18px; }
dialog form > footer { padding: 12px 18px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Unterschrift ---------- */
.sigpad { border: 1px dashed var(--ink-3); border-radius: 8px; background: #fff; touch-action: none; width: 100%; height: 190px; display: block; }

@media print { .side, .topbar, .actions, .no-print { display: none !important; } .shell { display: block; } body { background: #fff; } }

/* Stufe 2 */
h2 svg, .panel-h svg { width: 18px; height: 18px; vertical-align: -3px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin-right: 4px; }
.stempel { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); text-decoration: none !important; margin-bottom: 12px; }
.stempel b { font-variant-numeric: tabular-nums; font-size: 1.15rem; }
.stempel svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn svg{flex:none}
