/* =============================================================================
   Finanzen-Dashboard – Design-System
   Bewusst dieselben Tokens, Abstaende und Formen wie das Projektmanagement
   unter tobos.me: warme Graustufen im Notion-Stil, sehr zurueckhaltende
   Rahmen, viel Weissraum. Licht- und Dunkelmodus.
   ============================================================================= */

/* --- Design-Tokens --------------------------------------------------------- */

:root {
  color-scheme: light;

  /* Flaechen */
  --bg:            #ffffff;
  --bg-tint:       #f7f7f5;
  --bg-card:       #ffffff;
  --bg-elev:       rgba(55, 53, 47, 0.06);
  --bg-active:     rgba(55, 53, 47, 0.10);

  /* Text */
  --text:          #37352f;
  --text-muted:    rgba(55, 53, 47, 0.65);
  --text-subtle:   rgba(55, 53, 47, 0.45);

  /* Linien */
  --border:        rgba(55, 53, 47, 0.09);
  --border-strong: rgba(55, 53, 47, 0.16);

  /* Akzent und Bedeutungsfarben */
  --accent:        #2383e2;
  --accent-hover:  #1a6dbf;
  --accent-soft:   rgba(35, 131, 226, 0.12);
  --accent-ring:   rgba(35, 131, 226, 0.28);
  --danger:        #d03b3b;
  --danger-soft:   rgba(208, 59, 59, 0.10);
  --success:       #0f7b6c;
  --success-soft:  rgba(15, 123, 108, 0.10);
  --warning:       #d9730d;
  --warning-soft:  rgba(217, 115, 13, 0.12);

  /* Diagrammfarben: feste Reihenfolge, nie zyklisch erweitert. Gegen die
     Kartenflaeche geprueft (Helligkeitsband, Kontrast, Farbfehlsichtigkeit). */
  --viz-1: #2a78d6;  --viz-2: #eb6834;  --viz-3: #1baf7a;  --viz-4: #eda100;
  --viz-5: #e87ba4;  --viz-6: #008300;  --viz-7: #4a3aa7;  --viz-8: #e34948;
  --viz-axis: #898781;

  /* Rendering */
  --radius-sm:   4px;
  --radius:      6px;
  --radius-lg:   10px;
  --radius-pill: 999px;

  --shadow-sm: rgba(15, 15, 15, 0.1) 0 0 0 1px, rgba(15, 15, 15, 0.1) 0 1px 2px;
  --shadow-md: rgba(15, 15, 15, 0.1) 0 0 0 1px, rgba(15, 15, 15, 0.12) 0 3px 6px;
  --shadow-lg: rgba(15, 15, 15, 0.05) 0 0 0 1px, rgba(15, 15, 15, 0.1) 0 3px 6px,
               rgba(15, 15, 15, 0.2) 0 9px 24px;

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
          Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --ease:      cubic-bezier(0.2, 0, 0.2, 1);
  --sidebar-w: 232px;
  --topbar-h: 56px;
}

/* Dunkelmodus nach Systemeinstellung … */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg:            #191919;
    --bg-tint:       #202020;
    --bg-card:       #252525;
    --bg-elev:       rgba(255, 255, 255, 0.055);
    --bg-active:     rgba(255, 255, 255, 0.10);

    --text:          rgba(255, 255, 255, 0.81);
    --text-muted:    rgba(255, 255, 255, 0.46);
    --text-subtle:   rgba(255, 255, 255, 0.28);

    --border:        rgba(255, 255, 255, 0.094);
    --border-strong: rgba(255, 255, 255, 0.16);

    --accent-soft:   rgba(35, 131, 226, 0.20);
    --danger:        #ff7369;
    --danger-soft:   rgba(255, 115, 105, 0.15);
    --success:       #4dab6d;
    --success-soft:  rgba(77, 171, 109, 0.15);
    --warning:       #ffa344;
    --warning-soft:  rgba(255, 163, 68, 0.15);

    --viz-1: #3987e5;  --viz-2: #d95926;  --viz-3: #199e70;  --viz-4: #c98500;
    --viz-5: #d55181;  --viz-6: #008300;  --viz-7: #9085e9;  --viz-8: #e66767;

    --shadow-sm: rgba(255, 255, 255, 0.075) 0 0 0 1px, rgba(0, 0, 0, 0.2) 0 1px 2px;
    --shadow-md: rgba(255, 255, 255, 0.13) 0 0 0 1px, rgba(0, 0, 0, 0.3) 0 3px 6px;
    --shadow-lg: rgba(0, 0, 0, 0.3) 0 0 0 1px, rgba(0, 0, 0, 0.4) 0 9px 24px;
  }
}

