/* Wealth Analyser – eine Datei, keine Inline-Styles (strikte Content-Security-Policy).
   Gestaltung: dunkel, angelehnt an Grafana – Flächen mit dünnem Rand, kleine Rundungen, Farben der
   Diagramme aus einer festen Palette. */

:root {
  --bg: #111217;
  --surface: #181b1f;
  --surface-2: #22252b;
  --text: #d8d9e4;
  --muted: #8e90a0;
  --border: #2c2f36;
  --border-strong: #3d4049;
  --grid: rgba(204, 204, 220, .08);
  --accent: #3d71d9;
  --accent-hover: #5182e4;
  --accent-text: #ffffff;
  --link: #6e9fff;
  --positive: #73bf69;
  --negative: #f2495c;
  --warn-bg: #33270f;
  --warn-text: #ffb357;
  --forecast: #ff9830;
  --error-bg: #3a1a20;
  --ok-bg: #1b2e1e;
  /* Farben der Diagramme */
  --c-green: #73bf69;
  --c-green-dark: #37872d;
  --c-yellow: #fade2a;
  --c-yellow-dark: #cca300;
  --c-blue: #5794f2;
  --c-orange: #ff9830;
  --c-red: #f2495c;
  --c-purple: #b877d9;
  --c-cyan: #6ed0e0;
  --c-grey: #9a9cab;
  --radius: 4px;
  --radius-s: 3px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { font-size: 14.5px; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "SF Pro Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1rem; color: #ffffff; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .75rem; color: #ffffff; }
h3 { font-size: .95rem; font-weight: 600; margin: 1rem 0 .5rem; }
h1 .muted, h2 .muted, h3 .muted { font-weight: 400; }
h2 a { color: inherit; }

code { font-family: var(--mono); font-size: .92em; }

/* Kopfzeile */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem 1.25rem;
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; font-size: 1.05rem; color: #ffffff; }
.brand:hover { text-decoration: none; }

.mainnav { display: flex; flex-wrap: wrap; gap: .1rem; flex: 1; }

.mainnav a {
  position: relative;
  padding: .8rem .75rem;
  color: var(--muted);
  font-weight: 500;
}

.mainnav a:hover { color: var(--text); text-decoration: none; }
.mainnav a[aria-current="page"] { color: #ffffff; }
.mainnav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: .5rem;
  right: .5rem;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, #f55f3e, #ffb357);
}

.topbar-right { display: flex; align-items: center; gap: .75rem; padding: .4rem 0; }
.user { color: var(--muted); }
.login { max-width: 420px; margin: 3rem auto 0; }
/* Anmeldung über SSO: eigener Knopf unter der lokalen Anmeldung, durch eine Linie getrennt. */
.login-sso { border-top: 1px solid var(--border); padding-top: .9rem; }

main { flex: 1; width: 100%; max-width: 1720px; margin: 0 auto; padding: 1.1rem 1.25rem; box-sizing: border-box; }

.footer { max-width: 1720px; width: 100%; box-sizing: border-box; margin: 1.5rem auto 0; padding: 1rem 1.25rem 2rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }

/* Flächen */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1.05rem 1rem;
  margin-bottom: 1rem;
}

.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.card-head h2, .card-head h3 { margin: 0; }

/* Raster der Kacheln: so viele gleich breite Spalten, wie Platz ist. */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 1rem; }
.grid .card { margin-bottom: 0; }

/* Spalten einer Seite: schmal untereinander, ab 1200px zwei Spalten im Verhältnis 1,5 : 1.
   Flächen einer Zeile sind gleich hoch. col-main steht links, col-side rechts; rows-2 lässt die
   rechte Fläche neben zwei linken stehen.
   even teilt in zwei gleich breite Spalten. */
