/* Dunkles Dashboard, angelehnt an die Vorlage aus dem Screenshot.
   Telegram-Variablen werden genutzt, wenn die App im Messenger laeuft. */

:root {
  --bg:        var(--tg-theme-bg-color, #000000);
  --flaeche:   #1C1C1E;
  --flaeche-2: #2C2C2E;
  --text:      var(--tg-theme-text-color, #FFFFFF);
  --text-2:    #8E8E93;
  --akzent:    var(--tg-theme-button-color, #3B82F6);
  --gruen:     #30D158;
  --rot:       #FF453A;
  --radius:    18px;
  --radius-s:  14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Muss vor allen display-Regeln stehen: sonst ueberschreibt ein spaeteres
   display:flex das hidden-Attribut und das Element bleibt sichtbar. */
[hidden] { display: none !important; }

/* Sichere Raender. Telegram setzt --rand-oben/--rand-unten, wo es sie kennt;
   sonst greifen die env()-Werte von iOS. */
:root {
  --rand-oben: env(safe-area-inset-top, 0px);
  --rand-unten: env(safe-area-inset-bottom, 0px);
  --fensterhoehe: 100dvh;
}

/* Das Dokument selbst scrollt NICHT.
   Sonst deutet iOS ein Ziehen am oberen Rand als Schliessgeste, und die
   Mini App rutscht nach unten weg -- genau das soll nicht passieren.
   Gescrollt wird ausschliesslich in #app. */
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

#app {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;   /* kein Weiterreichen an Telegram */
  padding: 0 16px;
  padding-top: var(--rand-oben);
}

/* Im Vollbild liegt Telegrams Schliessen-Kreuz oben rechts ueber der Seite. */
:root.vollbild #app { padding-top: calc(var(--rand-oben) + 44px); }

.seite { padding-top: 8px; }
.fussraum { height: 140px; }

/* ---------------------------------------------------------- Kopfzeile */
.kopf { display: flex; gap: 8px; padding: 12px 0 4px; flex-wrap: wrap; align-items: center; }
.kopf-titel { gap: 12px; }
.kopf-titel h1 { font-size: 20px; margin: 0; font-weight: 600; }

.chip {
  background: var(--flaeche-2); color: var(--text); border: 0;
  border-radius: 999px; padding: 11px 18px; font-size: 15px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
}
.chip-aktiv { background: var(--akzent); color: #fff; }
.pfeil { font-size: 11px; opacity: .8; }

.zurueck {
  background: var(--flaeche-2); border: 0; color: var(--text);
  width: 36px; height: 36px; border-radius: 50%; font-size: 17px; cursor: pointer;
}

/* ---------------------------------------------------------- Summe */
.summe-block { padding: 16px 0 4px; }
.summe { font-size: 40px; font-weight: 700; letter-spacing: -1.2px; }
.summe-zeile { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.summe-label { color: var(--text-2); font-size: 16px; }
.delta {
  background: var(--flaeche-2); color: var(--text-2);
  border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 500;
}

/* ---------------------------------------------------------- Donut */
.donut-huelle { position: relative; width: 240px; margin: 12px auto 4px; }
#donut { width: 100%; display: block; overflow: visible; }
#donut circle { transition: stroke-dasharray .45s cubic-bezier(.4,0,.2,1), opacity .2s; }
#donut circle.gedimmt { opacity: .3; }

.donut-mitte {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none; text-align: center;
}
.donut-mitte-wert { font-size: 19px; font-weight: 700; }
.donut-mitte-text { font-size: 12px; color: var(--text-2); max-width: 110px; margin-top: 2px; }

.donut-beschriftung { font-size: 11px; fill: var(--text-2); font-weight: 600; }

/* ---------------------------------------------------------- Umschalter */
.umschalter {
  display: flex; background: var(--flaeche); border-radius: var(--radius);
  padding: 4px; margin: 16px 0; gap: 2px;
}
.umschalter button {
  flex: 1; background: transparent; border: 0; color: var(--text-2);
  padding: 11px; border-radius: var(--radius-s); font-size: 15px;
  font-weight: 500; cursor: pointer; transition: background .18s, color .18s;
}
.umschalter button.an { background: var(--flaeche-2); color: var(--text); }

/* ---------------------------------------------------------- Kategorien */
.kategorie-gitter { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.kategorie-chip {
  display: flex; align-items: center; gap: 9px; padding: 11px 13px;
  border-radius: var(--radius-s); border: 0; cursor: pointer; text-align: left;
  background: var(--flaeche); color: var(--text); min-width: 0;
  transition: transform .12s;
}
.kategorie-chip:active { transform: scale(.97); }
.kategorie-chip.aus { opacity: .35; }

.kategorie-punkt {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 15px;
}
.kategorie-text { min-width: 0; display: flex; flex-direction: column; }
.kategorie-name {
  font-size: 13px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kategorie-summe { font-size: 15px; font-weight: 600; }

/* ---------------------------------------------------------- Karten */
.karte { background: var(--flaeche); border-radius: var(--radius); padding: 16px; margin: 18px 0; }
.karte-titel { font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.abrechnung-gross { font-size: 20px; font-weight: 600; line-height: 1.3; }
.abrechnung-details { margin-top: 12px; display: grid; gap: 7px; }
.abrechnung-zeile {
  display: flex; justify-content: space-between; font-size: 14px;
  color: var(--text-2); gap: 12px;
}
.abrechnung-zeile b { color: var(--text); font-weight: 600; white-space: nowrap; }
.abrechnung-trenner { height: 1px; background: var(--flaeche-2); margin: 4px 0; }

/* ---------------------------------------------------------- Buchungen */
.abschnitt { font-size: 22px; font-weight: 700; margin: 26px 0 4px; }

.tag-kopf {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 22px 0 10px;
}
.tag-name { font-size: 20px; font-weight: 700; }
.tag-summe { color: var(--text-2); font-size: 16px; }

.buchung {
  display: flex; align-items: center; gap: 13px; padding: 9px 0;
  cursor: pointer; border: 0; background: none; color: var(--text);
  width: 100%; text-align: left;
}
.buchung-icon {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 20px;
}
.buchung-mitte { flex: 1; min-width: 0; }
.buchung-titel {
  font-size: 16px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.buchung-unter {
  font-size: 13px; color: var(--text-2); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.buchung-betrag { font-size: 16px; font-weight: 500; white-space: nowrap; }
.buchung-betrag.plus { color: var(--gruen); }
.buchung-betrag.neutral { color: var(--text-2); }

.leer { color: var(--text-2); text-align: center; padding: 40px 20px; font-size: 15px; }

/* ---------------------------------------------------------- Formular */
.art-wahl, .partner-wahl {
  display: flex; gap: 8px; background: var(--flaeche);
  border-radius: var(--radius); padding: 4px; margin: 14px 0;
}
.art-wahl button, .partner-wahl button {
  flex: 1; background: transparent; border: 0; color: var(--text-2);
  padding: 12px 8px; border-radius: var(--radius-s); font-size: 15px;
  font-weight: 500; cursor: pointer;
}
.art-wahl button.an, .partner-wahl button.an { background: var(--akzent); color: #fff; }

.feld { display: block; margin: 18px 0; }
.feld > span, .feld-label {
  display: block; font-size: 13px; color: var(--text-2); margin-bottom: 7px;
}
.feld input {
  width: 100%; background: var(--flaeche); border: 1px solid transparent;
  color: var(--text); border-radius: var(--radius-s);
  padding: 15px 16px; font-size: 17px; font-family: inherit;
}
.feld input:focus { outline: none; border-color: var(--akzent); }
.feld input.falsch { border-color: var(--rot); }
#f-betrag { font-size: 30px; font-weight: 700; letter-spacing: -.5px; }
.fehler { display: block; color: var(--rot); font-size: 13px; margin-top: 7px; line-height: 1.35; }

.kategorie-wahl { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.kategorie-wahl button {
  background: var(--flaeche); border: 1.5px solid transparent; color: var(--text);
  border-radius: 999px; padding: 9px 14px; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
}
.kategorie-wahl button.an { border-color: currentColor; }

.haupt-knopf {
  width: 100%; background: var(--akzent); color: #fff; border: 0;
  border-radius: var(--radius); padding: 17px; font-size: 17px;
  font-weight: 600; cursor: pointer; margin-top: 26px;
}
.haupt-knopf:disabled { opacity: .5; }

/* ---------------------------------------------------------- Plus-Knopf */
.abschnitt-zeile {
  display: flex; align-items: center; justify-content: space-between;
  margin: 26px 0 4px; gap: 12px;
}
.abschnitt-zeile .abschnitt { margin: 0; }
.plus {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none;
  background: var(--akzent); color: #fff; font-size: 26px; font-weight: 300;
  line-height: 1; cursor: pointer; box-shadow: 0 4px 14px rgba(59,130,246,.4);
  transition: transform .12s;
}
.plus:active { transform: scale(.92); }

/* ---------------------------------------------------------- Auswahlblatt */
.blatt { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.blatt-hintergrund { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.blatt-inhalt {
  position: relative; width: 100%; background: var(--flaeche);
  border-radius: 22px 22px 0 0; padding: 10px 16px calc(22px + var(--rand-unten));
  max-height: 72dvh; overflow-y: auto; overscroll-behavior: contain;
  animation: hoch .26s cubic-bezier(.32,.72,0,1);
}
@keyframes hoch { from { transform: translateY(100%); } }
.blatt-griff { width: 38px; height: 4px; background: var(--flaeche-2); border-radius: 2px; margin: 0 auto 14px; }
.blatt-eintrag {
  display: block; width: 100%; background: none; border: 0; color: var(--text);
  padding: 15px 4px; font-size: 16px; text-align: left; cursor: pointer;
  border-bottom: 1px solid var(--flaeche-2);
}
.blatt-eintrag:last-child { border-bottom: 0; }
.blatt-eintrag.an { color: var(--akzent); font-weight: 600; }
.blatt-eintrag.gefahr { color: var(--rot); }

/* ---------------------------------------------------------- Hinweis */
.hinweis {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--flaeche-2); color: var(--text); padding: 12px 20px;
  border-radius: 999px; font-size: 14px; z-index: 80; max-width: 88vw;
  text-align: center; animation: einblenden .2s;
}
.hinweis.schlecht { background: var(--rot); color: #fff; }
@keyframes einblenden { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------------------------------------------------- Startfehler */
.startfehler {
  max-width: 340px; margin: 0 auto; padding: 90px 8px 40px;
  text-align: center; color: var(--text);
}
.startfehler-symbol { font-size: 46px; margin-bottom: 18px; }
.startfehler h1 { font-size: 22px; font-weight: 700; margin: 0 0 12px; }
.startfehler p { color: var(--text-2); font-size: 15px; line-height: 1.5; margin: 0 0 14px; }
.startfehler p b { color: var(--text); font-weight: 600; }
.startfehler-klein { font-size: 13px !important; opacity: .7; }

/* ---------------------------------------------------------- Navigation */
.navi {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(28,28,30,.94); backdrop-filter: blur(16px);
  border-top: 1px solid #2C2C2E;
  padding: 8px 8px calc(8px + var(--rand-unten));
}
.navi button {
  flex: 1; background: none; border: 0; color: var(--text-2);
  font-size: 11px; font-weight: 500; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 4px; font-family: inherit;
}
.navi button span { font-size: 19px; line-height: 1; }
.navi button.an { color: var(--akzent); }

/* ---------------------------------------------------------- Berichte */
.jahr-waehler {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  margin: 14px 0 4px;
}
.jahr-waehler button {
  background: var(--flaeche-2); border: 0; color: var(--text);
  width: 38px; height: 38px; border-radius: 50%; font-size: 19px; cursor: pointer;
}
.jahr-waehler button:disabled { opacity: .3; }
#jahr-label { font-size: 21px; font-weight: 700; min-width: 76px; text-align: center; }

.monatszeile {
  display: grid; grid-template-columns: 52px 1fr 92px;
  align-items: center; gap: 10px; padding: 9px 0;
  border: 0; background: none; color: var(--text); width: 100%;
  text-align: left; cursor: pointer; font-family: inherit;
  border-bottom: 1px solid #242426;
}
.monatszeile:last-child { border-bottom: 0; }
.monatszeile.leer { opacity: .35; }
.monatszeile-name { font-size: 14px; font-weight: 600; color: var(--text-2); }
.balken { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.balken-spur { display: block; height: 7px; border-radius: 4px; background: #242426; overflow: hidden; }
.balken-wert { display: block; height: 100%; border-radius: 4px; }
.balken-ein .balken-wert { background: var(--gruen); }
.balken-aus .balken-wert { background: var(--rot); }
.monatszeile-gewinn { text-align: right; font-size: 14px; font-weight: 600; }
.monatszeile-gewinn.minus { color: var(--rot); }

.karte-fuss { color: var(--text-2); font-size: 12px; line-height: 1.5; margin: 10px 0 0; }
.legende { display: flex; gap: 14px; font-size: 11px; color: var(--text-2); margin-bottom: 10px; }
.legende i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

.pdf-knoepfe { display: flex; gap: 8px; }
.pdf-knoepfe button {
  flex: 1; background: var(--akzent); color: #fff; border: 0;
  border-radius: var(--radius-s); padding: 13px; font-size: 14px;
  font-weight: 600; cursor: pointer; font-family: inherit;
}
.pdf-knoepfe button:disabled { opacity: .5; }

/* ---------------------------------------------------------- Abrechnung */
.ergebnis-karte { background: linear-gradient(145deg, #1C1C1E, #24242B); }
.ergebnis-karte .abrechnung-gross { font-size: 23px; }

/* ---------------------------------------------------------- Einstellungen */
.zweit-knopf {
  width: 100%; background: var(--flaeche-2); color: var(--text); border: 0;
  border-radius: var(--radius-s); padding: 13px; font-size: 14px;
  font-weight: 600; cursor: pointer; font-family: inherit; margin-top: 10px;
}
.zweit-knopf:disabled { opacity: .5; }

.kat-zeile, .storno-zeile, .partner-zeile {
  display: flex; align-items: center; gap: 11px; padding: 10px 0;
  border-bottom: 1px solid #242426;
}
.kat-zeile:last-child, .storno-zeile:last-child, .partner-zeile:last-child {
  border-bottom: 0;
}
.kat-punkt {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 15px;
}
.kat-mitte, .storno-mitte, .partner-mitte { flex: 1; min-width: 0; }
.kat-name, .storno-name, .partner-name {
  font-size: 15px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kat-unter, .storno-unter, .partner-unter {
  font-size: 12px; color: var(--text-2); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kat-zeile.aus .kat-name, .kat-zeile.aus .kat-punkt { opacity: .4; }

.mini-knopf {
  background: var(--flaeche-2); border: 0; color: var(--text-2);
  border-radius: 999px; padding: 7px 13px; font-size: 12.5px;
  cursor: pointer; font-family: inherit; flex: none; font-weight: 500;
}
.mini-knopf.gefahr { color: var(--rot); }
.mini-knopf.gut { color: var(--gruen); }

.gruppe-titel {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-2); margin: 14px 0 4px; font-weight: 600;
}
.gruppe-titel:first-child { margin-top: 0; }

.farbwahl { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 2px; }
.farbwahl button {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0;
}
.farbwahl button.an { border-color: #fff; }

code {
  background: var(--flaeche-2); padding: 1px 5px; border-radius: 4px;
  font-size: 12px; font-family: ui-monospace, monospace;
}

.blatt-feld {
  width: 100%; background: var(--flaeche-2); border: 1.5px solid transparent;
  color: var(--text); border-radius: var(--radius-s);
  padding: 14px 15px; font-size: 17px; font-family: inherit; margin-bottom: 4px;
}
.blatt-feld:focus { outline: none; border-color: var(--akzent); }
.blatt-knoepfe { display: flex; gap: 8px; margin-top: 10px; }
.blatt-knoepfe .zweit-knopf, .blatt-knoepfe .blatt-ok { flex: 1; margin-top: 0; }
.blatt-ok { padding: 13px; font-size: 14px; border-radius: var(--radius-s); }

/* ---------------------------------------------------------- Zahlungsart */
.zahlweg-balken {
  display: flex; height: 9px; border-radius: 5px; overflow: hidden;
  background: #242426; margin-bottom: 12px;
}
.zahlweg-bar { display: block; background: #F59E0B; }
.zahlweg-konto { display: block; background: #3B82F6; }
