
  :root{
    --bg:#f4f5f2;
    --surface:#ffffff;
    --surface-2:#eceee8;
    --ink:#1e2222;
    --ink-muted:#5c6360;
    --line:#daddd6;
    --accent:#34544a;
    --accent-strong:#24382f;
    --accent-ink:#ffffff;
    --accent-soft:#e3ece8;
    --ok:#3f7d52;
    --ok-soft:#e5f1e7;
    --warn:#a56a14;
    --warn-soft:#f6ecd9;
    --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:#7bb6a1;
      --accent-strong:#9bcbb9;
      --accent-ink:#0f1714;
      --accent-soft:#20302b;
      --ok:#79c68d;
      --ok-soft:#1c2c20;
      --warn:#e3ac57;
      --warn-soft:#332a17;
      --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:#7bb6a1;
    --accent-strong:#9bcbb9;
    --accent-ink:#0f1714;
    --accent-soft:#20302b;
    --ok:#79c68d;
    --ok-soft:#1c2c20;
    --warn:#e3ac57;
    --warn-soft:#332a17;
    --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; }
  .mono{ font-family:"IBM Plex Mono", ui-monospace, monospace; }

  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{ width:30px; height:30px; flex:none; color:var(--accent); }
  .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; }
  .status-pill{
    display:flex; align-items:center; gap:6px; font-size:.78rem; color:var(--ink-muted);
    padding:5px 10px; border-radius:999px; border:1px solid var(--line); white-space:nowrap;
  }
  .status-dot{ width:7px; height:7px; border-radius:50%; background:var(--ink-muted); flex:none; }
  .status-pill[data-state="live"] .status-dot{ background:var(--ok); }
  .status-pill[data-state="live"]{ color:var(--ok); border-color:var(--ok-soft); background:var(--ok-soft); }
  .status-pill[data-state="local"] .status-dot{ background:var(--warn); }
  .status-pill[data-state="local"]{ color:var(--warn); border-color:var(--warn-soft); background:var(--warn-soft); }
  .status-pill[data-state="readonly"] .status-dot{ background:var(--danger); }
  .status-pill[data-state="readonly"]{ color:var(--danger); border-color:var(--danger-soft); background:var(--danger-soft); }

  .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:1180px; 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; }

  /* stat tiles */
  .stats{ display:grid; grid-template-columns:repeat(4,1fr); gap:14px; }
  .stat{
    background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:16px 18px;
    display:flex; flex-direction:column; gap:6px; box-shadow:var(--shadow);
  }
  .stat .label{ font-size:.72rem; text-transform:uppercase; letter-spacing:.06em; color:var(--ink-muted); font-weight:600; }
  .stat .value{ font-size:1.6rem; font-weight:700; letter-spacing:-0.01em; }
  .stat .sub{ font-size:.78rem; color:var(--ink-muted); }
  .stat.accent .value{ color:var(--accent-strong); }

  /* 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; }
  .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; }
  table{ width:100%; border-collapse:collapse; font-size:.88rem; min-width:760px; }
  thead th{
    text-align:left; font-size:.72rem; text-transform:uppercase; letter-spacing:.06em; color:var(--ink-muted);
    font-weight:600; padding:10px 18px; border-bottom:1px solid var(--line); white-space:nowrap;
  }
  tbody td{ padding:13px 18px; border-bottom:1px solid var(--line); vertical-align:middle; }
  tbody tr:last-child td{ border-bottom:none; }
  tbody tr:hover{ background:var(--surface-2); }
  .col-actions{ text-align:right; white-space:nowrap; }
  .row-actions{ display:inline-flex; gap:4px; }

  .type-tag{ display:inline-flex; align-items:center; gap:7px; font-weight:500; }
  .type-tag svg{ width:16px; height:16px; color:var(--ink-muted); flex:none; }
  .obj-name{ font-weight:600; }
  .obj-addr{ color:var(--ink-muted); font-size:.82rem; }

  .chip{ display:inline-flex; align-items:center; gap:6px; padding:3px 10px 3px 8px; border-radius:999px; font-size:.76rem; font-weight:600; white-space:nowrap; }
  .chip::before{ content:""; width:6px; height:6px; border-radius:50%; background:currentColor; }
  .chip.vermietet{ background:var(--ok-soft); color:var(--ok); }
  .chip.frei{ background:var(--warn-soft); color:var(--warn); }

  .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; }

  /* contract list */
  .contract-list{ display:flex; flex-direction:column; }
  .contract-row{ display:flex; align-items:center; gap:14px; padding:14px 18px; border-bottom:1px solid var(--line); flex-wrap:wrap; }
  .contract-row:last-child{ border-bottom:none; }
  .contract-row .who{ font-weight:600; }
  .contract-row .meta{ color:var(--ink-muted); font-size:.82rem; }
  .contract-row .spacer{ flex:1; }

  /* 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:760px; }
  .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:64vh; overflow-y:auto; }
  .modal-foot{ display:flex; justify-content:flex-end; gap:10px; padding:16px 22px 22px; }

  .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 textarea{ resize:vertical; min-height:70px; }
  .field-row{ display:grid; grid-template-columns: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; }
  .radio-row{ display:flex; gap:16px; flex-wrap:wrap; }
  .radio-row label{ display:flex; align-items:center; gap:6px; font-size:.88rem; font-weight:500; cursor:pointer; }

  /* 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 */
  .print-sheet{ font-family:"IBM Plex Serif", Georgia, serif; color:#20221f; background:#fff; padding:8px 6px; font-size:.95rem; line-height:1.6; }
  .print-sheet h3{ font-family:"IBM Plex Serif", Georgia, serif; font-size:1.25rem; text-align:center; margin:0 0 6px; }
  .print-sheet .doc-sub{ text-align:center; color:#5c6360; font-size:.85rem; margin-bottom:22px; }
  .print-sheet section{ margin-bottom:14px; }
  .print-sheet section h4{ font-size:.92rem; margin:0 0 4px; font-weight:600; }
  .print-sheet section p{ margin:0; }
  .print-sheet .sign-row{ display:flex; justify-content:space-between; gap:40px; margin-top:36px; }
  .print-sheet .sign-line{ flex:1; border-top:1px solid #999; padding-top:6px; text-align:center; font-size:.82rem; color:#5c6360; }
  .print-sheet .disclaimer{ margin-top:26px; padding-top:12px; border-top:1px dashed #ccc; font-family:"IBM Plex Sans",sans-serif; font-size:.74rem; color:#7a807c; }
  .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 24px; }
  }

  @media (max-width:760px){
    .stats{ grid-template-columns:1fr 1fr; }
    .field-row{ 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 page ---- */
  .login-body{
    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; }
  .login-brand svg{ width:26px; height:26px; }
  .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-error{
    background:var(--danger-soft); color:var(--danger); border-radius:8px; padding:9px 12px;
    font-size:.85rem; margin-bottom:16px;
  }
  .login-foot{ margin-top:18px; text-align:center; font-size:.78rem; color:var(--ink-muted); }

  /* ---- 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; }
  .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; }
