/* Büro-Programm – Gestaltung.
   Aufbau: feste Seitenleiste links (am Handy oben als Leiste), Arbeitsfläche rechts.
   Nur Systemschriften, keine externen Quellen. */
:root {
  --bg: #f2f4f3;
  --surface: #ffffff;
  --surface-2: #e8eeec;
  --line: #d3ddd9;
  --fg: #16231e;
  --muted: #5b6c65;
  --accent: #1c6656;
  --accent-fg: #ffffff;
  --accent-soft: #d5eae4;
  --warn: #93560a;
  --warn-soft: #fbedd6;
  --bad: #b02a22;
  --bad-soft: #f8dfdc;
  --good: #276b2d;
  --good-soft: #dcefdc;
  --info: #2d5a96;
  --info-soft: #dfe8f5;
  --shadow: 0 1px 2px rgb(16 35 30 / .06), 0 8px 24px rgb(16 35 30 / .08);
  --font-display: Bahnschrift, "DIN Alternate", "Segoe UI", system-ui, sans-serif;
  --font-body: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, ui-monospace, "SF Mono", monospace;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1614; --surface: #161f1c; --surface-2: #1e2925; --line: #2b3934;
    --fg: #e2ebe7; --muted: #93a59d; --accent: #5fc0a6; --accent-fg: #07201a; --accent-soft: #1c3832;
    --warn: #efb45c; --warn-soft: #39290f; --bad: #f08b80; --bad-soft: #3c1c19; --good: #82cf88; --good-soft: #1a3220;
    --info: #92b5ea; --info-soft: #1b2940; --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1614; --surface: #161f1c; --surface-2: #1e2925; --line: #2b3934;
  --fg: #e2ebe7; --muted: #93a59d; --accent: #5fc0a6; --accent-fg: #07201a; --accent-soft: #1c3832;
  --warn: #efb45c; --warn-soft: #39290f; --bad: #f08b80; --bad-soft: #3c1c19; --good: #82cf88; --good-soft: #1a3220;
  --info: #92b5ea; --info-soft: #1b2940; --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.45 var(--font-body);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.005em; text-wrap: balance; margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: .92em; }
.muted { color: var(--muted); }
.grow { flex: 1; }

/* ---------- Grundgerüst ---------- */
.app {
  display: grid; grid-template-columns: 228px minmax(0, 1fr); gap: 32px;
  min-height: 100vh;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.side {
  position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  padding-block: 22px; display: flex; flex-direction: column; gap: 18px;
}
.brand { font-family: var(--font-display); font-size: 21px; font-weight: 700; padding-left: 10px; line-height: 1.15; }
.brand small { display: block; font: 400 12px var(--font-body); color: var(--muted); margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 14px; }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-group h4 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 3px 10px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: 7px; color: var(--fg); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent); color: var(--accent-fg); }
.nav .cnt { font-size: 11px; font-weight: 700; min-width: 20px; text-align: center; padding: 1px 6px; border-radius: 10px; background: var(--bad); color: #fff; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding-left: 10px; font-size: 13px; }
.side-foot button { background: none; border: 0; padding: 4px 0; color: var(--muted); text-align: left; cursor: pointer; font: inherit; }
.side-foot button:hover { color: var(--fg); }
main { padding-block: 26px 80px; min-width: 0; }

@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); gap: 0; }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
  .side {
    position: sticky; top: env(safe-area-inset-top, 0px); z-index: 9; height: auto;
    flex-direction: row; align-items: center; gap: 14px; padding-block: 10px;
    background: var(--bg); border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden;
  }
  .brand { font-size: 17px; padding-left: 0; white-space: nowrap; }
  .brand small { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-group { flex-direction: row; }
  .nav-group h4 { display: none; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .side-foot { display: none; }
  main { padding-block: 18px 80px; }
}

/* ---------- Kopfbereich einer Seite ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-bottom: 20px; }
.page-head h1 { font-size: 27px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 62ch; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.toolbar label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }

.section { margin-top: 30px; }
.section > h2 { font-size: 18px; margin-bottom: 10px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.section > h2 small { font: 400 13px var(--font-body); color: var(--muted); }

/* ---------- Bedienelemente ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 13.5px var(--font-body); padding: 8px 14px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.link-btn { border: 0; background: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }
.link-btn:hover { text-decoration: underline; }

input, select, textarea {
  font: inherit; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
textarea { resize: vertical; min-height: 38px; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }

.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.fld .hint { font-size: 12px; color: var(--muted); margin: 0; }
.chk { display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
@media (max-width: 620px) { .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } .span2 { grid-column: auto; } }

/* ---------- Kennzahlen ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .val { font-family: var(--font-display); font-size: 25px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--muted); }
.kpi.alert { border-color: var(--bad); }
.kpi.alert .val { color: var(--bad); }

/* ---------- Tabellen ---------- */
.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: var(--surface-2); }
.tbl td.act { white-space: nowrap; text-align: right; }
.tbl td.act .btn + .btn { margin-left: 4px; }
.tbl .strong { font-weight: 600; }
.tbl .small { font-size: 12.5px; color: var(--muted); }
.tbl td.nowrap, .nowrap { white-space: nowrap; }