/* … oder per Umschalter fest eingestellt. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #191919;
  --bg-tint:       #202020;
  --bg-card:       #252525;
  --bg-elev:       rgba(255, 255, 255, 0.055);
  --bg-active:     rgba(255, 255, 255, 0.10);

  --text:          rgba(255, 255, 255, 0.81);
  --text-muted:    rgba(255, 255, 255, 0.46);
  --text-subtle:   rgba(255, 255, 255, 0.28);

  --border:        rgba(255, 255, 255, 0.094);
  --border-strong: rgba(255, 255, 255, 0.16);

  --accent-soft:   rgba(35, 131, 226, 0.20);
  --danger:        #ff7369;
  --danger-soft:   rgba(255, 115, 105, 0.15);
  --success:       #4dab6d;
  --success-soft:  rgba(77, 171, 109, 0.15);
  --warning:       #ffa344;
  --warning-soft:  rgba(255, 163, 68, 0.15);

  --viz-1: #3987e5;  --viz-2: #d95926;  --viz-3: #199e70;  --viz-4: #c98500;
  --viz-5: #d55181;  --viz-6: #008300;  --viz-7: #9085e9;  --viz-8: #e66767;

  --shadow-sm: rgba(255, 255, 255, 0.075) 0 0 0 1px, rgba(0, 0, 0, 0.2) 0 1px 2px;
  --shadow-md: rgba(255, 255, 255, 0.13) 0 0 0 1px, rgba(0, 0, 0, 0.3) 0 3px 6px;
  --shadow-lg: rgba(0, 0, 0, 0.3) 0 0 0 1px, rgba(0, 0, 0, 0.4) 0 9px 24px;
}

/* --- Grundlagen ------------------------------------------------------------ */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Zahlen gleich breit - Betraege springen beim Aktualisieren nicht. */
.mono, .val, .bar-value, .data-table td, .data-table th, .stand {
  font-variant-numeric: tabular-nums;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }

[hidden] { display: none !important; }
[x-cloak] { display: none !important; }
.hidden { display: none !important; }

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

/* Scrollbars dezent halten */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-subtle);
  background-clip: content-box;
}
*::-webkit-scrollbar-track { background: transparent; }

/* --- Grundgeruest ----------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* --- Obere Leiste mit Menuebutton ------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-tint);
  border-bottom: 1px solid var(--border);
}
.topbar .brand-top {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}
.nav-toggle:hover { background: var(--bg-elev); }
.nav-toggle svg { width: 18px; height: 18px; }

/* --- Navigations-Drawer (aufklappbares Menue, alle Groessen) --------------- */

.nav-scrim {
  position: fixed;
  inset: var(--topbar-h) 0 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.nav-scrim.open { opacity: 1; visibility: visible; }

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  z-index: 80;
  height: calc(100dvh - var(--topbar-h));
  width: 260px;
  max-width: 82vw;
  overflow-y: auto;
  background: var(--bg-tint);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
}
.sidebar.open { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-scrim { transition: none; }
}

/* Marke steht jetzt in der Topbar - im Drawer ausblenden. */
.sidebar .brand { display: none; }
.sidebar .brand-hidden {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 4px 8px 16px;
  color: var(--text);
}
.sidebar .brand small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--text-subtle);
}

.sidebar a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
  transition: background 20ms ease-in, color 20ms ease-in;
}
.sidebar a:hover { background: var(--bg-elev); color: var(--text); }

/* Aktive Seite: gefuellte Flaeche statt Farbbalken - wie im Board. */
.sidebar a.active {
  background: var(--bg-active);
  color: var(--text);
  font-weight: 500;
}
.sidebar a.active::after { content: none; }

/* Symbole als Maske, damit sie die Textfarbe uebernehmen.
   Jeder Link setzt --ico; unbekannte Links fallen auf --ico-default zurueck. */
