/* Alle Farbpaare sind im Browser nachgemessen (WCAG AA: 4,5:1 fuer normalen
   Text, 3:1 ab 24 px bzw. 18,66 px fett) - in HELL und DUNKEL. Wer hier etwas
   aendert, misst nach; geschaetzte Farben sind hier schon zweimal
   durchgefallen. Die gemessenen Werte stehen jeweils daneben. */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;          /* 4.76 auf --surface */
  --muted-strong: #475569;   /* 6.92 auf --surface-2, fuer kleine Schrift */
  --border: #e2e8f0;
  --primary: #2563eb;        /* 5.17 als Text auf --surface */
  --primary-bg: #2563eb;     /* Knopfgrund, weisse Schrift: 5.17 */
  --primary-ink: #ffffff;
  --pos: #15803d;            /* 5.02 auf --surface; #16a34a hatte nur 3.30 */
  --neg: #dc2626;            /* 4.83 auf --surface */
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 14px;
}
[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --text: #e5e7eb;
  --muted: #94a3b8;          /* 5.71 auf --surface-2 */
  --muted-strong: #cbd5e1;   /* 9.85 auf --surface-2 */
  --border: #1f2937;
  /* Zwei Blautoene statt einem: Als TEXT auf dunklem Grund muss die Farbe hell
     sein, als KNOPFGRUND unter weisser Schrift dunkel. Ein einziger Wert kann
     beides nicht - #3b82f6 kam als Knopfgrund auf 3.68 und fiel damit durch. */
  --primary: #60a5fa;        /* 6.98 als Text auf --surface */
  --primary-bg: #2563eb;     /* Knopfgrund, weisse Schrift: 5.17 */
  --primary-ink: #ffffff;
  --pos: #22c55e;            /* 7.79 auf --surface */
  --neg: #f87171;            /* 6.41 auf --surface */
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0 0 .5rem; }
a { color: var(--primary); }
button { font: inherit; cursor: pointer; }

/* ---------- Layout ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  /* Umbruch statt Abschneiden: Auf sehr schmalen Schirmen rutschen die
     Bedienknoepfe in eine zweite Zeile. Vorher gab es nur die Wahl zwischen
     einem auf "InA..." verstuemmelten Titel und einer ueberlaufenden Leiste,
     die die fixierte Navigation mitriss. */
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  padding: .6rem .75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
/* Der Titel gibt nach, die Bedienknoepfe behalten ihre Groesse. Ohne
   min-width:0 draengt der Titel sie aus dem Bild - auf 390 px lief die
   Kopfzeile 74 px ueber und riss die fixierte Navigation mit sich. */
.topbar .brand {
  font-size: 1.05rem; margin: 0;
  /* Der Titel bleibt ganz - dank flex-wrap muss er nicht mehr weichen. */
  white-space: nowrap;
}
.topbar .icon-btn { flex: 0 0 auto; }
/* Der Installieren-Knopf traegt Text und braucht am meisten Platz; auf
   schmalen Schirmen weicht er als Erster. */
#btn-install { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 430px) {
  .topbar { gap: .3rem; padding: .6rem .5rem; }
  #btn-install { font-size: .8rem; padding: .4rem .5rem; }
}
.brand { font-weight: 800; letter-spacing: -.02em; }
.brand span { color: var(--primary); }
.spacer { flex: 1; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .4rem .6rem; color: var(--text);
  /* 44 px in beide Richtungen. Die Breite war auf 40 px gesenkt, damit die
     Knoepfe neben den Titel passen - seit die Kopfzeile umbricht, ist das
     nicht mehr noetig. */
  min-height: 44px; min-width: 44px;
  display: inline-flex; align-items: center; justify-content: center;
}
.content { flex: 1; padding: 1rem; max-width: 900px; width: 100%; margin: 0 auto; padding-bottom: 5rem; }

/* Bottom-Nav (mobil) */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: .35rem env(safe-area-inset-right) calc(.35rem + env(safe-area-inset-bottom)) env(safe-area-inset-left);
  z-index: 10;
}
/* Die sechs Eintraege teilen sich die Breite gleichmaessig. Mit festen
   Innenabstaenden lief der letzte ("Sammelb.") auf jedem Handy aus dem Bild -
   die Sammelbuchungen waren per Navigation nicht mehr erreichbar. */
