/* PW Buchhaltung — gemeinsames Stylesheet.
   Aufbau: Schrift → Farb-Tokens (hell/dunkel) → Grundelemente → Layout (Seitenleiste) →
   Bausteine (Seitenkopf, Flächen, Tabellen, Formulare, Badges, Summenleiste).
   Seiten, die noch eigene <style>-Blöcke haben, nutzen die Alt-Variablen am Ende von :root. */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-hyperlegible-next-latin-wght-italic.woff2") format("woff2");
  font-weight: 200 800; font-style: italic; font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #F3F5F7;
  --surface: #FFFFFF;
  --surface-2: #F8F9FB;
  --ink: #18204A;
  --muted: #5D667F;
  --line: #DCE1E8;
  --line-strong: #C3CAD6;
  --brand: #1E2878;
  --brand-ink: #FFFFFF;
  --brand-soft: #E8EAF6;
  --link: #0079A0;
  --focus: #0090B7;
  --haben: #1D7A4F;      /* Einnahmen */
  --haben-soft: #E3F2EA;
  --soll: #B42C2C;       /* Ausgaben */
  --soll-soft: #F8E5E5;
  --warn: #8A5A00;
  --warn-soft: #FBF0D9;
  --sidebar: #1E2878;
  --sidebar-ink: #E9ECFA;
  --sidebar-muted: #A9B0DA;
  --sidebar-hover: #2A3590;
  --sidebar-active: #FFFFFF;

  --radius-l: 12px;   /* Flächen */
  --radius-m: 8px;    /* Bedienelemente */
  --radius-s: 5px;    /* Badges */

  --font: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Alt-Variablen für noch nicht umgestellte Seiten */
  --navy: var(--brand);
  --navy-light: var(--brand);
  --cyan: var(--link);
  --teal: var(--link);
  --blue: var(--link);
  --bg-light: var(--paper);
  --text-dark: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0E1326;
    --surface: #161C34;
    --surface-2: #1B2240;
    --ink: #E6E9F2;
    --muted: #9AA3BD;
    --line: #2A3153;
    --line-strong: #3A4370;
    --brand: #8E9BFF;
    --brand-ink: #0E1326;
    --brand-soft: #232B52;
    --link: #5CC6E8;
    --focus: #5CC6E8;
    --haben: #5CCB93;
    --haben-soft: #15302A;
    --soll: #F08585;
    --soll-soft: #3A1E2A;
    --warn: #F0C46A;
    --warn-soft: #362C17;
    --sidebar: #111733;
    --sidebar-ink: #E6E9F2;
    --sidebar-muted: #8F98B8;
    --sidebar-hover: #1C2447;
    --sidebar-active: #FFFFFF;
  }
}