.sidebar a::before {
  content: "";
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: var(--ico, var(--ico-default));
  mask-image: var(--ico, var(--ico-default));
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  opacity: 0.75;
}
.sidebar a:hover::before,
.sidebar a.active::before { opacity: 1; }

/* Kein Ausdehnen mehr: der Querlink sitzt direkt unter den Menuepunkten
   (wie im Projekttool), nicht am unteren Rand. */
.sidebar .spacer { display: none; }

/* Wechsel in die andere Anwendung: bewusst zurueckhaltender, mit Trennlinie
   direkt ueber sich (analog zum Trenner im Projekttool). */
.sidebar a.cross-app {
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-subtle);
}
.sidebar a.cross-app::before { content: none; }
.sidebar a.cross-app:hover { background: var(--bg-elev); color: var(--text); }
.sidebar a.cross-app svg { flex: 0 0 auto; opacity: 0.7; }

/* Theme + Abmelden sind jetzt Icon-Knoepfe oben rechts in der Topbar. */
.sidebar .foot { display: none; }

/* --- Icon-Knoepfe rechts in der Topbar (Theme, Abmelden) ------------------- */
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-elev); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* --- Inhaltsbereich --------------------------------------------------------- */

main.content {
  padding: 28px 34px 64px;
  max-width: 1180px;
  width: 100%;
  min-width: 0;
  justify-self: center; /* ohne feste Seitenleiste den Inhalt mittig setzen */
  overflow-x: auto;     /* breite Tabellen scrollen hier, nicht die Seite */
}

main.content > header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

main.content h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

main.content .stand,
.stand {
  font-size: 12px;
  color: var(--text-subtle);
}

/* --- Karten ----------------------------------------------------------------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

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

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.grid[style] { gap: 16px; }

/* --- Kennzahlen ------------------------------------------------------------- */

/* Flache Zahlenreihe ohne Schatten - die Zahl traegt, nicht der Kasten. */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px 28px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.stat-card {
  position: relative;
  min-width: 0;
}
.stat-card.big::before { content: none; }

.stat-card .lab {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.stat-card .lab.periode-waehler {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 5px;
  margin-left: -5px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}
.stat-card .lab.periode-waehler:hover { background: var(--bg-elev); color: var(--text); }
.stat-card .lab.periode-waehler .chev { font-size: 10px; color: var(--text-subtle); }

/* Grosse Zahlen mit proportionalen Ziffern. */
.stat-card .val {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.stat-card .val.pos { color: var(--success); }
.stat-card .val.neg { color: var(--danger); }
.stat-card .val small { font-size: 12px; font-weight: 400; color: var(--text-subtle); }

.stat-card > small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-subtle);
}

/* Genau eine fuehrende Zahl je Seite. */
.stat-card.big .val { font-size: 38px; letter-spacing: -0.03em; }

/* --- Aufklappmenue ---------------------------------------------------------- */

.dropdown {
  position: absolute;
  z-index: 50;
  min-width: 160px;
  padding: 4px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.stat-card .dropdown { top: 100%; left: 0; margin-top: 4px; }

.dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  box-shadow: none;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}
.dropdown button:hover { background: var(--bg-elev); }

/* --- Schwebender Berater-Knopf --------------------------------------------- */
/* Fest in der rechten unteren Ecke, bleibt beim Scrollen sichtbar. Wird von
   shared.js auf jeder Seite ausser dem Chat selbst eingehaengt. */
.berater-fab {
  position: fixed;
  right: 40px;
  bottom: 40px;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  box-shadow: var(--shadow-lg);
  transition: transform 120ms ease, background 120ms ease;
}
/* Linien-Icon im Stil der Sidebar-Symbole (Outline, currentColor). */
.berater-fab svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.berater-fab:hover { background: var(--accent-hover); transform: translateY(-2px); }
.berater-fab:active { transform: translateY(0); }
.berater-fab:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 3px; }

@media (max-width: 900px) {
  .berater-fab { right: 24px; bottom: 24px; width: 58px; height: 58px; }
  .berater-fab svg { width: 31px; height: 31px; }
}

/* --- Reiternavigation ------------------------------------------------------- */