/* ---------- Status-Chips ---------- */
.chip { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Leerer Zustand ---------- */
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px 22px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--fg); font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 12px; }

/* ---------- Übersicht ---------- */
.cols2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 22px; }
@media (max-width: 1050px) { .cols2 { grid-template-columns: minmax(0, 1fr); } }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list-item { display: grid; grid-template-columns: 86px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .date { font-variant-numeric: tabular-nums; font-size: 13px; }
.list-item .date small { display: block; font-size: 11.5px; color: var(--muted); }
.list-item .t { font-weight: 600; }
.list-item .s { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.list-item.over .date { color: var(--bad); font-weight: 600; }

.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter.warn > i { background: var(--warn); }
.meter.bad > i { background: var(--bad); }

.budgets { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.budget { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.budget h3 { font-size: 15.5px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.budget .row { font-size: 13px; }
.budget .row .top { display: flex; justify-content: space-between; gap: 8px; }
.budget .row .top b { font-variant-numeric: tabular-nums; }
.budget .row .bot { font-size: 12px; color: var(--muted); }

.note { background: var(--info-soft); color: var(--fg); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; }
.note.warn { background: var(--warn-soft); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.card h3 { font-size: 16px; }
.card .meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.card .foot { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }

/* ---------- Dialoge ---------- */
dialog {
  border: 0; padding: 0; border-radius: 12px; background: var(--surface); color: var(--fg);
  box-shadow: var(--shadow); width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
}
dialog.wide { width: min(1000px, calc(100vw - 24px)); }
dialog.small { width: min(440px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(10 20 17 / .45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 12px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 19px; flex: 1; }
.dlg-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dlg-body h3.sec { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; }
.dlg-foot { display: flex; gap: 8px; align-items: center; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.ask-text { padding: 20px 20px 4px; margin: 0; font-size: 15px; }

/* Positionen */
.pos-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.pos-tbl { width: 100%; border-collapse: collapse; min-width: 640px; }
.pos-tbl th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: left; padding: 7px 8px; background: var(--surface-2); }
.pos-tbl td { padding: 5px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.pos-tbl textarea { width: 100%; min-height: 36px; }
.pos-tbl input { width: 100%; }
.pos-tbl td:nth-child(2) { width: 84px; } .pos-tbl td:nth-child(3) { width: 80px; } .pos-tbl td:nth-child(4) { width: 110px; }
.pos-tbl td.ptot { width: 100px; padding-top: 12px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos-tbl td:last-child { width: 36px; }
.pos-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pos-sum { font-size: 15px; }
.pos-sum strong { font-family: var(--font-display); font-size: 19px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.std-panel { border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px; background: var(--accent-soft); display: flex; flex-direction: column; gap: 8px; }
.std-panel .std-list { max-height: 260px; overflow-y: auto; background: var(--surface); border-radius: 6px; border: 1px solid var(--line); }
.std-panel label { display: grid; grid-template-columns: 22px 88px 52px minmax(0, 1fr); gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); align-items: center; font-size: 13px; }
.std-panel label:last-child { border-bottom: 0; }

.files { display: flex; flex-wrap: wrap; gap: 6px; }
.file { display: inline-flex; align-items: center; gap: 2px; background: var(--surface-2); border-radius: 6px; padding: 2px 2px 2px 10px; font-size: 13px; max-width: 100%; }
.file .link-btn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.file .icon-btn { font-size: 16px; padding: 2px 6px; }
.upl { position: relative; cursor: pointer; align-self: flex-start; }
.upl input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.checklist { display: flex; flex-direction: column; gap: 4px; }
.checklist label { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }

/* Hinweisleiste */
.toast {
  position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow);
  z-index: 50; max-width: min(420px, calc(100vw - 32px)); font-size: 13.5px;
}
.toast.bad { background: var(--bad); color: #fff; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }

.lightbox img { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; }

/* Anmeldung */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.login { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 28px; width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 24px; }
.login p { margin: 0; color: var(--muted); }
.login .err { color: var(--bad); font-weight: 600; }

/* ---------- Druck (Rechnung, Angebot, Leistungsnachweis) ---------- */
#print { display: none; }
@media print {
  @page { size: A4; margin: 14mm 16mm 14mm 22mm; }
  body { background: #fff; color: #000; }
  body.printing > *:not(#print) { display: none !important; }
  body.printing #print { display: block; }
}
.doc { font: 10pt/1.4 Arial, "Helvetica Neue", Helvetica, sans-serif; color: #000; }
.doc-firm { text-align: right; font-size: 9pt; line-height: 1.35; min-height: 28mm; }
.doc-firm strong { font-size: 14pt; display: block; margin-bottom: 1mm; }
.doc-addr { margin-top: 3mm; min-height: 40mm; display: grid; grid-template-columns: 85mm 1fr; gap: 10mm; align-items: start; }
.doc-sender { font-size: 7pt; color: #444; border-bottom: .2mm solid #888; padding-bottom: .8mm; margin-bottom: 3mm; }
.doc-info { font-size: 9pt; border-collapse: collapse; justify-self: end; }
.doc-info td { padding: .4mm 0 .4mm 6mm; }
.doc-info td:first-child { color: #444; padding-left: 0; }
.doc-info td:last-child { text-align: right; }
.doc h1 { font: 700 14pt Arial, sans-serif; margin: 6mm 0 3mm; }
.doc-klient { font-size: 9pt; border: .2mm solid #999; padding: 2mm 3mm; margin-bottom: 4mm; }
.doc-pos { width: 100%; border-collapse: collapse; margin: 3mm 0; font-size: 9.5pt; }
.doc-pos th { text-align: left; border-bottom: .4mm solid #000; padding: 1.5mm 1.5mm; font-weight: 700; }
.doc-pos td { border-bottom: .2mm solid #bbb; padding: 1.5mm 1.5mm; vertical-align: top; }
.doc-pos .r { text-align: right; white-space: nowrap; }
.doc-pos tr { page-break-inside: avoid; }
.doc-total { display: flex; justify-content: flex-end; gap: 12mm; font-size: 11pt; font-weight: 700; border-top: .4mm solid #000; padding-top: 2mm; margin-top: 1mm; }
.doc p { margin: 3mm 0; white-space: pre-line; }
.doc-foot { margin-top: 14mm; border-top: .2mm solid #888; padding-top: 2mm; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6mm; font-size: 7.5pt; color: #333; page-break-inside: avoid; }
.doc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 14mm; margin-top: 18mm; font-size: 8.5pt; page-break-inside: avoid; }
.doc-sign div { border-top: .2mm solid #000; padding-top: 1.5mm; }
