/* Budget-Rechner – ein Stylesheet, keine Abhängigkeiten.
   Farben: Papier und Tinte in kühlem Grau-Grün. Im Diagramm hat jede Gruppe
   eine Farbfamilie: Einnahmen grau, Ausgaben warm, Sparen grün. */

:root {
  color-scheme: light dark;

  --paper: oklch(0.972 0.004 170);
  --surface: oklch(1 0 0);
  --ink: oklch(0.24 0.02 170);
  --ink-2: oklch(0.44 0.015 170);
  --rule: oklch(0.88 0.008 170);
  --accent: oklch(0.42 0.09 165);
  --accent-ink: oklch(1 0 0);
  --danger: oklch(0.48 0.17 27);
  --notice: oklch(0.95 0.03 85);
  --notice-rule: oklch(0.72 0.12 80);

  /* Diagrammfarben, eine Familie pro Gruppe */
  --tone-inc: oklch(0.62 0.012 250);
  --tone-bud: oklch(0.36 0.015 250);
  --tone-free: oklch(0.8 0.01 250);
  --tone-deficit: oklch(0.55 0.17 27);
  --tone-exp-1: oklch(0.46 0.125 48);
  --tone-exp-2: oklch(0.53 0.13 50);
  --tone-exp-3: oklch(0.6 0.125 52);
  --tone-exp-4: oklch(0.67 0.115 55);
  --tone-exp-5: oklch(0.74 0.105 58);
  --tone-exp-x: oklch(0.32 0.09 40);
  --tone-sav-1: oklch(0.48 0.1 160);
  --tone-sav-2: oklch(0.58 0.1 160);
  --tone-sav-3: oklch(0.68 0.09 160);
  --link-opacity: 0.36;

  --radius: 6px;
  --measure: 68ch;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 100%;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: oklch(0.17 0.008 170);
    --surface: oklch(0.21 0.01 170);
    --ink: oklch(0.93 0.008 170);
    --ink-2: oklch(0.76 0.012 170);
    --rule: oklch(0.33 0.012 170);
    --accent: oklch(0.78 0.11 165);
    --accent-ink: oklch(0.18 0.02 170);
    --danger: oklch(0.74 0.14 27);
    --notice: oklch(0.27 0.03 85);
    --notice-rule: oklch(0.6 0.1 80);

    --tone-inc: oklch(0.6 0.012 250);
    --tone-bud: oklch(0.82 0.012 250);
    --tone-free: oklch(0.42 0.01 250);
    --tone-deficit: oklch(0.66 0.16 27);
    --tone-exp-1: oklch(0.52 0.12 48);
    --tone-exp-2: oklch(0.59 0.12 50);
    --tone-exp-3: oklch(0.66 0.115 52);
    --tone-exp-4: oklch(0.73 0.105 55);
    --tone-exp-5: oklch(0.8 0.095 58);
    --tone-exp-x: oklch(0.93 0.05 75);
    --tone-sav-1: oklch(0.55 0.1 160);
    --tone-sav-2: oklch(0.65 0.1 160);
    --tone-sav-3: oklch(0.74 0.09 160);
    --link-opacity: 0.42;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  accent-color: var(--accent);
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.skip-link:focus {
  top: 0.5rem;
}

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

/* ---------- Grundgerüst ---------- */

.site-header,
main,
.site-footer {
  width: min(100% - 2rem, 70rem);
  margin-inline: auto;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding-block: 1rem;
}

.wordmark {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.save-state {
  margin: 0 0.5rem 0 0;
  color: var(--ink-2);
  font-size: 0.875rem;
}

main {
  padding-bottom: 3rem;
}

main section {
  margin-top: 2.75rem;
}

h1,
h2,
h3 {
  line-height: 1.2;
  text-wrap: balance;
}

h1 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 1.3rem + 3vw, 3.25rem);
  font-weight: 680;
  letter-spacing: -0.025em;
}

h2 {
  margin: 0 0 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--ink);
  font-size: 1.125rem;
  font-weight: 650;
}

h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1rem;
  font-weight: 650;
}

p {
  margin: 0 0 1rem;
  max-width: var(--measure);
}

.lead {
  font-size: 1.1875rem;
  color: var(--ink-2);
}

.fineprint,
.hint,
figcaption,
caption {
  color: var(--ink-2);
  font-size: 0.875rem;
}

.site-footer {
  padding-block: 1.5rem 2.5rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: 0.875rem;
}

.narrow {
  max-width: 30rem;
}
.narrow h1 {
  font-size: 2rem;
}