.tab-nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.tab-nav > button {
  padding: 5px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  box-shadow: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 20ms ease-in, color 20ms ease-in;
}
.tab-nav > button:hover:not(:disabled) { background: var(--bg-elev); color: var(--text); }
.tab-nav > button.active {
  background: var(--bg-active);
  color: var(--text);
  font-weight: 500;
}
.tab-nav > button:disabled { color: var(--text-subtle); cursor: not-allowed; }

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr { transition: background 20ms ease-in; }
.data-table tbody tr:hover td { background: var(--bg-elev); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tr.row-warning td { background: var(--warning-soft); }

.data-table .row-child td:first-child { padding-left: 28px; color: var(--text-muted); }

.data-table .row-actions {
  display: flex;
  gap: 2px;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 80ms ease;
}
.data-table tbody tr:hover .row-actions,
.data-table .row-actions:focus-within { opacity: 1; }
@media (hover: none) { .data-table .row-actions { opacity: 1; } }

.row-bucket td { font-weight: 500; }
.row-subbucket td { color: var(--text-muted); }

/* Zahlenspalten rechtsbuendig und mit gleich breiten Ziffern. */
.tab-vermoegen th:nth-child(2), .tab-vermoegen td:nth-child(2),
.tab-vermoegen th:nth-child(3), .tab-vermoegen td:nth-child(3),
.tab-vermoegen th:nth-child(5), .tab-vermoegen td:nth-child(5),
.tab-positionen th:nth-child(2), .tab-positionen td:nth-child(2),
.tab-positionen th:nth-child(4), .tab-positionen td:nth-child(4),
.tab-positionen th:nth-child(5), .tab-positionen td:nth-child(5),
.tab-positionen th:nth-child(6), .tab-positionen td:nth-child(6),
.tab-buchungen th:nth-child(3), .tab-buchungen td:nth-child(3) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tree-indent { display: inline-block; width: 18px; }

/* --- Formulare -------------------------------------------------------------- */

label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

input, select, textarea {
  width: 100%;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background-color: var(--bg-tint);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  outline: none;
  transition: background 20ms ease-in, border-color 20ms ease-in, box-shadow 20ms ease-in;
}

input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input:hover, select:hover, textarea:hover { background-color: var(--bg-elev); }

input:focus, select:focus, textarea:focus {
  background-color: var(--bg-card);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

textarea { min-height: 70px; line-height: 1.6; resize: vertical; }

/* Nur die Farbe als Langform setzen - die Kurzform "background" wuerde das
   Pfeil-Symbol mitloeschen. Und Safari braucht das -webkit-Praefix, sonst
   zeichnet iOS zusaetzlich seinen eigenen Pfeil. */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  cursor: pointer;
  padding-right: 28px;
  background-size: 12px 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23898781' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

label + input, label + select, label + textarea { margin-top: 0; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--bg-tint);
  border-radius: var(--radius);
}
.form-row > div { min-width: 0; }
.form-row .wide { grid-column: span 2; }
.form-row .form-row-full { grid-column: 1 / -1; }
.form-row .form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Kategorieauswahl in Listen: farbig, aber immer mit lesbarem Text. */
select.kat-select {
  padding: 4px 24px 4px 8px;
  font-size: 13px;
  background-color: transparent;
}
select.kat-select.kat-einnahme  { color: var(--success); }
select.kat-select.kat-ausgabe   { color: var(--danger); }
select.kat-select.kat-umbuchung { color: var(--text-muted); }
select.kat-select.kat-unkat     { color: var(--warning); }

/* --- Schaltflaechen --------------------------------------------------------- */

button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-elev);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  transition: background 20ms ease-in, color 20ms ease-in;
}
button:hover { background: var(--bg-active); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: rgba(15, 15, 15, 0.1) 0 1px 2px;
}
button.primary:hover { background: var(--accent-hover); color: #fff; }

button.danger { background: transparent; color: var(--danger); }
button.danger:hover { background: var(--danger-soft); color: var(--danger); }

button.small { padding: 4px 9px; font-size: 13px; }

button.subtle { background: transparent; color: var(--text-muted); }
button.subtle:hover { background: var(--bg-elev); color: var(--text); }

/* --- Hinweise und Abzeichen ------------------------------------------------- */

.badge-offen, .badge-fertig {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: 3px;
  font-size: 12px;
  white-space: nowrap;
}
.badge-offen { background: var(--warning-soft); color: var(--warning); }
.badge-offen::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-fertig { background: var(--success-soft); color: var(--success); }

.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.alerts li:last-child { border-bottom: none; }

/* Statusfarbe erscheint nie allein - immer neben dem Meldungstext. */
.alert-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--text-subtle);
}
.alert-dot.sev-error { background: var(--danger); }
.alert-dot.sev-warn  { background: var(--warning); }
.alert-dot.sev-info  { background: var(--accent); }