.bottom-nav button {
  flex: 1 1 0; min-width: 0;
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .66rem; padding: .3rem .1rem; border-radius: 10px;
  min-height: 44px;  /* bequem mit dem Finger treffbar */
}
.bottom-nav button > span:last-child {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bottom-nav button .ico { font-size: 1.3rem; }
/* Auf schmalen Geraeten (320-360 px) teilen sich sechs Eintraege rund 55 px.
   "Buchungen" wurde dort zu "Buchung…" gekuerzt - eine Beschriftung, die man
   raten muss. Kleinere Schrift statt Auslassungspunkte. */
@media (max-width: 380px) {
  .bottom-nav button { font-size: .58rem; letter-spacing: -.01em; }
  .bottom-nav button .ico { font-size: 1.2rem; }
}
@media (max-width: 340px) {
  .bottom-nav button { font-size: .52rem; }
}
.bottom-nav button.active { color: var(--primary); }

/* ---------- Cards / lists ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; margin-bottom: 1rem;
}
.row { display: flex; align-items: center; gap: .75rem; }
.list-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 0; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
/* Listeneintraege sind anklickbar (Statuswechsel) - gross genug dafuer. */
.list-item[role="button"] { min-height: 44px; cursor: pointer; }
/* Lange Einzelwörter brechen notfalls um, statt bei 320 px unter den Betrag
   zu laufen; der Betrag selbst bricht nie. */
.list-item .grow { flex: 1; min-width: 0; overflow-wrap: break-word; hyphens: auto; }
.beleg-position { align-items: flex-start; }
.mt-xs { margin-top: .35rem; }
.list-item > .amount { flex-shrink: 0; white-space: nowrap; }
.list-item .sub, .inbox-item .sub, .stand-row .sub { color: var(--muted); font-size: .82rem; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; }
/* Mehrere Waehrungen untereinander, rechtsbuendig - ein Kontakt kann in CHF
   im Plus und in EUR im Minus stehen. */
.amounts { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.amount.pos { color: var(--pos); }
.amount.neg { color: var(--neg); }
.muted { color: var(--muted); }

.badge {
  display: inline-block; font-size: .72rem; font-weight: 600;
  padding: .15rem .5rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.erfasst { color: var(--muted-strong); }
.badge.zu_pruefen { color: #b45309; background: #fef3c7; border-color: #fde68a; }
.badge.unsicher { color: #b45309; background: #fef3c7; border-color: #fde68a; }
.badge.genehmigt { color: #15803d; background: #dcfce7; border-color: #bbf7d0; }
.badge.archiviert { color: var(--muted-strong); background: var(--surface-2); }
[data-theme="dark"] .badge.zu_pruefen { color: #fbbf24; background: #78350f33; border-color: #78350f; }
[data-theme="dark"] .badge.unsicher { color: #fbbf24; background: #78350f33; border-color: #78350f; }
[data-theme="dark"] .badge.genehmigt { color: #4ade80; background: #14532d33; border-color: #14532d; }

/* Stand eines Abgleichs - eigene Klassen, die Statuswerte heissen anders. */
.badge.abg-offen { color: #b45309; background: #fef3c7; border-color: #fde68a; }
.badge.abg-angenommen { color: #15803d; background: #dcfce7; border-color: #bbf7d0; }
.badge.abg-abgelehnt { color: #b91c1c; background: #fee2e2; border-color: #fecaca; }
/* Verfallen (Verknuepfung beendet): wie "archiviert" - erledigt, ohne Wertung.
   --muted-strong auf --surface-2 ist in beiden Themen nachgemessen (6,92 / 9,85). */
.badge.abg-verfallen { color: var(--muted-strong); background: var(--surface-2); }
[data-theme="dark"] .badge.abg-offen { color: #fbbf24; background: #78350f33; border-color: #78350f; }
[data-theme="dark"] .badge.abg-angenommen { color: #4ade80; background: #14532d33; border-color: #14532d; }
[data-theme="dark"] .badge.abg-abgelehnt { color: #fca5a5; background: #7f1d1d33; border-color: #7f1d1d; }
/* Badges duerfen umbrechen: Ein Ablehnungsgrund ist Freitext und lief sonst
   ueber den Rand. */
.badge { white-space: normal; overflow-wrap: anywhere; }
.badge[class*="abg-"] { border-radius: 8px; }
/* Der Status im Belegkopf ist ein echter Knopf, das Abzeichen liegt darin.
   Er traegt die 44 px selbst; die negativen Raender halten die Kopfzeile
   dabei so flach wie das Abzeichen (21 px). Vorher war das Abzeichen das
   Bedienelement: Kasten 68 x 20,8 px, die 44 px nur ueber ein unsichtbares
   ::after, das weder eine Messung noch ein Pruefwerkzeug als Trefferflaeche
   erkennt. */
.status-knopf {
  background: none; border: none; color: inherit; padding: 0 .35rem;
  min-height: 44px; min-width: 44px; margin: -12px -.35rem;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
}
/* Der Fokusrahmen sitzt am Abzeichen: Der Rahmen des Knopfs ragte in die
   Zeile darunter und ueberdeckte dort Text (im Browser gesehen). */
.status-knopf:focus-visible { outline: none; }
.status-knopf:focus-visible .badge { outline: 3px solid var(--primary); outline-offset: 2px; }

/* Stand in der Uebersicht: je Waehrung zwei Spalten */
.stand-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1rem; padding: .5rem 0;
  border-bottom: 1px solid var(--border); }
.stand-row:last-of-type { border-bottom: none; }
.card h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
/* Filter: aufklappbar, Zeitraum nebeneinander (bricht unter 340 px um) */
.filter-card summary { cursor: pointer; list-style: none; min-height: 44px;
  display: flex; align-items: center; }
.filter-card summary::-webkit-details-marker { display: none; }
.filter-card summary h2 { margin: 0; font-size: 1.1rem; }
.filter-card summary h2::before { content: "▸ "; color: var(--muted); }
.filter-card[open] summary h2::before { content: "▾ "; }
.date-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0 .75rem; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* Eingang in der Uebersicht */
.inbox-item { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.inbox-item:last-child { border-bottom: none; }
.link-form { padding: .25rem 0 .75rem; }
/* Zaehler am Navigationseintrag: weisse Schrift auf --primary-bg (5.17). */
.bottom-nav .ico { position: relative; }
.nav-badge {
  position: absolute; top: -.35rem; right: -.75rem;
  min-width: 1.15rem; height: 1.15rem; padding: 0 .3rem; border-radius: 999px;
  background: var(--primary-bg); color: var(--primary-ink);
  font-size: .7rem; font-weight: 700; line-height: 1.15rem; text-align: center;
}

/* ---------- Forms / buttons ---------- */
label { display: block; font-size: .82rem; color: var(--muted); margin: .6rem 0 .2rem; }
input, select, textarea {
  width: 100%; padding: .6rem .7rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  /* Gemessen: 13,3 px Schrift (Browser-Vorgabe fuer Formularfelder, denn
     "font: inherit" galt nur fuer button) und 36,2 px Hoehe. Beides ist auf dem
     Handy - dem Hauptfall - falsch: Unter 16 px zoomt iOS Safari die Seite beim
     Hineintippen und zoomt nicht wieder heraus, und 36 px unterschreiten die
     44 px, die eine Trefferflaeche haben muss. */
  font-family: inherit;
  font-size: 1rem;
  min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

/* Sichtbarer Fokus fuer jedes Bedienelement - ohne ihn ist Tastaturbedienung
   blind. :focus-visible zeigt ihn nur bei Tastatur, nicht bei Mausklick. */
button:focus-visible,
[role="button"]:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 8px;
}
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: .6rem 1rem; border-radius: 10px; font-weight: 600;
  /* 44 px Mindesthoehe fuer alles, was mit dem Finger getroffen wird. Gemessen
     waren es 40,2 px - jeder Knopf der App lag darunter, "Speichern" und
     "Bestaetigen" eingeschlossen. inline-flex, damit ein <a class="btn"> (der
     otpauth-Link der 2FA-Einrichtung) genauso aussieht und genauso trifft. */
  min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.btn.primary { background: var(--primary-bg); color: var(--primary-ink); border-color: var(--primary-bg); }
.btn.small { padding: .35rem .6rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; flex-wrap: wrap; gap: .5rem; }
.section-head { display: flex; align-items: center; margin-bottom: .5rem; }
.section-head h2 { margin: 0; font-size: 1.1rem; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  padding: 1.75rem;
}
.auth .brand { font-size: 1.8rem; text-align: center; }
.tagline { text-align: center; color: var(--muted); margin-top: 0; }
.tabs { display: flex; gap: .5rem; margin: 1rem 0; }
.tab { flex: 1; min-height: 44px; padding: .55rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); }
.tab.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 50; max-width: 90vw; font-size: .9rem;
}
.toast.err { background: var(--neg); color: #fff; }
/* Leer = nichts zu melden. Die Region bleibt im Dokument, damit ein
   Screenreader die Aenderung mitbekommt. */
.toast:empty { display: none; }

/* ---------- Utilities (CSP verbietet Inline-Styles) ---------- */
.mt { margin-top: .8rem; }
.my { margin: .6rem 0; }
.py-sm { padding: .5rem 0; }

/* ---------- Settings ---------- */
.hint { color: var(--muted); font-size: .85rem; margin: .3rem 0; }
.secret {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .95rem; letter-spacing: .05em; word-break: break-all; user-select: all;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .6rem .7rem; margin: .4rem 0;
}

.hint.warn { color: var(--neg); }
/* Zwei Spalten: Zehn Codes untereinander reichten auf dem Handy über den Bildschirm. */
.recovery-codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: .2rem .8rem; }

/* ---------- Split editor ---------- */
.split-part {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end;
  padding: .6rem 0; border-bottom: 1px solid var(--border);
}
/* Jedes Feld traegt seine Beschriftung mit; auf schmalen Geraeten brechen sie
   untereinander statt sich auf 24 px zusammenzuquetschen. */
.split-feld { display: flex; flex-direction: column; gap: .2rem; flex: 1 1 8rem; min-width: 0; }
.split-feld label { font-size: .75rem; color: var(--muted); margin: 0; }
.split-feld select, .split-feld input { margin: 0; width: 100%; }
.split-part .p-remove { flex: 0 0 auto; min-height: 44px; min-width: 44px; }
.split-sum { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

@media (min-width: 720px) {
  .content { padding: 1.5rem; }
}

/* ---------- Ergaenzungen fuer Bedienbarkeit ---------- */
/* Datei-Eingaben liegen versteckt hinter ihrem <label>, bleiben aber fuer
   Screenreader und Tastatur erreichbar - display:none waere unbedienbar. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  /* Die 44-px-Mindesthoehe fuer Eingabefelder gilt hier NICHT: gemessen blies
     sie die versteckten Datei-Eingaben auf 44 px auf. Sichtbar waren sie
     weiterhin nicht (clip), aber ein absolut gesetzter Kasten in dieser Groesse
     kann einen Tipp abfangen. Bedient werden sie ueber ihre Beschriftung. */
  min-height: 0;
}
.visually-hidden:focus + label,
.visually-hidden:focus-visible + label { outline: 3px solid var(--primary); outline-offset: 2px; }
/* Waehrend eines Uploads: beide Wege sichtbar gesperrt (das Feld selbst ist disabled). */
.busy .visually-hidden + label { opacity: .55; cursor: progress; }
.upload-status:empty { display: none; }
.btn.block { display: block; width: 100%; text-align: center; }

/* Wegweiser fuer neue Nutzer */
.steps { margin: .25rem 0 0; padding-left: 1.25rem; color: var(--text); line-height: 1.7; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
/* Auf dem Kartengrund, nicht auf --surface-2: Dort hatte --neg im hellen Thema
   nur 4,41 (im Browser gemessen, "Archivieren" und "Beenden"); auf --surface
   4,83 hell und 6,41 dunkel. */
.btn.danger { border-color: var(--neg); color: var(--neg); background: var(--surface); }

/* Belegbild: nie breiter als die Karte, sonst laeuft die Ansicht auf dem
   Handy horizontal ueber. */
.receipt-image { display: block; max-width: 100%; height: auto; border-radius: 8px; margin-top: 8px; }
.receipt-image img { display: block; max-width: 100%; height: auto; border-radius: 8px; }
.preview-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.preview-row .btn { flex: 1 1 auto; margin-top: 0; min-width: 0; }
/* 64 px: gross genug, um einen Kassenzettel vom Tankbeleg zu unterscheiden,
   klein genug, dass auf 320 px der Knopf daneben nicht umbricht. */
.thumb { flex: 0 0 64px; width: 64px; height: 64px; border-radius: 8px; object-fit: cover;
  object-position: top; cursor: pointer; background: var(--surface-2); }
.thumb-icon { display: flex; align-items: center; justify-content: center; font-size: 1.6rem;
  cursor: default; }
.add-item-box > summary { list-style: none; cursor: pointer; }
.add-item-box > summary::-webkit-details-marker { display: none; }

/* Belegerkennung: Hinweise, Summenabgleich, Fotoausschnitt je Position. */
.hinweis { margin: .5rem 0; padding: .5rem .75rem; border-radius: 8px;
  color: #92400e; background: #fef3c7; border: 1px solid #fde68a; }
[data-theme="dark"] .hinweis { color: #fbbf24; background: #78350f33; border-color: #78350f; }
.warn-text { color: #b45309; }
[data-theme="dark"] .warn-text { color: #fbbf24; }
.ausschnitt { display: block; width: 100%; height: auto; margin: 0 0 .5rem;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.list-item .badge.unsicher { margin-top: .25rem; display: inline-block; }

/* "hidden" muss immer gewinnen. Eine Klasse mit eigenem display (.btn-group: flex,
   .icon-btn: inline-flex) hob das Attribut auf: "Passwort vergessen?" stand auch
   ohne Mailversand da (Server: 503), der Installieren-Knopf ohne Funktion. */
[hidden] { display: none !important; }
