
  :root{
    --bg:#f4f5f2;
    --surface:#ffffff;
    --surface-2:#eceee8;
    --ink:#1e2222;
    --ink-muted:#5c6360;
    --line:#daddd6;
    --accent:#1c3d5a;
    --accent-strong:#132c40;
    --accent-ink:#ffffff;
    --accent-soft:#e4ebf1;
    --ok:#3f7d52;
    --ok-soft:#e5f1e7;
    --warn:#a56a14;
    --warn-soft:#f6ecd9;
    --brand-orange:#e5690b;
    --danger:#b1433a;
    --danger-soft:#f7e6e4;
    --shadow: 0 1px 2px rgba(30,34,34,.06), 0 8px 24px -12px rgba(30,34,34,.18);
    color-scheme: light;
  }
  @media (prefers-color-scheme: dark){
    :root:not([data-theme="light"]){
      --bg:#14181a;
      --surface:#1b2124;
      --surface-2:#212a2c;
      --ink:#e8eae6;
      --ink-muted:#9aa3a0;
      --line:#2b3538;
      --accent:#7ba7c9;
      --accent-strong:#a3c4e0;
      --accent-ink:#0f1714;
      --accent-soft:#1e2a33;
      --ok:#79c68d;
      --ok-soft:#1c2c20;
      --warn:#e3ac57;
      --warn-soft:#332a17;
      --brand-orange:#f0954a;
      --danger:#e2938a;
      --danger-soft:#33201e;
      --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.5);
      color-scheme: dark;
    }
  }
  :root[data-theme="dark"]{
    --bg:#14181a;
    --surface:#1b2124;
    --surface-2:#212a2c;
    --ink:#e8eae6;
    --ink-muted:#9aa3a0;
    --line:#2b3538;
    --accent:#7ba7c9;
    --accent-strong:#a3c4e0;
    --accent-ink:#0f1714;
    --accent-soft:#1e2a33;
    --ok:#79c68d;
    --ok-soft:#1c2c20;
    --warn:#e3ac57;
    --warn-soft:#332a17;
    --brand-orange:#f0954a;
    --danger:#e2938a;
    --danger-soft:#33201e;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.5);
    color-scheme: dark;
  }

  *,*::before,*::after{box-sizing:border-box;}
  html,body{margin:0;padding:0;}
  body{
    background:var(--bg);
    color:var(--ink);
    font-family:"IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size:15px;
    line-height:1.5;
    -webkit-font-smoothing:antialiased;
  }
  h1,h2,h3{ text-wrap:balance; margin:0; font-family:"IBM Plex Sans",sans-serif; font-weight:600; }
  button{ font-family:inherit; }
  input,select,textarea{ font-family:inherit; font-size:inherit; color:inherit; }
  .num{ font-variant-numeric: tabular-nums; font-feature-settings:"tnum" 1; }
  .wfull{ width:100%; justify-content:center; }

  a{color:var(--accent-strong);}

  /* ---- shell ---- */
  #root{ min-height:100vh; display:flex; flex-direction:column; }

  .topbar{
    display:flex; align-items:center; gap:20px;
    padding:14px 28px; border-bottom:1px solid var(--line);
    background:var(--surface);
    position:sticky; top:0; z-index:20;
  }
  .brand{ display:flex; align-items:center; gap:10px; margin-right:8px; }
  .brand-mark{ height:30px; width:auto; flex:none; }
  .brand-name{ font-weight:700; font-size:1.05rem; letter-spacing:-0.01em; white-space:nowrap; }
  nav.tabs{ display:flex; gap:2px; flex:1; }
  nav.tabs button{
    appearance:none; border:none; background:transparent; color:var(--ink-muted);
    padding:9px 14px; border-radius:7px; font-size:.92rem; font-weight:500; cursor:pointer;
    transition:background .12s ease, color .12s ease;
  }
  nav.tabs button:hover{ background:var(--surface-2); color:var(--ink); }
  nav.tabs button[aria-selected="true"]{ background:var(--accent-soft); color:var(--accent-strong); font-weight:600; }
  .topbar-right{ display:flex; align-items:center; gap:10px; margin-left:auto; }

  .icon-btn{
    appearance:none; border:1px solid var(--line); background:var(--surface); color:var(--ink-muted);
    width:34px; height:34px; border-radius:8px; display:flex; align-items:center; justify-content:center;
    cursor:pointer; transition:background .12s ease, color .12s ease, border-color .12s ease;
  }
  .icon-btn:hover{ background:var(--surface-2); color:var(--ink); }
  .icon-btn svg{ width:17px; height:17px; }

  main{ flex:1; padding:28px; max-width:1280px; width:100%; margin:0 auto; }
  .view{ display:none; flex-direction:column; gap:22px; }
  .view.active{ display:flex; }

  .view-head{ display:flex; align-items:baseline; justify-content:space-between; gap:16px; flex-wrap:wrap; }
  .view-head h1{ font-size:1.5rem; }
  .view-head p{ margin:4px 0 0; color:var(--ink-muted); font-size:.92rem; }

  /* buttons */
  .btn{
    appearance:none; border:1px solid var(--line); background:var(--surface); color:var(--ink);
    padding:9px 15px; border-radius:8px; font-size:.88rem; font-weight:500; cursor:pointer;
    display:inline-flex; align-items:center; gap:7px; white-space:nowrap;
    transition:background .12s ease, border-color .12s ease, transform .05s ease;
  }
  .btn:hover{ background:var(--surface-2); }
  .btn:active{ transform:translateY(1px); }
  .btn svg{ width:15px; height:15px; flex:none; }
  .btn-primary{ background:var(--accent); border-color:var(--accent); color:var(--accent-ink); }
  .btn-primary:hover{ background:var(--accent-strong); border-color:var(--accent-strong); }
  .btn-ghost{ border-color:transparent; background:transparent; }
  .btn-ghost:hover{ background:var(--surface-2); }
  .btn-danger{ color:var(--danger); }
  .btn-danger:hover{ background:var(--danger-soft); }
  .btn-sm{ padding:6px 11px; font-size:.8rem; border-radius:7px; }
  .btn:focus-visible, .icon-btn:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible{
    outline:2px solid var(--accent); outline-offset:2px;
  }
  .btn[disabled]{ opacity:.5; cursor:not-allowed; }

  /* cards / sections */
  .card{ background:var(--surface); border:1px solid var(--line); border-radius:12px; box-shadow:var(--shadow); overflow:hidden; }
  .card-head{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:16px 18px; border-bottom:1px solid var(--line); flex-wrap:wrap; }
  .card-head h2{ font-size:1.02rem; }
  .card-body{ padding:16px 18px; }

  .filter-row{ display:flex; gap:6px; flex-wrap:wrap; }
  .filter-row button{
    appearance:none; border:1px solid var(--line); background:var(--surface); color:var(--ink-muted);
    padding:5px 11px; border-radius:999px; font-size:.78rem; cursor:pointer;
  }
  .filter-row button[aria-pressed="true"]{ background:var(--accent-soft); border-color:var(--accent-soft); color:var(--accent-strong); font-weight:600; }

  .table-wrap{ overflow-x:auto; }
  /* Eigener Scrollbereich für die (potenziell lange) Rechnungsliste: die
     Seite selbst wird dadurch nicht länger, stattdessen scrollt nur die
     Tabelle - die Kopfzeile bleibt dabei oben sichtbar ("sticky"). */
  /* max-height wird per JS exakt auf "Kopfzeile + 5 Zeilen + Gesamt-Zeile"
     gesetzt (siehe setzeTabellenScrollHoehe in app.js) - der feste Wert hier
     ist nur ein Fallback, falls JS das aus irgendeinem Grund nicht schafft. */
  .table-wrap-scroll{ max-height:320px; overflow-y:auto; }
  .table-wrap-scroll thead th{ position:sticky; top:0; z-index:2; box-shadow:0 1px 0 var(--line); }
  .table-wrap-scroll tfoot td{ position:sticky; bottom:0; z-index:2; background:var(--surface); box-shadow:0 -1px 0 var(--line); }
  table{ width:100%; border-collapse:collapse; font-size:.86rem; min-width:760px; }
  /* Für schmale Tabellen mit wenigen Spalten (z. B. die Zahlungsliste einer
     Rechnung, die neben einer zweiten Karte in einer schmalen Spalte steht):
     die pauschale Mindestbreite von 760px oben ist für Tabellen mit vielen
     Spalten (Rechnungsliste, Saldenliste) gedacht - hier würde sie unnötig
     zum horizontalen Scrollen zwingen und die Spalten nicht mehr mit dem
     darunterliegenden Formular (z. B. "Zahlung hinzufügen") übereinstimmen
     lassen. */
  table.table-compact{ min-width:0; }
  thead th{
    text-align:left; font-size:.72rem; text-transform:uppercase; letter-spacing:.06em; color:var(--brand-orange);
    font-weight:700; padding:10px 14px; border-bottom:1px solid var(--line); white-space:nowrap;
    background:var(--surface);
  }
  th.sortable{ cursor:pointer; user-select:none; }
  th.sortable:hover{ color:var(--ink); }
  th.sortable .sort-arrow{ display:inline-block; margin-left:4px; opacity:.35; font-size:.7em; }
  th.sortable.sort-active .sort-arrow{ opacity:1; }
  tbody td{ padding:10px 14px; border-bottom:1px solid var(--line); vertical-align:middle; }
  tbody tr:last-child td{ border-bottom:none; }
  tbody tr.clickable{ cursor:pointer; }
  tbody tr.clickable:hover{ background:var(--surface-2); }
  tbody tr.selected{ background:var(--accent-soft); }
  tfoot td{ font-weight:600; border-top:2px solid var(--line); border-bottom:none; padding:10px 14px; }
  td.num, th.num{ text-align:right; }
  .col-actions{ text-align:right; white-space:nowrap; }
  .row-actions{ display:inline-flex; gap:4px; }

  .offen-pos{ color:var(--danger); font-weight:600; }
  .offen-null{ color:var(--ok); font-weight:600; }
  .muted{ color:var(--ink-muted); }

  .empty{ padding:48px 24px; text-align:center; color:var(--ink-muted); }
  .empty svg{ width:34px; height:34px; margin-bottom:10px; opacity:.5; }
  .empty p{ margin:4px 0 14px; font-size:.9rem; }

  /* filter form (rechnungen view) */
  .search-form{ display:flex; flex-direction:column; gap:14px; padding:16px 18px; }
  .field-grid{ display:grid; grid-template-columns:repeat(5,1fr); gap:12px; }
  .radios{ display:flex; gap:16px; flex-wrap:wrap; font-size:.88rem; }
  .radios label{ display:flex; align-items:center; gap:6px; cursor:pointer; }
  .row-between{ display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:12px; }

  /* selected-invoice summary */
  .summary-box{ background:var(--surface-2); border-radius:8px; padding:14px 16px; }
  .summary-line{ display:flex; justify-content:space-between; padding:4px 0; font-size:.9rem; }
  .summary-line.total{ border-top:1px solid var(--line); margin-top:6px; padding-top:8px; font-weight:600; }

  .gutschrift-box{ border:1px solid var(--line); border-radius:8px; padding:14px; }

  /* modal */
  .modal-overlay{
    position:fixed; inset:0; background:rgba(15,18,17,.45); display:flex; align-items:flex-start;
    justify-content:center; padding:5vh 16px; overflow-y:auto; z-index:100;
  }
  .modal{
    background:var(--surface); border-radius:14px; width:100%; max-width:560px; box-shadow:0 24px 64px -20px rgba(0,0,0,.4);
    border:1px solid var(--line);
  }
  .modal.wide{ max-width:820px; }
  .modal-head{ display:flex; align-items:flex-start; justify-content:space-between; gap:12px; padding:20px 22px 14px; }
  .modal-head h2{ font-size:1.15rem; }
  .modal-head p{ margin:4px 0 0; color:var(--ink-muted); font-size:.85rem; }
  .modal-body{ padding:2px 22px 4px; display:flex; flex-direction:column; gap:14px; max-height:68vh; overflow-y:auto; }
  .modal-foot{ display:flex; justify-content:flex-end; gap:10px; padding:16px 22px 22px; flex-wrap:wrap; }
  .modal-foot.between{ justify-content:space-between; }

  .field{ display:flex; flex-direction:column; gap:6px; }
  .field label{ font-size:.8rem; font-weight:600; color:var(--ink-muted); }
  .field .hint{ font-size:.76rem; color:var(--ink-muted); font-weight:400; }
  .field input, .field select, .field textarea{
    border:1px solid var(--line); background:var(--bg); color:var(--ink); border-radius:8px; padding:9px 11px; font-size:.9rem;
    width:100%;
  }
  .field input:disabled{ background:var(--surface-2); font-weight:600; color:var(--ink); }
  .field textarea{ resize:vertical; min-height:60px; }
  .field-row{ display:grid; grid-template-columns:1fr 1fr; gap:12px; }
  .field-row-3{ display:grid; grid-template-columns:1fr 1fr 1fr; gap:12px; }
  fieldset{ border:1px solid var(--line); border-radius:8px; padding:10px 12px; margin:0; }
  legend{ font-size:.8rem; font-weight:600; color:var(--ink-muted); padding:0 4px; }

  hr.sep{ border:none; border-top:1px solid var(--line); margin:6px 0; }

  /* toast */
  #toast{
    position:fixed; bottom:22px; left:50%; transform:translateX(-50%) translateY(12px); opacity:0;
    background:var(--ink); color:var(--bg); padding:10px 18px; border-radius:8px; font-size:.86rem;
    box-shadow:0 10px 30px rgba(0,0,0,.25); z-index:200; pointer-events:none; transition:opacity .18s ease, transform .18s ease;
  }
  #toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }

  /* print sheet (tabular / Mahnung) - siehe app.js "print views (PDF-Export)":
     bewusst reine Browser-Druckansicht statt serverseitiger PDF-Bibliothek. */
  .print-sheet{ font-family:"IBM Plex Sans", sans-serif; color:#20221f; background:#fff; padding:8px 6px; font-size:.85rem; }
  .print-sheet h3{ font-size:1.15rem; margin:0 0 4px; color:var(--accent); }
  .print-sheet .doc-sub{ color:#5c6360; font-size:.8rem; margin-bottom:16px; }
  .print-sheet table{ min-width:0; font-size:.78rem; }
  .print-letterhead{ font-size:.78rem; line-height:1.5; color:#5c6360; margin-bottom:22px; padding-bottom:10px; border-bottom:1px solid #ccc; }
  .print-hinweis{ margin-top:22px; font-size:.68rem; color:#5c6360; }
  .print-actions{ display:flex; justify-content:flex-end; gap:10px; padding:14px 22px 20px; border-top:1px solid var(--line); }

  @media print{
    body *{ visibility:hidden; }
    .print-sheet, .print-sheet *{ visibility:visible; }
    .print-sheet{ position:absolute; top:0; left:0; width:100%; padding:0 16px; }
  }

  @media (max-width:900px){
    .field-grid{ grid-template-columns:repeat(2,1fr); }
  }
  @media (max-width:760px){
    .field-row, .field-row-3{ grid-template-columns:1fr; }
    main{ padding:18px; }
    .topbar{ padding:12px 16px; flex-wrap:wrap; }
    nav.tabs{ order:3; width:100%; }
  }
  @media (prefers-reduced-motion: reduce){
    *{ transition:none !important; animation:none !important; }
  }

  /* ---- login screen (embedded in index.html, toggled via JS) ---- */
  .center-screen{
    min-height:100vh; display:flex; align-items:center; justify-content:center;
    padding:24px; background:var(--bg); color:var(--ink);
  }
  .login-card{
    width:100%; max-width:380px; background:var(--surface); border:1px solid var(--line);
    border-radius:14px; box-shadow:var(--shadow); padding:32px 28px;
  }
  .login-brand{ display:flex; align-items:center; gap:10px; margin-bottom:22px; color:var(--accent); font-weight:700; }
  .brand-logo{ height:44px; width:auto; flex:none; }
  .login-card h1{ font-size:1.3rem; margin-bottom:18px; }
  .login-card form{ display:flex; flex-direction:column; gap:14px; }
  .login-card .btn{ justify-content:center; margin-top:4px; }
  .login-info{
    background:var(--warn-soft); color:var(--warn); border-radius:8px; padding:9px 12px;
    font-size:.85rem; margin-bottom:16px; line-height:1.5;
  }
  .login-info code{ background:rgba(0,0,0,.06); padding:1px 5px; border-radius:4px; }
  .login-foot{ margin-top:18px; text-align:center; font-size:.78rem; color:var(--ink-muted); }
  .msg{ font-size:.85rem; padding:9px 12px; border-radius:8px; margin-bottom:16px; }
  .msg-error{ background:var(--danger-soft); color:var(--danger); }
  .msg-ok{ background:var(--ok-soft); color:var(--ok); }

  /* ---- topbar user menu ---- */
  .user-chip{ display:flex; align-items:center; gap:8px; font-size:.82rem; color:var(--ink-muted); }
  .user-chip strong{ color:var(--ink); font-weight:600; }
  .user-chip a{ color:var(--ink-muted); text-decoration:none; border-left:1px solid var(--line); padding-left:8px; cursor:pointer; }
  .user-chip a:hover{ color:var(--danger); }

  /* ---- connection banner ---- */
  .conn-banner{
    display:flex; align-items:center; gap:10px; justify-content:space-between; flex-wrap:wrap;
    background:var(--danger-soft); color:var(--danger); border:1px solid var(--danger-soft);
    border-radius:10px; padding:12px 16px; font-size:.88rem;
  }
  .conn-banner .btn{ border-color:var(--danger); color:var(--danger); }

  /* ---- busy state ---- */
  .btn[data-busy="true"]{ opacity:.65; pointer-events:none; }