.warning-box {
  padding: 10px 12px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--text);
  font-size: 13px;
}
.warning-box strong { font-weight: 600; }

.error {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* --- Balken (Buckets) ------------------------------------------------------- */

.bucket-bars { display: flex; flex-direction: column; gap: 2px; }

/* Die Zeile selbst ist das Raster: Name | Spur | Wert | Pfeil */
.bucket-row {
  display: grid;
  grid-template-columns: minmax(0, 200px) 1fr minmax(0, 120px) 16px;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}
.bucket-row:not(.child):hover { background: var(--bg-elev); cursor: pointer; }

.bucket-row .bar-name {
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Spur und Fuellung: eine Datenreihe, eine Farbe. */
.bucket-row .bar-wrapper {
  height: 8px;
  background: var(--bg-elev);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.bucket-row .bar {
  height: 100%;
  background: var(--viz-1);
  border-radius: var(--radius-pill);
  transition: width 400ms var(--ease);
}

.bucket-row .bar-value {
  text-align: right;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.bucket-row .bar-chev {
  color: var(--text-subtle);
  font-size: 11px;
  text-align: center;
}

/* Unterebene tritt zurueck. */
.bucket-row.child {
  padding-left: 32px;
  grid-template-columns: minmax(0, 180px) 1fr minmax(0, 120px) 16px;
}
.bucket-row.child .bar { background: var(--border-strong); }
.bucket-row.child .bar-name { font-weight: 400; color: var(--text-muted); }

/* --- Ziele ------------------------------------------------------------------ */

.ziel-progress-wrap {
  height: 8px;
  background: var(--bg-elev);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.ziel-progress {
  height: 100%;
  background: var(--viz-1);
  border-radius: var(--radius-pill);
  transition: width 200ms var(--ease);
}

/* --- Diagrammflaechen ------------------------------------------------------- */

#chart-allokation, #chart-verlauf, #chart-cashflow,
#chart-donut, #chart-sankey, #chart-heatmap {
  width: 100%;
}

/* --- Anmeldeseite ----------------------------------------------------------- */

.login-wrapper {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-tint);
}

.login-card {
  width: min(400px, 100%);
  padding: 40px 36px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.login-card .subtitle {
  margin: 0 0 28px;
  font-size: 14px;
  color: var(--text-muted);
}

.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card form button { margin-top: 4px; padding: 8px 12px; }

/* --- Hilfsklassen ----------------------------------------------------------- */

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

.muted  { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small  { font-size: 13px; }
.mono   { font-family: var(--mono); font-size: 13px; }

.chev { font-size: 10px; color: var(--text-subtle); }

/* Gewinn und Verlust: Farbe steht immer neben dem Zahlenwert, nie allein. */
.text-pos, .pos { color: var(--success); }
.text-neg, .neg { color: var(--danger); }

.link-monat, button.link-monat {
  padding: 0;
  background: none;
  border: none;
  font-size: inherit;
  font-weight: inherit;
  color: var(--accent);
  cursor: pointer;
}
.link-monat:hover, button.link-monat:hover {
  background: none;
  text-decoration: underline;
}

.wide { grid-column: span 2; }

/* --- Symbole der Seitenleiste (unveraendert uebernommen) -------------------- */

:root {
  --ico-default: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3.5'/%3E%3C/svg%3E");
  --ico-uebersicht: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='13.5' y='3' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='13.5' y='13.5' width='7.5' height='7.5' rx='1.8'/%3E%3Crect x='3' y='13.5' width='7.5' height='7.5' rx='1.8'/%3E%3C/svg%3E");
  --ico-vermoegen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2.5 2.5 7.5l9.5 5 9.5-5-9.5-5Z'/%3E%3Cpath d='m2.5 16.5 9.5 5 9.5-5'/%3E%3Cpath d='m2.5 12 9.5 5 9.5-5'/%3E%3C/svg%3E");
  --ico-cashflow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 17.5 9.5 11l4 4L21 7.5'/%3E%3Cpath d='M15 7.5h6v6'/%3E%3C/svg%3E");
  --ico-ziele: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Ccircle cx='12' cy='12' r='5'/%3E%3Ccircle cx='12' cy='12' r='1.2'/%3E%3C/svg%3E");
  --ico-erfassen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E");
  --ico-einstellungen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3.2'/%3E%3Cpath d='M20 12a8 8 0 0 0-.15-1.5l2-1.55-2-3.46-2.35.95a8 8 0 0 0-2.6-1.5L14.5 2h-4l-.4 2.44a8 8 0 0 0-2.6 1.5L5.15 5 3.15 8.45l2 1.55A8 8 0 0 0 5 12a8 8 0 0 0 .15 1.5l-2 1.55 2 3.46 2.35-.95a8 8 0 0 0 2.6 1.5l.4 2.44h4l.4-2.44a8 8 0 0 0 2.6-1.5l2.35.95 2-3.46-2-1.55A8 8 0 0 0 20 12Z'/%3E%3C/svg%3E");
}

.sidebar a[href="/index.html"]          { --ico: var(--ico-uebersicht); }
.sidebar a[href="/vermoegen.html"]      { --ico: var(--ico-vermoegen); }
.sidebar a[href="/cashflow.html"]       { --ico: var(--ico-cashflow); }
.sidebar a[href="/ziele.html"]          { --ico: var(--ico-ziele); }
.sidebar a[href="/erfassen.html"]       { --ico: var(--ico-erfassen); }
.sidebar a[href="/einstellungen.html"]  { --ico: var(--ico-einstellungen); }

/* --- Handy und Tablet ------------------------------------------------------- */

@media (max-width: 900px) {
  /* Die Seitenleiste wird zur oberen Leiste: Marke und Knoepfe in einer Zeile,
     die Navigation als Reiterzeile darunter. Eine schmale Symbolspalte waere
     auf einem 360-px-Display verschenkter Platz. */
  /* Zwei Zeilen: die Leiste bekommt ihre natuerliche Hoehe, der Inhalt den
     Rest. Ohne "auto 1fr" verteilt das Raster den ungenutzten Platz bei
     kurzen Seiten gleichmaessig auf beide Zeilen - die Leiste wuerde dann
     nach unten aufgezogen. Genau das passierte auf Ziele, Erfassen und
     Einstellungen, weil dort keine Diagramme mit fester Hoehe stehen. */
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }

  /* Navigation ist jetzt ueberall ein aufklappbarer Drawer (siehe Basis-CSS) -
     keine Umformung der Leiste mehr noetig. */

  /* -- Inhalt -- */
  main.content { padding: 16px 14px 44px; }
  main.content > header { margin-bottom: 16px; gap: 10px; }
  main.content h1 { font-size: 20px; }
  .card { padding: 14px; }

  /* -- Kennzahlen: fuehrende Zahl volle Breite, Rest zu zweit -- */
  .stat-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 18px;
    margin-bottom: 20px;
    padding-bottom: 16px;
  }
  .stat-card.big { grid-column: 1 / -1; }
  .stat-card .val { font-size: 21px; }
  .stat-card.big .val { font-size: 30px; }

  /* Zeitraum-Auswahl darf nicht ueber den rechten Rand laufen. */
  .stat-card .dropdown { left: auto; right: 0; min-width: 200px; }

  /* -- Raster der Seiten einspaltig. Die Seiten setzen die Spalten per
        style-Attribut, deshalb hier ausdruecklich uebersteuern. -- */
  .grid, .grid[style] { grid-template-columns: 1fr !important; gap: 12px !important; }

  /* -- Diagramme niedriger, sonst scrollt man ewig. Hoehe steht inline. -- */
  #chart-allokation, #chart-verlauf, #chart-cashflow, #chart-donut {
    height: 230px !important;
  }
  #chart-heatmap { height: 280px !important; }
  #chart-sankey  { height: 400px !important; }

  /* -- Bucket-Balken schmaler -- */
  .bucket-row, .bucket-row.child {
    grid-template-columns: minmax(0, 1.2fr) 1fr minmax(0, 0.9fr) 14px;
    gap: 8px;
    padding: 7px 4px;
  }
  .bucket-row.child { padding-left: 16px; }
  .bucket-row .bar-name { font-size: 13px; }
  .bucket-row .bar-value { font-size: 12px; }

  /* -- Formulare einspaltig, Aktionsknoepfe volle Breite -- */
  .form-row { grid-template-columns: 1fr; gap: 10px; padding: 14px; }
  .form-row .wide, .form-row .form-row-full { grid-column: 1 / -1; }
  .form-row .form-actions { flex-direction: column; align-items: stretch; }
  .form-row .form-actions button { width: 100%; min-width: 0; }

  .section-head { flex-wrap: wrap; gap: 8px; }
  .tab-nav { gap: 2px; }
  .tab-nav > button { padding: 5px 9px; font-size: 13px; }

  /* Grosszuegigere Trefferflaechen auf Touch-Geraeten. */
  .data-table th, .data-table td { padding: 9px 8px; }
}

@media (max-width: 420px) {
  .stat-row { grid-template-columns: 1fr; }
  main.content { padding: 14px 10px 40px; }
  main.content h1 { font-size: 18px; }
  .login-card { padding: 28px 22px; }
}

/* --- Umschalter in Abschnittskoepfen (z. B. Allokation) --------------------- */

.section-head .row button {
  padding: 4px 9px;
  font-size: 13px;
  font-weight: 400;
  background: transparent;
  color: var(--text-muted);
}
.section-head .row button:hover { background: var(--bg-elev); color: var(--text); }
.section-head .row button.active {
  background: var(--bg-active);
  color: var(--text);
  font-weight: 500;
}

@media (max-width: 900px) {
  /* Bei vielen Kategorien darf die Knopfreihe umbrechen statt zu quetschen. */
  .section-head { flex-wrap: wrap; }
  .section-head .row { flex-wrap: wrap; gap: 2px; }
  .section-head .row button { padding: 4px 7px; font-size: 12px; }
}

/* --- Vertrieb: Icons fuer die eigenen Seiten + zweiter Querlink ------------ */
:root {
  --ico-projekte: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='7' width='20' height='14' rx='2'/%3E%3Cpath d='M16 7V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v2'/%3E%3C/svg%3E");
  --ico-provisionen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M15 8.5a3.5 3.5 0 1 0 0 7'/%3E%3Cline x1='7' y1='11' x2='13' y2='11'/%3E%3Cline x1='7' y1='13.5' x2='12' y2='13.5'/%3E%3C/svg%3E");
  --ico-auswertung: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='3' y1='21' x2='21' y2='21'/%3E%3Crect x='6' y='10' width='3' height='8'/%3E%3Crect x='11' y='6' width='3' height='12'/%3E%3Crect x='16' y='13' width='3' height='5'/%3E%3C/svg%3E");
}
.sidebar a[href="/projekte.html"]     { --ico: var(--ico-projekte); }
.sidebar a[href="/provisionen.html"]  { --ico: var(--ico-provisionen); }
.sidebar a[href="/auswertung.html"]   { --ico: var(--ico-auswertung); }

/* Zwei Querlinks (Finanzen + Projekttool): nur der erste bekommt die Trennlinie. */
.sidebar a.cross-app + a.cross-app { border-top: 0; margin-top: 0; padding-top: 6px; }

/* Rechtsbuendige Zahlenspalten in Tabellen. */
.data-table th.num, .data-table td.num, .num { text-align: right; }

/* Vertrieb: Icon fuer die Kennzahlen-Seite (Regler). */
:root {
  --ico-kennzahlen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='4' y1='21' x2='4' y2='14'/%3E%3Cline x1='4' y1='10' x2='4' y2='3'/%3E%3Cline x1='12' y1='21' x2='12' y2='12'/%3E%3Cline x1='12' y1='8' x2='12' y2='3'/%3E%3Cline x1='20' y1='21' x2='20' y2='16'/%3E%3Cline x1='20' y1='12' x2='20' y2='3'/%3E%3Cline x1='1' y1='14' x2='7' y2='14'/%3E%3Cline x1='9' y1='8' x2='15' y2='8'/%3E%3Cline x1='17' y1='16' x2='23' y2='16'/%3E%3C/svg%3E");
}
.sidebar a[href="/kennzahlen.html"] { --ico: var(--ico-kennzahlen); }