.cols { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); grid-auto-flow: row dense; align-items: stretch; margin-bottom: 1rem; }
.cols > * { margin-bottom: 0; min-width: 0; }
@media (min-width: 1200px) {
  .cols { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .cols.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols > .col-main { grid-column: 1; }
  .cols > .col-side { grid-column: 2; }
  .cols > .rows-2 { grid-row: span 2; }
}

.kpi-label { color: var(--muted); font-size: .85rem; }
.kpi-value { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: #ffffff; }
.kpi-sub { color: var(--muted); font-size: .85rem; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.25rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts:not(:last-child) { margin-bottom: .75rem; }

.muted { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }
.pos { color: var(--positive); }
.neg { color: var(--negative); }

.badge {
  display: inline-block;
  padding: .05rem .4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: .78rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.badge-warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge-ok { background: var(--ok-bg); color: var(--positive); border-color: transparent; }
.state-new { background: var(--ok-bg); color: var(--positive); border-color: transparent; }
.state-conflict, .state-deviating { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.state-error { background: var(--error-bg); color: var(--negative); border-color: transparent; }

.notice { padding: .6rem .8rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); margin: 0 0 1rem; }
.notice-warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.notice-error { background: var(--error-bg); border-color: transparent; }
.notice-ok { background: var(--ok-bg); color: var(--positive); border-color: transparent; }

.errors { margin: 0 0 .75rem; padding: .5rem .8rem .5rem 1.6rem; background: var(--error-bg); border-radius: var(--radius); color: #ffb4b6; }

/* Tabellen */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }

th, td { padding: .4rem .6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .82rem; font-weight: 500; color: var(--muted); white-space: nowrap; border-bottom-color: var(--border-strong); }
th a { color: inherit; }
td { border-bottom-color: #23262c; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions, th.actions { text-align: right; white-space: nowrap; }
tr.inactive td { color: var(--muted); }
/* Prognostizierte Buchungen: noch nicht gebucht. */
tr.forecast td, tr.forecast td a, span.forecast { color: var(--forecast); opacity: .85; }
tfoot td { font-weight: 600; border-bottom: none; }
/* Gruppierte Tabelle: je Gruppe ein tbody, die erste Zeile ist die Summe, darunter eingerückt die Teile. */
table.grouped tr.group td { font-weight: 600; }
table.grouped td.sub { padding-left: 1.6rem; }
table.grouped tbody tr:last-child td { border-bottom: 1px solid var(--border); }
table.grouped tbody:last-of-type tr:last-child td { border-bottom: none; }
table.grouped tfoot td { border-top: 1px solid var(--border-strong); }

/* Formulare */

form.stack { display: grid; gap: .75rem; max-width: 640px; }
form.stack.wide { max-width: none; }
form.inline { display: inline; }

.fields { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

label { display: grid; gap: .2rem; font-size: .88rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: .45rem; color: var(--text); }
.choices { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
fieldset { margin: 0; padding: .75rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); display: grid; gap: .6rem; min-width: 0; }
fieldset legend { padding: 0 .35rem; font-weight: 600; }
fieldset .hint { margin: 0; }

input, select, textarea, button {
  font: inherit;
  color: var(--text);
}

input[type="text"], input[type="password"], input[type="date"], input[type="number"], input[type="file"], select, textarea {
  width: 100%;
  padding: .4rem .6rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
}
input[type="text"]:hover, input[type="password"]:hover, input[type="date"]:hover, input[type="number"]:hover, select:hover, textarea:hover { border-color: #565a66; }
input::placeholder, textarea::placeholder { color: #5f6170; }
input[type="file"]::file-selector-button {
  margin-right: .7rem; padding: .25rem .7rem; border: 1px solid var(--border-strong); border-radius: var(--radius-s);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}

input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.hint { font-size: .8rem; color: var(--muted); }
.hint.warn { color: var(--warn-text); }

/* Erläuterung: sichtbar ist nur die Marke „Info“; der Text erscheint beim Überfahren oder mit Fokus. */
.info { position: relative; display: inline-block; width: fit-content; justify-self: start; align-self: start; margin: .25rem 0; font-size: .8rem; color: var(--muted); cursor: help; }
.info::before { content: "ⓘ Info"; display: inline-block; padding: .1rem .45rem; border: 1px solid var(--border); border-radius: var(--radius-s); white-space: nowrap; }
.info:hover::before, .info:focus::before, .info:focus-within::before { color: var(--text); border-color: var(--border-strong); }
.info-box {
  display: none;
  position: absolute;
  z-index: 30;
  top: 100%;
  left: 0;
  width: max-content;
  max-width: min(34rem, calc(100vw - 3rem));
  padding: .7rem .85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  line-height: 1.45;
  text-align: left;
  cursor: auto;
}
.info:hover .info-box, .info:focus .info-box, .info:focus-within .info-box { display: block; }

.button, button {
  display: inline-block;
  padding: .4rem .85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.button:hover, button:hover { background: #2c3038; border-color: #565a66; text-decoration: none; }
.button-primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button-primary:hover, button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button-danger, button.danger { color: var(--negative); }
.button-danger:hover, button.danger:hover { border-color: var(--negative); }
.button-small, button.small { padding: .15rem .55rem; font-size: .85rem; }

.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: .6rem; margin-bottom: .75rem; }
.toolbar label { min-width: 150px; }
.spacer { flex: 1; }

.scope select { width: auto; max-width: 260px; }
form.scope { display: flex; align-items: center; gap: .4rem; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: .75rem; color: var(--muted); font-size: .88rem; }

/* Tabelle zum direkten Bearbeiten (data-grid): sieht aus wie die übrigen Tabellen, jede Zelle ist ein
   Eingabefeld. Die Klasse heißt nicht „grid“, weil .grid das Raster der Kacheln ist. */
table.sheet th, table.sheet td { padding: .3rem .35rem; vertical-align: middle; }
table.sheet th:first-child, table.sheet td:first-child { padding-left: 0; }
table.sheet tbody tr:hover { background: transparent; }
table.sheet td input, table.sheet td select { width: 100%; min-width: 7.5rem; padding: .4rem .6rem; }
table.sheet td input[type="date"] { min-width: 9.5rem; }
table.sheet td.computed { padding: .3rem .6rem; color: var(--muted); white-space: nowrap; }
table.sheet td.actions { width: 1%; padding-right: 0; white-space: nowrap; }
table.sheet td.actions button { min-width: 2rem; padding: .3rem .55rem; }
.table-wrap + .toolbar { margin-top: .75rem; }

/* Rechenweg der Steuerschätzung: schmale Tabelle wie ein Bescheid. Eingaben stehen als Felder in der
   Betragsspalte; applied markiert die Variante, die die Bilanz bestimmt. */
table.calc th, table.calc td { vertical-align: middle; }
table.calc tbody tr:hover { background: transparent; }
table.calc td.sub { padding-left: 1.6rem; color: var(--muted); }
table.calc td.num input { width: 10rem; padding: .25rem .5rem; text-align: right; }
table.calc tr.total td { font-weight: 600; border-top: 1px solid var(--border-strong); }
table.calc tr.balance td { font-size: 1.1rem; }
table.calc th.applied, table.calc td.applied { background: var(--surface-2); color: #ffffff; }
.cols + .toolbar { align-items: center; }

/* Diagramme */
.chart { width: 100%; height: 380px; }
.chart-small { width: 100%; height: 240px; }
.chart-half { width: 100%; height: 190px; }
/* Schalter über einem Liniendiagramm: Zeitraum und Skala als zusammenhängende Gruppen. */
.chart-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1.25rem; margin: 0 0 .5rem; font-size: .8rem; color: var(--muted); }
.chart-group { display: inline-flex; align-items: center; gap: .5rem; }
.seg-box { display: inline-flex; padding: 1px; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--bg); }
button.seg { padding: .15rem .6rem; border: none; border-radius: 2px; background: transparent; font-size: .8rem; font-weight: 500; color: var(--muted); }
button.seg:hover { background: transparent; color: var(--text); }
button.seg[aria-pressed="true"] { background: var(--surface-2); color: #ffffff; }
.chart-tip { margin-left: auto; }

/* Aufteilungen mit Drilldown (PLAN 8.5) */
.pies { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.pie { min-width: 0; }
.pie-path { margin: 0 0 .25rem; }
.chart-pie { width: 100%; height: 300px; }
button.linklike { padding: 0; border: none; border-radius: 0; background: none; color: var(--link); font: inherit; text-align: left; cursor: pointer; }
button.linklike:hover { background: none; text-decoration: underline; text-underline-offset: 3px; }
[hidden] { display: none !important; }

.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

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

.breadcrumb { margin: 0 0 .4rem; color: var(--muted); font-size: .88rem; }

details { margin: .25rem 0; }
details > summary { cursor: pointer; color: var(--muted); margin-bottom: .6rem; }

textarea { resize: vertical; font-family: inherit; }
textarea[spellcheck="false"] { font-family: var(--mono); }