.notice {
  padding: 0.75rem 1rem;
  background: var(--notice);
  border-inline-start: 3px solid var(--notice-rule);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.form-error {
  color: var(--danger);
  font-weight: 550;
}
.form-success {
  color: var(--accent);
  font-weight: 550;
}

.empty {
  color: var(--ink-2);
}

/* ---------- Bedienelemente ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
}
.button:hover {
  border-color: var(--ink-2);
}
.button:active {
  translate: 0 1px;
}
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.button.quiet {
  background: transparent;
  border-color: transparent;
}
.button.quiet:hover {
  border-color: var(--rule);
}
.button.danger {
  color: var(--danger);
}
.button.small {
  min-height: 2rem;
  padding: 0.15rem 0.6rem;
  font-size: 0.875rem;
}
.button:disabled {
  opacity: 0.55;
  cursor: progress;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.button-row,
.auth-actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.button-row.end {
  justify-content: flex-end;
  margin: 1.5rem 0 0;
}
.push-left {
  margin-inline-end: auto;
}

.field {
  margin-bottom: 1rem;
}
.field.inline {
  margin-bottom: 0;
}
.field .hint {
  margin: 0.3rem 0 0;
}

label,
legend {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 550;
}

input:where([type="text"], [type="password"], [type="number"]),
select {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--ink-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  /* 16px verhindert das automatische Zoomen auf dem iPhone */
  font-size: max(1rem, 16px);
}
select {
  width: auto;
  max-width: 100%;
}
td select {
  min-height: 2rem;
  padding-block: 0.15rem;
}

/* Fehler erst zeigen, nachdem das Feld benutzt wurde */
input:user-invalid {
  border-color: var(--danger);
  outline-color: var(--danger);
}

fieldset {
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
}
.choice {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
  margin: 0 1rem 0 0;
  font-weight: 400;
}

dialog {
  width: min(100% - 2rem, 28rem);
  padding: 1.5rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop {
  background: oklch(0.2 0.02 170 / 0.5);
}
dialog h2 {
  padding-top: 0;
  border-top: 0;
  font-size: 1.25rem;
}

details {
  border-bottom: 1px solid var(--rule);
}
summary {
  padding: 0.8rem 0;
  font-weight: 550;
  cursor: pointer;
}
.details-body {
  padding: 0.25rem 0 1.25rem;
}
.table-alt {
  margin-top: 0.5rem;
  border-bottom: 0;
}
.table-alt summary {
  display: inline-block;
  color: var(--ink-2);
  font-size: 0.875rem;
  font-weight: 400;
  text-decoration: underline;
}

.steps {
  max-width: var(--measure);
  padding-inline-start: 1.25rem;
}
.steps li {
  margin-bottom: 0.6rem;
}

.plain-list {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}
.plain-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
}

code,
.code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.code {
  display: block;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  overflow-wrap: anywhere;
  flex: 1 1 14rem;
}
.copy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.4rem 0 1rem;
  max-width: var(--measure);
}

/* ---------- Startseite ---------- */

#view-auth {
  margin-top: 1.5rem;
}
.intro {
  max-width: 40rem;
  margin-bottom: 2rem;
}
.auth-actions {
  margin-block: 1.5rem 1rem;
}

/* ---------- Überblick ---------- */

.summary {
  margin-top: 1rem;
}
.statement {
  max-width: 34ch;
  margin-bottom: 1.5rem;
  font-size: clamp(1.5rem, 1.05rem + 2vw, 2.4rem);
  font-weight: 620;
  line-height: 1.18;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.statement .flag {
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.14em;
  text-decoration-color: var(--tone-exp-2);
}

.figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1rem 2rem;
  margin: 0;
}
.figures div {
  padding-top: 0.6rem;
  border-top: 1px solid var(--rule);
}
.figures dt {
  color: var(--ink-2);
  font-size: 0.875rem;
}
.figures dd {
  margin: 0.1rem 0 0;
  font-size: 1.5rem;
  font-weight: 620;
  letter-spacing: -0.01em;
}
.figures small {
  display: block;
  color: var(--ink-2);
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0;
}

/* ---------- Diagramme ---------- */

.chart-figure,
.donut-figure {
  margin: 0;
}
.chart-figure figcaption {
  max-width: var(--measure);
  margin-top: 0.5rem;
}

.sankey {
  position: relative;
  overflow-x: auto;
  padding: 0.75rem 0;
}
.sankey-svg {
  display: block;
  font-size: 0.8125rem;
}

.tone-inc { --tone: var(--tone-inc); }
.tone-bud { --tone: var(--tone-bud); }
.tone-free { --tone: var(--tone-free); }
.tone-deficit { --tone: var(--tone-deficit); }
.tone-exp-1 { --tone: var(--tone-exp-1); }
.tone-exp-2 { --tone: var(--tone-exp-2); }
.tone-exp-3 { --tone: var(--tone-exp-3); }
.tone-exp-4 { --tone: var(--tone-exp-4); }
.tone-exp-5 { --tone: var(--tone-exp-5); }
.tone-exp-x { --tone: var(--tone-exp-x); }
.tone-sav-1 { --tone: var(--tone-sav-1); }
.tone-sav-2 { --tone: var(--tone-sav-2); }
.tone-sav-3 { --tone: var(--tone-sav-3); }

