:root {
  --paper: #eef1f4;
  --surface: #ffffff;
  --ink: #1c2733;
  --ink-2: #4d5b68;
  --line: #d6dce2;
  --slate: #22303c;
  --slate-2: #2f3f4d;
  --teal: #0e7c7b;
  --red: #b23a3a;
  --amber: #9a6b12;
  --amber-bg: #fbf2dc;
  --info-bg: #e6f0f5;
  --focus: #0e7c7b;
  --radius: 6px;
  --sidebar-w: 300px;
  --results-w: 420px;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); }
body { line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; letter-spacing: -0.01em; font-weight: 600; }
b, td, th, .li-meta { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.pad { padding: 14px 16px; }
.pos { color: var(--teal); }
.neg { color: var(--red); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  height: 56px; padding: 0 16px;
  background: var(--slate); color: #fff;
}
.brand { font-weight: 700; letter-spacing: 0.02em; font-size: 17px; }
.topbar-title { flex: 1; color: #c9d3dc; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }
.burger { display: none; background: none; border: 0; padding: 8px 6px; cursor: pointer; }
.burger span { display: block; width: 22px; height: 2px; background: #fff; margin: 4px 0; border-radius: 2px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid #5c6d7c; background: var(--slate-2); color: #fff;
  padding: 7px 14px; border-radius: var(--radius); font: inherit; font-size: 14px;
  cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: #3a4c5c; }
.btn.primary { background: var(--teal); border-color: var(--teal); }
.btn.primary:hover { background: #0a6362; }
.btn.ghost { background: transparent; border-color: transparent; color: #c9d3dc; }
.btn.ghost:hover { color: #fff; background: rgba(255,255,255,.08); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: #f6e3e3; }
.btn.wide { width: 100%; padding: 11px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--surface);
  border-right: 1px solid var(--line);
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
}
.sidebar-head { padding: 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.search {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px;
  font: inherit; background: var(--paper);
}
.calc-list { list-style: none; margin: 0; padding: 6px 0; }
.calc-list li[data-id] { padding: 10px 14px; cursor: pointer; border-left: 3px solid transparent; }
.calc-list li[data-id]:hover { background: var(--paper); }
.calc-list li.active { border-left-color: var(--teal); background: #eaf4f3; }
.li-name { font-weight: 600; }
.li-obj { color: var(--ink-2); font-size: 13px; }
.li-meta { display: flex; gap: 10px; font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }

/* ---------- Objekte mit nummerierten Varianten ---------- */
.calc-list li.obj { padding: 10px 12px 12px; border-left: 3px solid transparent; border-bottom: 1px solid var(--line); cursor: default; }
.calc-list li.obj.aktiv { border-left-color: var(--teal); background: #f3f8f8; }
.obj-kopf { cursor: pointer; }
.obj-kopf:hover .li-name { color: var(--teal); }
.varianten { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.variante {
  display: flex; align-items: center; gap: 6px; max-width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper);
  padding: 4px 8px; font: inherit; font-size: 12.5px; color: var(--ink-2); cursor: pointer;
}
.variante b { font-size: 13px; color: var(--ink); font-variant-numeric: tabular-nums; }
.variante span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.variante:hover { border-color: var(--teal); background: #eaf4f3; }
.variante.active { border-color: var(--teal); background: var(--teal); color: #fff; }
.variante.active b { color: #fff; }
.nummer-badge {
  display: inline-block; margin-left: 8px; padding: 1px 9px; border-radius: 10px;
  background: #e2f1ef; color: var(--teal); font-size: 12px; font-weight: 600; vertical-align: 2px;
}
.danger-zone { display: flex; flex-wrap: wrap; gap: 10px; }
.scrim { display: none; }
.sidebar-foot { display: none; border-top: 1px solid var(--line); padding: 10px 16px 18px; }
.sidebar-foot a, .sidebar-foot .whoami { display: block; padding: 6px 0; color: var(--ink-2); text-decoration: none; }
.sidebar-foot .whoami { color: var(--ink); font-weight: 600; max-width: none; }
.sidebar-foot a:hover { color: var(--teal); }

.content {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) var(--results-w);
  gap: 24px; padding: 24px; align-items: start; max-width: 1400px;
}

/* ---------- Form ---------- */
.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.block h2 { font-size: 15px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.field > span:first-child { color: var(--ink-2); }
.field small { color: var(--ink-2); font-size: 12px; opacity: .85; }
/* Alle Eingabearten gleich stylen - sonst faellt genau eine (etwa email)
   auf die Standardbox des Browsers zurueck. */
.field input[type="text"], .field input[type="password"],
.field input[type="email"], .field input[type="url"],
.field input[type="number"], .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius);
  background: #f7f9fa; padding: 8px 10px; font: inherit; font-size: 15px; color: var(--ink);
  transition: border-color .12s, background .12s;
}
.field input:-webkit-autofill { -webkit-box-shadow: 0 0 0 40px #f7f9fa inset; -webkit-text-fill-color: var(--ink); }
.field input:focus, .field textarea:focus { background: #fff; border-color: var(--teal); outline: none; box-shadow: 0 0 0 3px rgba(14,124,123,.15); }
.unitwrap { display: flex; align-items: stretch; }
.field .unitwrap input { flex: 1; min-width: 0; text-align: right; border-radius: 0; border-left: 0; border-right: 0; }
.unitwrap em {
  flex: none; display: flex; align-items: center; padding: 0 9px;
  border: 1px solid var(--line); border-left: 0; border-right: 0;
  background: #eceff2; font-style: normal; font-size: 12px; color: var(--ink-2); white-space: nowrap;
}

/* Schrittknoepfe. Die Felder bleiben Textfelder wegen der deutschen
   Schreibweise, deshalb eigene Knoepfe statt input[type=number]. */
.step {
  flex: none; width: 32px; padding: 0; cursor: pointer;
  border: 1px solid var(--line); background: #eceff2; color: var(--ink-2);
  font: inherit; font-size: 17px; line-height: 1; user-select: none;
}
.step.minus { border-radius: var(--radius) 0 0 var(--radius); }
.step.plus  { border-radius: 0 var(--radius) var(--radius) 0; }
.step:hover { background: #dfe4e9; color: var(--ink); }
.step:active { background: #d2d9df; }
.unitwrap:focus-within .step, .unitwrap:focus-within em,
.unitwrap:focus-within input { border-color: var(--teal); }

/* Feld kurz hervorheben, wenn der Import es gefuellt hat */
.uebernommen { background: #e2f1ef !important; border-color: var(--teal) !important; }

/* Import aus Inserat */
.importtext { margin: 4px 0 10px; }
.importtext summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
.importtext textarea {
  width: 100%; margin: 10px 0 8px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #f7f9fa; padding: 8px 10px; font: inherit; font-size: 13.5px; resize: vertical;
}
.import-block { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; font-size: 13.5px; }
.import-block ul { margin: 4px 0 0; padding-left: 18px; }
.import-block li { margin: 2px 0; }

/* Jahresverlauf oeffnet ein eigenes Fenster */
.jahre-panel { padding: 12px 14px; }
.jahre-kopf { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 9px; }
.jahre-panel .btn.wide { padding: 9px; }
.jahre-panel p { margin: 8px 0 0; }

.note-add { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.note-add textarea { flex: 1; border: 1px solid var(--line); border-radius: var(--radius); background: #f7f9fa; padding: 8px 10px; font: inherit; resize: vertical; }
.note-add .btn { flex: none; background: var(--slate); }
.notes { list-style: none; margin: 0; padding: 0; }
.notes li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.note-date { font-size: 12px; color: var(--ink-2); }
.note-text { grid-column: 1; white-space: pre-wrap; }
.note-del { grid-row: 1 / span 2; grid-column: 2; align-self: start; background: none; border: 0; color: var(--ink-2); font-size: 18px; cursor: pointer; padding: 0 4px; }
.note-del:hover { color: var(--red); }

/* ---------- Quellen ---------- */
.note-add input[type="text"] { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: #f7f9fa; padding: 8px 10px; font: inherit; }
.note-add input[type="text"]:focus { background: #fff; border-color: var(--teal); outline: none; box-shadow: 0 0 0 3px rgba(14,124,123,.15); }
.note-add #quelleTitel { flex: 0 1 210px; }
.quellen { list-style: none; margin: 0; padding: 0; }
.quellen li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.quelle-titel { flex: none; max-width: 45%; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quelle-url { flex: 1; min-width: 0; color: var(--ink-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quelle-del { flex: none; background: none; border: 0; color: var(--ink-2); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px; }
.quelle-del:hover { color: var(--red); }
.danger-zone { text-align: right; margin: 0 0 24px; }
.danger-zone .btn { border-color: var(--line); }

/* ---------- Ergebnisse ---------- */
.results { position: sticky; top: 80px; }
.ledger { background: var(--slate); color: #fff; border-radius: var(--radius); padding: 20px 22px 16px; margin-bottom: 14px; }
.ledger b { display: block; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.ledger .big b { font-size: 44px; line-height: 1; margin-bottom: 6px; }
.ledger span { display: block; font-size: 12.5px; color: #b6c2cd; line-height: 1.3; }
.ledger i { font-style: normal; }
.ledger .big { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid rgba(255,255,255,.15); }
.ledger .row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.ledger .pos { color: #6fd3c8; }
.ledger .neg { color: #f19a8f; }

.alert { border-radius: var(--radius); padding: 10px 12px; font-size: 13.5px; margin: 0 0 10px; }
.alert.warn { background: var(--amber-bg); color: var(--amber); border-left: 3px solid var(--amber); }
.alert.info { background: var(--info-bg); color: #2c5470; border-left: 3px solid #4d7fa0; }
.alert.ok { background: #e2f1ef; color: var(--teal); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.panel summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: 14px; list-style: none; display: flex; justify-content: space-between; }
.panel summary::after { content: "+"; color: var(--ink-2); }
.panel[open] summary::after { content: "−"; }
.kv { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.kv th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 6px 14px; border-top: 1px solid var(--line); width: 60%; }
.kv td { text-align: right; padding: 6px 14px; border-top: 1px solid var(--line); white-space: nowrap; }
.table-scroll { overflow-x: auto; }
.years { border-collapse: collapse; font-size: 12px; white-space: nowrap; }
.years th, .years td { padding: 5px 8px; border-top: 1px solid var(--line); text-align: right; }
.years th { position: sticky; top: 0; background: var(--paper); font-weight: 600; color: var(--ink-2); }
.years td:first-child, .years th:first-child { text-align: left; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--slate); color: #fff; padding: 10px 18px; border-radius: var(--radius);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 50; font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--teal); }
.toast.warn { background: var(--red); }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 32px 30px; width: 100%; max-width: 380px; }
.login-card .brand { font-size: 24px; color: var(--ink); }
.login-card .muted { margin: 4px 0 20px; font-size: 14px; }
.login-card .field { margin-bottom: 16px; }

/* ---------- Nebenseiten: Konto, Benutzerverwaltung ---------- */
.topnav { display: flex; flex: 1; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { color: #c9d3dc; text-decoration: none; padding: 7px 12px; border-radius: var(--radius); font-size: 14px; white-space: nowrap; }
.topnav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.topnav a.on { color: #fff; background: rgba(255,255,255,.14); }
.whoami { align-self: center; max-width: 220px; color: #c9d3dc; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.page { max-width: 880px; margin: 0 auto; padding: 22px 16px 60px; }
.page-title { font-size: 20px; margin-bottom: 14px; }
.small { font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack .grid { gap: 12px 16px; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.checks { display: flex; flex-wrap: wrap; gap: 18px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--teal); }
.select { border: 1px solid var(--line); border-radius: var(--radius); background: #f7f9fa; padding: 8px 10px; font: inherit; font-size: 15px; color: var(--ink); width: 100%; }
.btn.small { padding: 4px 10px; font-size: 13px; }

.utable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.utable th { text-align: left; font-weight: 600; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.utable td { padding: 8px 10px; border-top: 1px solid var(--line); }
.utable td.num { text-align: right; white-space: nowrap; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; background: var(--paper); color: var(--ink-2); border: 1px solid var(--line); }
.tag.admin { background: #e2f1ef; color: var(--teal); border-color: #bcdedb; }
.tag.off { background: #f6e3e3; color: var(--red); border-color: #e5c4c4; }

.vorein { display: grid; grid-template-columns: 270px 1fr; gap: 6px 20px; align-items: start; padding: 13px 0; border-top: 1px solid var(--line); }
.vorein:first-of-type { border-top: 0; padding-top: 2px; }
.herkunft { font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }
.herkunft .tag { margin-right: 6px; vertical-align: 1px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .content { grid-template-columns: 1fr; }
  .results { position: static; order: -1; }
  .years { font-size: 11.5px; }
}
@media (max-width: 800px) {
  .vorein { grid-template-columns: 1fr; }
  .burger { display: block; }
  .topbar-title { display: none; }
  .topbar .brand { flex: 1; }
  .btn#btnCopyObjekt, .btn#btnSaveNeu { display: none; }
  .sidebar {
    position: fixed; left: 0; top: 56px; bottom: 0; height: auto; z-index: 25;
    transform: translateX(-100%); transition: transform .2s;
    box-shadow: 0 0 30px rgba(0,0,0,.25);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .content { padding: 14px; gap: 14px; }
  .grid, .grid.two { grid-template-columns: 1fr 1fr; }
  .ledger .big b { font-size: 36px; }
  .note-add { flex-direction: column; }
  .note-add .btn { align-self: flex-end; }
  .note-add #quelleTitel { flex: 1; }
  .quellen li { flex-wrap: wrap; }
  .quelle-titel { max-width: 100%; }
  .ledger .row3 { grid-template-columns: 1fr; }
  .navlink { display: none; }
  .sidebar-foot { display: block; }
  .topbar-actions .whoami { display: none; }
}
@media (max-width: 480px) {
  .grid, .grid.two { grid-template-columns: 1fr; }
  .topnav a { padding: 7px 8px; }
  .topbar { gap: 8px; padding: 0 10px; }
  .btn { padding: 7px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .scrim, .toast { transition: none; }
}
