:root {
  --paper: #faf9f6;
  --card: #ffffff;
  --ink: #16181a;
  --muted: #6e7169;
  --rule: #e3e3dc;
  --rule-strong: #c9c9c0;
  --accent: #14584c;
  --accent-soft: #e8efec;
  --signal: #a8443a;
  --positive: #14584c;
  --negative: #a8443a;
  --positive-soft: #eaf1ee;
  --negative-soft: #fbf0ef;
  --radius: 3px;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; font-size: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Kopfzeile ---------- */

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
}

.wordmark {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.wordmark span { color: var(--accent); }

.topbar-right {
  display: flex;
  align-items: baseline;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
}

.linkbutton {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1px solid var(--rule-strong);
}

.linkbutton:hover { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------- Layout ---------- */

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px;
}

.yearbar {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.yearpicker {
  display: flex;
  align-items: center;
  gap: 4px;
}

.yearpicker button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--rule-strong);
  background: var(--card);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

.yearpicker button:hover { border-color: var(--ink); color: var(--ink); }

.yearpicker .year {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.02em;
  min-width: 5ch;
  text-align: center;
  padding: 0 6px;
}

.yearsum {
  border-left: 1px solid var(--rule);
  padding-left: 20px;
}

.yearsum .label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.yearsum .value {
  font-family: var(--mono);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.spacer { flex: 1; }

/* ---------- Reiter ---------- */

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: -1px;
  position: relative;
  z-index: 1;
}

.tab {
  border: 1px solid var(--rule);
  border-bottom-color: transparent;
  background: transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 9px 18px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.tab:hover { color: var(--ink); }

.tab.is-active {
  background: var(--card);
  color: var(--ink);
  font-weight: 500;
  border-color: var(--rule);
  border-bottom-color: var(--card);
  box-shadow: inset 0 2px 0 var(--accent);
}

.ghost {
  border: 1px solid var(--rule-strong);
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Tabelle ---------- */

.tablewrap {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 1200px;
}

th, td {
  border-bottom: 1px solid var(--rule);
  padding: 0;
  text-align: right;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 10px 8px;
  vertical-align: bottom;
  border-bottom: 1px solid var(--rule-strong);
}

th.col-name, td.col-name {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card);
  border-right: 1px solid var(--rule);
  min-width: 190px;
}

thead th.col-name { z-index: 3; }

th.col-total, td.col-total {
  border-left: 2px solid var(--rule-strong);
  background: #fcfcfa;
  min-width: 120px;
}

/* Signatur: Anteilsbalken unter jedem Monatstitel */
.sharebar {
  display: block;
  height: 2px;
  margin-top: 6px;
  background: var(--rule);
}

.sharebar i {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width 0.35s ease;
}

tbody tr:hover td { background: #fbfbf8; }
tbody tr:hover td.col-name { background: #fbfbf8; }

.cell-input,
.name-input {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 9px 10px;
  border-radius: 0;
}

.cell-input {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--ink);
}

.cell-input::placeholder { color: #cfcfc7; }
.cell-input:hover { background: var(--accent-soft); }
.cell-input:focus { background: var(--accent-soft); outline-offset: -2px; }

.name-input { font-weight: 500; }
.name-input::placeholder { color: #b9b9b1; font-weight: 400; }

td.saved { animation: flash 0.7s ease-out; }

@keyframes flash {
  0% { box-shadow: inset 0 0 0 2px var(--accent); }
  100% { box-shadow: inset 0 0 0 2px transparent; }
}

td.failed { box-shadow: inset 0 0 0 2px var(--signal); }

.rowtotal {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  padding: 9px 10px;
  display: block;
}

.rowtotal.zero { color: #c2c2ba; }

/* Zeilenkopf mit Löschen-Knopf */
.namecell {
  display: flex;
  align-items: center;
}

.delete {
  border: 0;
  background: none;
  color: transparent;
  cursor: pointer;
  padding: 0 10px 0 4px;
  font-size: 16px;
  line-height: 1;
}

tr:hover .delete { color: var(--rule-strong); }
.delete:hover { color: var(--signal) !important; }

/* Doppellinie über der Totalzeile – Buchhaltungskonvention */
tfoot td {
  border-top: 3px double var(--rule-strong);
  border-bottom: 0;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  padding: 12px 10px;
  background: var(--card);
  font-weight: 500;
}

tfoot td.col-name {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding-left: 10px;
}

tfoot td.col-total {
  border-left: 2px solid var(--rule-strong);
  background: var(--accent-soft);
  color: var(--accent);
}

.addrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 9px 12px;
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  cursor: pointer;
  width: 100%;
}

.addrow:hover { border-color: var(--accent); color: var(--accent); background: var(--card); }
.addrow .plus { font-size: 17px; line-height: 1; }

/* ---------- Grafiken ---------- */

.charts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-top: 36px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px 20px 14px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-wide { grid-column: 1 / -1; }

.canvas-box { position: relative; height: 260px; }

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 40px 0;
  text-align: center;
}

/* ---------- Anmeldung ---------- */

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 34px 32px;
}

.auth-card .wordmark { margin-bottom: 4px; display: block; }

.auth-card p.lead {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 14px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
}

.field input:focus { border-color: var(--accent); background: var(--card); }

.primary {
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.primary:hover { background: #0f463c; }
.primary:disabled { opacity: 0.6; cursor: default; }

.switch {
  margin: 20px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.switch a { color: var(--accent); }

.message {
  margin: 0 0 16px;
  padding: 9px 12px;
  border-left: 2px solid var(--signal);
  background: #fbf1f0;
  color: var(--signal);
  font-size: 13px;
}

.message[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 20;
}

.toast[hidden] { display: none; }

@media (max-width: 900px) {
  main { padding: 18px; }
  .charts { grid-template-columns: 1fr; }
  .topbar { padding: 16px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}


/* ---------- Reiter 2: Einnahmen und Saldo ---------- */

#saldo th.col-name,
#saldo td.col-name { min-width: 210px; }

#saldo tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card);
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  text-align: left;
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  padding: 10px;
  min-width: 210px;
  white-space: nowrap;
}

#saldo tbody th .hint {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
}

#saldo td {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  min-width: 92px;
}

.readonly {
  padding: 10px;
  display: block;
  color: var(--muted);
}

.row-derived th { color: var(--muted); }
.row-derived td { background: #fcfcfa; }

/* Ergebniszeilen */
.row-result th,
.row-result td {
  border-top: 1px solid var(--rule-strong);
  font-weight: 500;
}

.row-final th,
.row-final td {
  border-top: 3px double var(--rule-strong);
  border-bottom: 0;
  font-weight: 600;
}

.row-final th { background: var(--card); }

.amount {
  padding: 10px;
  display: block;
}

.amount.pos { color: var(--positive); }
.amount.neg { color: var(--negative); }
.amount.nil { color: #c2c2ba; }

.row-final td .amount.pos { background: var(--positive-soft); }
.row-final td .amount.neg { background: var(--negative-soft); }

.legend {
  margin: 14px 2px 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--muted);
  max-width: 78ch;
}

.legend strong { color: var(--ink); font-weight: 500; }

/* Vorzeichenfarbe auch in den Kopfzahlen */
.yearsum .value.pos { color: var(--positive); }
.yearsum .value.neg { color: var(--negative); }

#saldo td.saved { animation: flash 0.7s ease-out; }
#saldo td.failed { box-shadow: inset 0 0 0 2px var(--signal); }

/* ---------- Spalte "Anteil pro Monat" ---------- */

th.col-share,
td.col-share {
  border-left: 1px solid var(--rule);
  background: #fcfcfa;
  min-width: 118px;
}

thead th.col-share {
  white-space: normal;
  line-height: 1.35;
  max-width: 130px;
}

.rowshare {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  padding: 9px 10px;
  display: block;
  color: var(--muted);
}

.rowshare.zero { color: #c2c2ba; }

tfoot td.col-share {
  border-left: 1px solid var(--rule);
  background: #f6f7f5;
  color: var(--muted);
}

/* ---------- Dialog "Passwort ändern" ---------- */

.dialog {
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  padding: 26px 28px 22px;
  width: min(400px, calc(100vw - 32px));
  box-shadow: 0 10px 40px rgba(20, 24, 26, 0.14);
}

.dialog::backdrop {
  background: rgba(20, 24, 26, 0.34);
}

.dialog h2 {
  margin: 0 0 18px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.dialog-note {
  margin: 0 0 20px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-actions .primary,
.dialog-actions .ghost {
  width: auto;
  padding: 9px 18px;
}