.node rect:not(.hatch) {
  fill: var(--tone);
}
.node rect.flagged {
  fill: var(--tone-exp-x);
}
.link path:not(.hatch) {
  fill: var(--tone);
  fill-opacity: var(--link-opacity);
}
/* Unnötige Ausgaben: dunklere Stufe der Gruppe, darüber die Schraffur */
.link.tone-exp-x path:not(.hatch) {
  fill-opacity: 0.8;
}
.hatch-line {
  stroke: var(--paper);
  stroke-width: 3;
  stroke-opacity: 0.7;
}
/* Ein Rand in Papierfarbe hält die Schrift lesbar, wo ein Band darunter läuft */
.label {
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--paper);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.label-name {
  font-weight: 600;
}
.label-value,
.label-flag {
  fill: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

/* Beim Überfahren tritt ein Band hervor, die anderen treten zurück */
.sankey-svg:has(.link:hover) .link:not(:hover) {
  opacity: 0.3;
}
@media (prefers-reduced-motion: no-preference) {
  .link {
    transition: opacity 120ms ease-out;
  }
}

.donut {
  position: relative;
  width: min(13rem, 70%);
  aspect-ratio: 1;
  margin: 0.5rem 0 1.25rem;
}
.donut-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--rule);
  -webkit-mask: radial-gradient(circle, transparent 0 56%, #000 57%);
  mask: radial-gradient(circle, transparent 0 56%, #000 57%);
}
.donut-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  margin: 0;
  text-align: center;
  font-size: 0.875rem;
  color: var(--ink-2);
  line-height: 1.25;
}
.donut-center b {
  display: block;
  color: var(--ink);
  font-size: 1.375rem;
  font-weight: 620;
}

.swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-inline-end: 0.5rem;
  border-radius: 2px;
  background: var(--tone);
}
.swatch.flag {
  background:
    repeating-linear-gradient(45deg, transparent 0 2px, color-mix(in oklch, var(--paper) 65%, transparent) 2px 3.5px),
    var(--tone-exp-x);
}

/* ---------- Tabellen ---------- */

.columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0 3rem;
}
@media (min-width: 60rem) {
  .columns {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    align-items: start;
  }
}

.table-scroll {
  /* relative, damit auch unsichtbare Tabellenköpfe im Scrollbereich bleiben */
  position: relative;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
caption {
  padding-bottom: 0.5rem;
  text-align: start;
}
th,
td {
  padding: 0.5rem 0.75rem 0.5rem 0;
  border-bottom: 1px solid var(--rule);
  text-align: start;
  vertical-align: middle;
}
th:last-child,
td:last-child {
  padding-inline-end: 0;
}
thead th {
  border-bottom-color: var(--ink-2);
  color: var(--ink-2);
  font-size: 0.875rem;
  font-weight: 550;
  vertical-align: bottom;
}
.num {
  text-align: end;
  white-space: nowrap;
}
tfoot td,
tfoot th {
  border-bottom: 0;
  font-weight: 650;
}

.ledger {
  margin-bottom: 2rem;
}
.ledger-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.ledger-head h3 {
  margin: 0;
  font-size: 1.0625rem;
}
.ledger-total {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.ledger .group-row > * {
  padding-top: 1rem;
  border-bottom-color: var(--ink-2);
  font-weight: 600;
}
.ledger .group-row .num {
  font-weight: 600;
}
.ledger td.name {
  width: 100%;
}
.ledger .sub {
  display: block;
  color: var(--ink-2);
  font-size: 0.875rem;
}
.rating {
  white-space: nowrap;
  color: var(--ink-2);
  font-size: 0.875rem;
}
.rating.unnoetig {
  color: var(--ink);
  font-weight: 600;
}
.ledger .add-row {
  margin-top: 0.75rem;
}

.payments-total {
  font-weight: 550;
}
tr.uncategorized td {
  background: var(--notice);
}
tr.uncategorized td:first-child {
  padding-inline-start: 0.5rem;
}
.over {
  color: var(--danger);
  font-weight: 600;
}

@media (max-width: 40rem) {
  main section {
    margin-top: 2.25rem;
  }
  th,
  td {
    padding-inline-end: 0.5rem;
  }
}

@media print {
  .site-header .header-actions,
  #einstellungen,
  .button,
  .skip-link {
    display: none !important;
  }
  body {
    background: #fff;
  }
}

#compare-table {
  margin-top: 1.5rem;
}
