:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1b1f24;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1f5eff;
  --accent-ink: #ffffff;
  --ok: #0a7d34;
  --err: #b42318;
  --warn: #9a6700;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Muss vor allen Autor-Regeln mit eigenem display stehen (.centered, .spinner u.a.),
   sonst gewinnt die spezifischere Klasse gegen das hidden-Attribut. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  font-size: 15px;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }

.view { min-height: 100vh; }
.centered { display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.muted { color: var(--muted); }
.error { color: var(--err); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

/* Login */
.login-card { width: 100%; max-width: 340px; }
.login-card input { margin: .75rem 0; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.container { max-width: 900px; margin: 1.5rem auto; padding: 0 1.5rem; }

/* Forms */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.field { display: flex; flex-direction: column; }
label { font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }

input, select, button {
  font: inherit;
  padding: .55rem .7rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
input[type="file"] { padding: .4rem; background: #fafbfc; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button:hover { filter: brightness(.95); }
button:disabled { opacity: .55; cursor: default; }
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
#start-btn, #login-btn { margin-top: 1rem; width: 100%; }

/* Result */
.result-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .5rem; flex-wrap: wrap; }
.result-head h2 { margin: 0; }
.badge {
  font-size: .78rem; padding: .15rem .55rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.badge.laufend { color: var(--warn); border-color: var(--warn); }
.badge.fertig  { color: var(--ok);  border-color: var(--ok); }
.badge.fehler  { color: var(--err); border-color: var(--err); }

/* Live-Spinner waehrend eines laufenden Analyse-Jobs */
.spinner {
  display: inline-block;
  width: 1rem; height: 1rem;
  border: 2px solid var(--line);
  border-top-color: var(--warn);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}
.result-elapsed { font-size: .85rem; }

/* .warn-text: nicht-blockierende Hinweise (z.B. Platzhalter-Hinweis bei der
   Methodik, "Analyse laeuft ungewoehnlich lange"). .field-error: blockierende
   Formular-Probleme, die den Start-Knopf sperren (PDF zu gross, Haiku+PDF) —
   eigene Klasse mit Fehlerfarbe, damit beide Faelle optisch unterscheidbar sind. */
.warn-text { color: var(--warn); font-size: .9rem; }
.field-error { color: var(--err); font-size: .9rem; }
.field .warn-text, .field .field-error { margin: .35rem 0 0; }
.upload-status-zeile { display: flex; align-items: center; gap: .5rem; margin: .75rem 0 0; }
.upload-status-zeile #upload-status { margin: 0; }

/* Verlauf */
.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 0; border-bottom: 1px solid var(--line);
}
.history li:last-child { border-bottom: 0; }
.history .meta { font-size: .85rem; color: var(--muted); }
.history button { padding: .3rem .6rem; font-weight: 500; font-size: .85rem; }

/* Markdown-Ausgabe */
.markdown { overflow-x: auto; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1.2rem 0 .5rem; line-height: 1.3; }
.markdown h1 { font-size: 1.2rem; }
.markdown h2 { font-size: 1.08rem; }
.markdown h3 { font-size: 1rem; }
.markdown table {
  border-collapse: collapse; width: 100%; margin: .8rem 0; font-size: .9rem;
}
.markdown th, .markdown td {
  border: 1px solid var(--line); padding: .4rem .55rem; text-align: left; vertical-align: top;
}
.markdown th { background: #f0f2f5; }
.markdown code {
  background: #f0f2f5; padding: .1rem .3rem; border-radius: 4px; font-size: .9em;
}
.markdown a { color: var(--accent); }
.markdown ul, .markdown ol { padding-left: 1.3rem; }

/* Methodik */
.methodik-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.methodik-head h2 { margin: 0; }
.hint { margin-top: .35rem; }
.methodik-view {
  max-height: 60vh; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .8rem; background: #fafbfc;
}
.methodik-textarea {
  width: 100%; min-height: 360px; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .85rem; line-height: 1.45;
  padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink);
}
.methodik-textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Merkposten sind kurze Notizen — niedriger als das grosse Methodik-Feld. */
.merkposten-textarea { min-height: 140px; }
.methodik-editbar, .methodik-confirm {
  display: flex; align-items: center; gap: .6rem; margin-top: .6rem; flex-wrap: wrap;
}
.editbar-spacer { flex: 1 1 auto; }

/* Merkposten-Vorschlaege (siehe app.js) */
.merkposten-vorschlaege {
  border: 1px solid var(--line); border-radius: 8px;
  padding: .75rem .9rem; margin-bottom: .9rem; background: #fafbfc;
}
.vorschlaege-titel { margin: 0 0 .2rem; font-weight: 600; font-size: .95rem; }
.vorschlaege-hinweis { margin: 0 0 .6rem; font-size: .82rem; }
.vorschlaege-gruppe + .vorschlaege-gruppe { margin-top: .8rem; }
.vorschlaege-gruppe-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; flex-wrap: wrap; }
.vorschlaege-gruppe-head > .vorschlag-aktion-btn { font-size: .82rem; padding: .3rem .6rem; }
.vorschlaege-liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.vorschlag-zeile {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.vorschlag-text { flex: 1 1 auto; font-size: .9rem; word-break: break-word; }
.vorschlag-aktion-btn { font-size: .82rem; padding: .3rem .6rem; font-weight: 500; white-space: nowrap; flex: 0 0 auto; }
/* Deutlich beschriftet statt eines kleinen "×"-Symbols, groesseres Tap-Ziel
   (mind. .4rem .8rem) und per margin-left zusaetzlich vom Aktions-Button
   abgesetzt (Befund: Tap-Ziel zu klein/zu nah am primaeren Aktions-Knopf). */
.vorschlag-ignorieren-btn {
  flex: 0 0 auto; padding: .4rem .8rem; font-size: .82rem; font-weight: 500;
  white-space: nowrap; margin-left: .4rem;
}

/* Rueckfrage-Chat */
.chat-messages {
  display: flex; flex-direction: column; gap: .75rem;
  max-height: 55vh; overflow-y: auto;
  margin-bottom: 1rem;
}
.chat-messages:empty { margin-bottom: 0; }
.chat-msg { display: flex; flex-direction: column; }
.chat-msg .chat-rolle { font-size: .75rem; color: var(--muted); margin-bottom: .2rem; }
.chat-bubble {
  border: 1px solid var(--line); border-radius: 8px;
  padding: .55rem .75rem; max-width: 100%;
}
.chat-msg.user { align-items: flex-end; }
.chat-msg.user .chat-bubble {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  white-space: pre-wrap; word-break: break-word;
}
.chat-msg.assistant .chat-bubble { background: #fafbfc; }
.chat-msg.assistant .chat-bubble.markdown { font-size: .95rem; }
/* Blinkender Cursor, solange die Antwort noch streamt */
.chat-bubble.streaming::after {
  content: "▋"; color: var(--muted);
  animation: chat-blink 1s steps(2, start) infinite;
}
@keyframes chat-blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  .chat-bubble.streaming::after { animation-duration: 2.4s; }
}
.chat-modell-tag { font-size: .72rem; color: var(--muted); margin-top: .25rem; }
.chat-interrupt {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin-top: .35rem; font-size: .85rem;
}
.chat-interrupt .warn-text { margin: 0; }
/* Standard-Button-Groesse (kein verkleinertes Tap-Target) — diese beiden
   Knoepfe sind der Ausweg aus einer Fehlersituation und muessen gut treffbar sein. */
.chat-interrupt button { font-weight: 500; }

.chat-form fieldset.chat-modell {
  border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .75rem; margin: 0 0 .6rem;
  display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: center;
}
.chat-form fieldset.chat-modell legend { font-size: .75rem; color: var(--muted); padding: 0 .3rem; }
.radio-label {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .9rem; color: var(--ink); margin: 0;
}
.radio-label input { width: auto; margin: 0; }
.chat-input-row { display: flex; gap: .6rem; align-items: flex-end; }
.chat-input-row textarea {
  flex: 1 1 auto; resize: vertical; min-height: 2.6rem;
  font: inherit; padding: .55rem .7rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.chat-input-row textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chat-input-row #chat-send { flex: 0 0 auto; white-space: nowrap; align-self: stretch; }
.chat-status-zeile { display: flex; align-items: center; gap: .5rem; margin: .6rem 0 0; }
.chat-status-zeile #chat-status { margin: 0; }

@media (max-width: 640px) {
  .chat-input-row { flex-direction: column; align-items: stretch; }
  .chat-input-row #chat-send { width: 100%; }
}

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 8px;
  font-size: .9rem; z-index: 50; max-width: 90vw;
}
.toast.err { background: var(--err); }

@media (max-width: 640px) {
  .grid, .row { grid-template-columns: 1fr; }
}

/* --- Zusatz-Auswertung (Grafiken + Kennzahlen) ---------------------------- */

/* Vorab-Auswahl in der Start-Karte */
fieldset.extras-wahl {
  border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .75rem; margin: 0 0 .9rem;
  display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: center;
}
fieldset.extras-wahl legend { font-size: .75rem; color: var(--muted); padding: 0 .3rem; }
fieldset.extras-wahl .hint { flex-basis: 100%; margin: .2rem 0 0; font-size: .85rem; }
.checkbox-label {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .9rem; color: var(--ink); margin: 0;
}
.checkbox-label input { width: auto; margin: 0; }

.extras-aktionen { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.extras-umschalter {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center;
  padding-bottom: .75rem; margin-bottom: .75rem; border-bottom: 1px solid var(--line);
}
/* Aktive Ansicht sichtbar machen — sonst raet der Nutzer, welche Sicht laeuft. */
.extras-umschalter button.aktiv {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}

/* Kennzahlen-Kacheln */
.extras-kacheln {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem; margin-bottom: 1rem;
}
.extras-kachel {
  border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem;
}
.extras-kachel .k-titel { font-size: .8rem; color: var(--muted); }
.extras-kachel .k-wert { font-size: 1.15rem; font-weight: 600; margin-top: .15rem; }
.extras-kachel .k-wert.plus { color: var(--ok); }
.extras-kachel .k-wert.minus { color: var(--err); }

/* Kennzahlen-Tabelle */
.extras-tabelle { width: 100%; border-collapse: collapse; font-size: .92rem; }
.extras-tabelle th, .extras-tabelle td {
  text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line);
}
.extras-tabelle td.zahl, .extras-tabelle th.zahl { text-align: right; font-variant-numeric: tabular-nums; }
/* Summenzeilen zusaetzlich mit Linie absetzen — allein ueber die Schriftstaerke
   sind sie beim Ueberfliegen zu leicht zu uebersehen. */
.extras-tabelle tr.summe td { font-weight: 600; border-top: 2px solid var(--line); }
.extras-tabelle td.plus { color: var(--ok); }
.extras-tabelle td.minus { color: var(--err); }
/* Breite Tabellen scrollen in sich selbst, statt die Seite quer zu schieben. */
.extras-scroll { overflow-x: auto; }

/* Grafik-Bloecke */
.extras-block { margin-bottom: 1.5rem; }
.extras-block h3 { font-size: .95rem; margin: 0 0 .5rem; }
.extras-block svg { display: block; width: 100%; height: auto; max-width: 100%; }
.extras-legende { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .5rem; font-size: .85rem; }
.extras-legende span.eintrag { display: inline-flex; align-items: center; gap: .35rem; }
.extras-legende i { width: .7rem; height: .7rem; border-radius: 2px; display: inline-block; }
.extras-leer { color: var(--muted); font-size: .9rem; }
.extras-block h4 { font-size: .9rem; margin: 1.25rem 0 .35rem; }

/* Loeschende Aktionen sichtbar von hinzufuegenden abheben. Zwei gleich
   aussehende Sammelknoepfe direkt uebereinander, von denen einer handgeschriebene
   Notizen unwiderruflich entfernt, sind eine Einladung zum Fehlgriff
   (Befund Interaktions-Kritiker). */
button.gefaehrlich {
  background: var(--card); color: var(--err); border-color: var(--err);
}
button.gefaehrlich:hover:not(:disabled) { background: var(--err); color: #fff; }
button.gefaehrlich.bestaetigen { background: var(--err); color: #fff; }

/* Zeitraumwahl der Wertentwicklung. Genug Flaeche zum Treffen mit dem Daumen —
   die Seite wird ueberwiegend auf dem Handy gelesen. */
.bereichswahl { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.bereich-btn {
  padding: .4rem .7rem; font-size: .85rem; min-height: 2.2rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink); cursor: pointer;
}
.bereich-btn:hover { border-color: var(--accent); }
.bereich-btn.aktiv {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}

/* Renditetabelle: Jahre als Zeilen, Monate als Spalten. Die Farbe kommt aus dem
   Skript (Staerke nach Betrag), hier stehen nur Raster und Lesbarkeit. */
.rendite-tabelle { font-size: .82rem; white-space: nowrap; }
.rendite-tabelle th, .rendite-tabelle td { padding: .3rem .45rem; }
.rendite-tabelle tbody th { font-weight: 600; position: sticky; left: 0; background: var(--card); }
.rendite-tabelle td.gesamt { font-weight: 600; }
.rendite-tabelle td.muted { color: var(--muted); background: none; }

/* Uebersicht: grosse Zahl links, Ring rechts. Auf schmalen Schirmen
   untereinander — der Ring ist dort sonst nur noch ein Streifen. */
.uebersicht-kopf {
  display: flex; flex-wrap: wrap; gap: 1rem 2rem;
  align-items: center; margin-bottom: 1rem;
}
.uebersicht-zahl { flex: 1 1 14rem; min-width: 0; }
.uebersicht-zahl .gross {
  font-size: 1.9rem; font-weight: 600; line-height: 1.15; margin-top: .1rem;
  font-variant-numeric: tabular-nums;
}
.uebersicht-zahl .entwicklung { font-size: .95rem; margin-top: .25rem; }
.uebersicht-zahl .entwicklung.plus { color: var(--ok); }
.uebersicht-zahl .entwicklung.minus { color: var(--err); }
.uebersicht-ring { flex: 1 1 16rem; max-width: 22rem; min-width: 0; }
@media (max-width: 560px) {
  .uebersicht-zahl .gross { font-size: 1.55rem; }
}

.extras-hinweise { border-top: 1px solid var(--line); padding-top: .75rem; }
.extras-hinweise ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.extras-hinweise li { font-size: .88rem; color: var(--muted); }

@media (max-width: 640px) {
  .extras-aktionen button, .extras-umschalter button { flex: 1 1 auto; }
}

/* --- Bereichs-Navigation ------------------------------------------------
   Drei Bereiche statt einer langen Seite. Bewusst schlicht: Textlinks mit
   Unterstrich beim aktiven Eintrag, keine Reiter-Optik, kein Framework. */
.seitennav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 0 0 1.25rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--line);
}
.nav-eintrag {
  color: var(--muted);
  text-decoration: none;
  padding: .35rem 0;
  border-bottom: 2px solid transparent;
  font-size: .95rem;
}
.nav-eintrag:hover { color: var(--text); }
.nav-eintrag.aktiv {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
/* Menue-Knopf: nur am schmalen Schirm sichtbar. */
.nav-menue-btn { display: none; }
.nav-liste { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }

@media (max-width: 640px) {
  /* Am Handy: ein Knopf mit dem aktuellen Bereich, der die Liste aufklappt.
     Die Reiterzeile haette hier Platz gekostet, den der Inhalt braucht. */
  .seitennav { display: block; position: relative; }
  .nav-menue-btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: 1rem;
    padding: .5rem .9rem;
  }
  .nav-liste {
    display: none;
    position: absolute;
    top: calc(100% + .35rem);
    left: 0;
    min-width: 12rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    padding: .25rem;
    z-index: 10;
  }
  .nav-liste.offen { display: flex; }
  .nav-liste .nav-eintrag {
    padding: .7rem .75rem;
    border-bottom: none;
    border-radius: 8px;
  }
  .nav-liste .nav-eintrag.aktiv {
    background: var(--bg);
    border-bottom-color: transparent;
  }
}

/* Punkt am Menue-Knopf — gleiche Bedeutung wie der Punkt am Eintrag, nur an
   der Stelle, die am Handy immer sichtbar ist. */
.nav-punkt {
  display: inline-block;
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: var(--accent);
}

/* Punkt am Navigationseintrag, wenn dort etwas passiert ist, waehrend der
   Betreiber woanders war. */
.nav-eintrag.hinweis::after {
  content: "";
  display: inline-block;
  width: .5rem;
  height: .5rem;
  margin-left: .4rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}

/* Die Navigation bleibt am oberen Rand stehen. Auf einer langen Ergebnisseite
   musste man sonst erst ganz nach oben scrollen, um den Bereich zu wechseln —
   am Handy die haeufigste Bewegung (Befund Interaktions-Kritiker). */
.seitennav {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg, #fff);
}