/* ---------- Grundelemente ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}
a { color: var(--link); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.98rem; }
p { margin: 0 0 0.75rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 1.1rem 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 1rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 0.6rem; padding: 0 0.5rem; text-decoration: none; color: inherit; }
.sidebar-brand img { height: 32px; width: auto; background: #fff; border-radius: 7px; padding: 3px; }
.sidebar-brand .name { font-weight: 700; font-size: 0.95rem; line-height: 1.2; }
.sidebar-brand .owner { font-size: 0.78rem; color: var(--sidebar-muted); }

.sidebar-actions { display: grid; gap: 0.4rem; padding: 0 0.25rem; }
.sidebar-actions .btn { justify-content: center; }
.sidebar .btn-primary { background: #fff; color: #1E2878; border-color: #fff; }
.sidebar .btn-quiet { color: var(--sidebar-ink); border-color: #ffffff38; background: transparent; }
.sidebar .btn-quiet:hover { background: var(--sidebar-hover); }

.nav { display: grid; gap: 0.7rem; }
.nav-group { display: grid; gap: 1px; }
.nav-group-title { font-size: 0.75rem; color: var(--sidebar-muted); padding: 0 0.6rem 0.2rem; }
.nav a {
  display: block; padding: 0.3rem 0.6rem; border-radius: var(--radius-m);
  color: var(--sidebar-ink); text-decoration: none; font-size: 0.9rem;
}
.nav a:hover { background: var(--sidebar-hover); }
.nav a[aria-current="page"] { background: var(--sidebar-hover); color: var(--sidebar-active); font-weight: 700; box-shadow: inset 3px 0 0 #fff; }

.sidebar-user { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 0.5rem 0; border-top: 1px solid #ffffff22; font-size: 0.82rem; color: var(--sidebar-muted); }
.sidebar-user form { margin: 0; }
.sidebar-user button { font: inherit; background: none; border: 0; color: var(--sidebar-ink); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; padding: 0; }

.mobile-bar { display: none; }

.main { min-width: 0; padding: 1.75rem 2rem 4rem; }
.main-inner { max-width: 1240px; margin: 0 auto; }

@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .mobile-bar { display: block; background: var(--sidebar); color: var(--sidebar-ink); position: sticky; top: 0; z-index: 10; }
  .mobile-bar summary { list-style: none; display: flex; align-items: center; justify-content: space-between; padding: 0.7rem 1rem; cursor: pointer; }
  .mobile-bar summary::-webkit-details-marker { display: none; }
  .mobile-bar .menu-label { border: 1px solid #ffffff44; border-radius: var(--radius-m); padding: 0.25rem 0.7rem; font-size: 0.85rem; }
  .mobile-bar .mobile-panel { padding: 0.25rem 0.75rem 1rem; display: grid; gap: 1rem; max-height: calc(100vh - 56px); overflow-y: auto; }
  .main { padding: 1.25rem 1rem 3rem; }
}

/* ---------- Seitenkopf ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .sub { color: var(--muted); margin-top: 0.3rem; font-size: 0.92rem; }
.page-head .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.back { display: inline-block; font-size: 0.85rem; color: var(--muted); text-decoration: none; margin-bottom: 0.4rem; }
.back:hover { color: var(--ink); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font: inherit; font-size: 0.88rem; font-weight: 600; line-height: 1.2;
  padding: 0.55rem 0.95rem; border-radius: var(--radius-m);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.12); border-color: var(--brand); }
.btn-quiet { background: transparent; }
.btn-danger { color: var(--soll); border-color: color-mix(in srgb, var(--soll) 45%, transparent); background: transparent; }
.btn-danger:hover { background: var(--soll-soft); border-color: var(--soll); }
.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.82rem; }
.btn-link { background: none; border: 0; padding: 0; color: var(--link); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.btn-row form { margin: 0; }

/* ---------- Flächen ---------- */
.surface { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.surface > h2:first-child, .surface-head { margin-bottom: 0.8rem; }
.surface-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.surface-flush { padding: 0; overflow: hidden; }
.surface-flush > .surface-head { padding: 1rem 1.25rem 0; }
.cols-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .cols-2 { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.9rem 1.5rem; margin: 0; }
.kv dt { font-size: 0.8rem; color: var(--muted); }
.kv dd { margin: 0.1rem 0 0; overflow-wrap: anywhere; }
.pre { white-space: pre-line; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { color: var(--muted); padding: 1.5rem 0; text-align: center; }
.empty .btn { margin-top: 0.6rem; }

/* ---------- Summenleiste (Kontoblatt) ---------- */
.ledger-strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  margin-bottom: 1.25rem; overflow: hidden;
}
.ledger-strip > div { padding: 0.95rem 1.25rem; border-left: 1px solid var(--line); }
.ledger-strip > div:first-child { border-left: 0; }
.ledger-strip .label { font-size: 0.82rem; color: var(--muted); }
.ledger-strip .figure { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; margin-top: 0.15rem; }
.ledger-strip .figure.haben { color: var(--haben); }
.ledger-strip .figure.soll { color: var(--soll); }
.ledger-strip .note { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }
.ledger-strip .saldo { background: var(--surface-2); }
@media (max-width: 700px) {
  .ledger-strip { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
  .ledger-strip > div { padding: 0.75rem 0.9rem; border-left: 0; border-top: 1px solid var(--line); }
  .ledger-strip > div:nth-child(-n+2) { border-top: 0; }
  .ledger-strip > div:nth-child(even) { border-left: 1px solid var(--line); }
  .ledger-strip .figure { font-size: 1.2rem; }
}

/* ---------- Tabellen ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th { text-align: left; font-weight: 600; font-size: 0.8rem; color: var(--muted); padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line-strong); white-space: nowrap; background: var(--surface); }
.tbl td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl .nowrap { white-space: nowrap; }
.tbl a.rowlink { color: inherit; font-weight: 600; text-decoration: none; }
.tbl a.rowlink:hover { text-decoration: underline; }
.tbl tfoot td { border-top: 1px solid var(--line-strong); border-bottom: 0; font-weight: 700; }
.tbl .sub { color: var(--muted); font-size: 0.82rem; }
.surface-flush .tbl th:first-child, .surface-flush .tbl td:first-child { padding-left: 1.25rem; }
.surface-flush .tbl th:last-child, .surface-flush .tbl td:last-child { padding-right: 1.25rem; }

.amount { white-space: nowrap; }
.amount.haben { color: var(--haben); }
.amount.soll { color: var(--soll); }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 0.76rem; font-weight: 600; padding: 0.12rem 0.5rem; border-radius: var(--radius-s); background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge-ok { background: var(--haben-soft); color: var(--haben); border-color: transparent; }
.badge-bad { background: var(--soll-soft); color: var(--soll); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-info { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

/* ---------- Formulare ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 0.9rem 1rem; }
.form-grid > * { grid-column: span 6; }
.form-grid .span-3 { grid-column: span 3; }
.form-grid .span-4 { grid-column: span 4; }
.form-grid .span-8 { grid-column: span 8; }
.form-grid .span-12 { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid > *, .form-grid .span-3, .form-grid .span-4, .form-grid .span-8 { grid-column: 1 / -1; } }
.field label, .field-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--muted); margin-bottom: 0.25rem; }
.field .hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.input, .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea,
.filters input:not([type="checkbox"]), .filters select {
  width: 100%; font: inherit; font-size: 0.92rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m);
  padding: 0.5rem 0.65rem;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .filters input:focus, .filters select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.25rem; flex-wrap: wrap; }

.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { min-width: 140px; }
.filters .field.grow { flex: 1 1 220px; }
.filters .check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.88rem; padding-bottom: 0.55rem; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-m); overflow: hidden; background: var(--surface); }
.segmented a { padding: 0.42rem 0.8rem; font-size: 0.85rem; color: var(--ink); text-decoration: none; border-left: 1px solid var(--line); }
.segmented a:first-child { border-left: 0; }
.segmented a[aria-current="true"] { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.segmented .count { color: inherit; opacity: 0.7; margin-left: 0.25rem; }

/* Positionen-Editor (Angebote/Rechnungen) */
.positions .tbl td { padding: 0.45rem 0.5rem; }
.positions .tbl input, .positions .tbl textarea { width: 100%; font: inherit; font-size: 0.9rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m); padding: 0.4rem 0.5rem; }
.positions .tbl textarea { margin-top: 0.3rem; resize: vertical; }
.positions .rabatt-zeile { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
.positions .rabatt-zeile #rabatt-prozent { width: 5rem; }
.positions .rabatt-zeile #rabatt-bezeichnung { width: 16rem; max-width: 100%; }
.positions .rabatt-zeile[hidden], .positions [hidden] { display: none; }
.positions .total { text-align: right; font-weight: 700; font-size: 1.05rem; padding: 0.8rem 0.5rem 0.2rem; }

/* ---------- Meldungen ---------- */
.flash { margin: 0 0 1rem; padding: 0.65rem 0.95rem; border-radius: var(--radius-m); background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 25%, transparent); font-size: 0.92rem; }
.notice { padding: 0.75rem 1rem; border-radius: var(--radius-m); background: var(--warn-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); margin-bottom: 1rem; font-size: 0.9rem; }

.pagination { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem 1.25rem; border-top: 1px solid var(--line); font-size: 0.88rem; color: var(--muted); }

/* Alt-Klassen, die einzelne noch nicht umgestellte Seiten verwenden */
.btn-outline, .btn-solid { display: inline-flex; align-items: center; font-size: 0.85rem; font-weight: 600; padding: 0.5rem 0.9rem; border-radius: var(--radius-m); text-decoration: none; }
.btn-outline { border: 1px solid var(--line-strong); color: var(--ink); background: var(--surface); }
.btn-solid { border: 1px solid var(--brand); color: var(--brand-ink); background: var(--brand); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.totals { margin-left: auto; max-width: 440px; padding: 0 1.25rem 0.5rem; }
.totals .tbl tfoot td { padding-left: 0; }
.totals .tbl tfoot td:last-child { padding-right: 0; }

/* ---------- Dialoge ---------- */
.dialog { border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); color: var(--ink); padding: 1.25rem 1.4rem; width: min(760px, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgb(14 19 38 / 0.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.dialog-foot { display: flex; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* Auswahl als Segmente (Radio) */
.segmented label { color: var(--ink); }
.segmented label:first-child { border-left: 0 !important; }
.segmented label input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }

/* ---------- Kleinteile für Formulare und Status ---------- */
.segmented label { padding: 0.42rem 0.8rem; font-size: 0.85rem; border-left: 1px solid var(--line); cursor: pointer; }
.check-row { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.9rem; }
.check-row input { margin-top: 0.2rem; }
.dropzone {
  display: grid; place-items: center; gap: 0.35rem; text-align: center; cursor: pointer;
  padding: 2.5rem 1rem; border: 2px dashed var(--line-strong); border-radius: var(--radius-l);
  background: var(--surface-2); color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone strong { color: var(--ink); font-size: 1rem; }
.dropzone:hover, .dropzone.dragover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone .files { color: var(--ink); font-size: 0.88rem; overflow-wrap: anywhere; }
.status-line { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.status-line::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--muted); }
.status-line.ok::before { background: var(--haben); }
.status-line.bad::before { background: var(--soll); }
.positions .tbl select { width: 100%; font: inherit; font-size: 0.9rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m); padding: 0.4rem 0.5rem; }
.positions .tbl td { vertical-align: middle; }
details.inline-details > summary { cursor: pointer; color: var(--link); font-size: 0.85rem; width: fit-content; }
details.inline-details[open] > summary { margin-bottom: 0.6rem; }
.lead { color: var(--muted); max-width: 72ch; font-size: 0.92rem; }
.bar-track { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; height: 8px; overflow: hidden; min-width: 90px; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--brand); }
.bar-fill.ok { background: var(--haben); }
.bar-fill.warnung { background: var(--warn); }
.bar-fill.ueber { background: var(--soll); }
.input-num { width: 100%; max-width: 9rem; text-align: right; }

/* ---------- Monats-Balkendiagramm (_monatschart.html) ---------- */
  :root { --chart-ein: #1D7A4F; --chart-aus: #E0806B; }
  @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --chart-ein: #38A672; --chart-aus: #B34237; } }
  .chart { position: relative; }
  .chart svg { width: 100%; height: 240px; display: block; overflow: visible; }
  .chart .grid { stroke: var(--line); stroke-width: 1; }
  .chart .axis-label { fill: var(--muted); font-size: 11px; }
  .chart .bar-ein { fill: var(--chart-ein); }
  .chart .bar-aus { fill: var(--chart-aus); }
  .chart .hit { fill: transparent; cursor: default; }
  .chart .hit:hover { fill: var(--ink); fill-opacity: 0.05; }
  .legend { display: flex; gap: 1.1rem; font-size: 0.85rem; color: var(--muted); }
  .legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 0.35rem; vertical-align: -1px; }
  .legend .ein::before { background: var(--chart-ein); }
  .legend .aus::before { background: var(--chart-aus); }
  .tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m); padding: 0.5rem 0.7rem; font-size: 0.82rem; min-width: 170px; display: none; z-index: 2; box-shadow: 0 6px 20px rgb(0 0 0 / 0.12); }
  .tooltip .row { display: flex; justify-content: space-between; gap: 1rem; }
  .tooltip .row span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 0.35rem; }
  .tooltip .ein span::before { background: var(--chart-ein); } .tooltip .aus span::before { background: var(--chart-aus); }
  details.table-view summary { cursor: pointer; color: var(--link); font-size: 0.85rem; margin-top: 0.6rem; }
.tbl tfoot.add-row td { font-weight: 400; }
