@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Hanken+Grotesk:wght@400;500;600;700&display=swap');

:root {
    /* Editorial / warm: Papier-Hintergrund, Tinte, EIN Terracotta-Akzent. Flach, kein Glow. */
    --bg-main: #F5F1EA;       /* Papier */
    --bg-card: #FFFFFF;
    --bg-card-hover: #FBF7F0;
    --text-main: #292524;      /* warme Tinte */
    --text-muted: #78716C;
    --primary: #C2562F;        /* Terracotta */
    --primary-hover: #A8431F;
    --primary-tint: rgba(194, 86, 47, 0.10);
    --positive: #2F7D5B;       /* gedämpftes Grün (bekommt Geld) */
    --negative: #C0392B;       /* gedämpftes Rot (schuldet) */
    --accent-edit: #4F6D7A;    /* ruhiges Blaugrau für „Bearbeiten" */
    --border: #E7E1D6;         /* warme Haarlinie */
    --glass-blur: none;        /* kein Glassmorphism mehr */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    /* Aliase: im Code wurden --bg/--surface/--radius-sm benutzt, waren aber nie definiert
       (führte zu transparenten Beleg-Posten-Zeilen u. ä.). Verweisen themefähig auf die echten Tokens. */
    --bg: var(--bg-main);
    --surface: var(--bg-card);
    --card-shadow: 0 1px 2px rgba(41, 37, 36, 0.05);
    --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
    --font-body: 'Hanken Grotesk', system-ui, sans-serif;
    --select-arrow: url("data:image/svg+xml;utf8,<svg fill='%23292524' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
}

[data-theme="dark"] {
    --bg-main: #1C1917;        /* warmes Dunkel */
    --bg-card: #292524;
    --bg-card-hover: #44403C;
    --text-main: #F5F1EA;
    --text-muted: #A8A29E;
    --primary: #E0795E;        /* helleres Terracotta für Kontrast */
    --primary-hover: #EC8E74;
    --primary-tint: rgba(224, 121, 94, 0.14);
    --positive: #4FB286;
    --negative: #E07A6A;
    --accent-edit: #7FA0B0;
    --border: rgba(245, 241, 234, 0.12);
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    --select-arrow: url("data:image/svg+xml;utf8,<svg fill='%23F5F1EA' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-main: #1C1917;
        --bg-card: #292524;
        --bg-card-hover: #44403C;
        --text-main: #F5F1EA;
        --text-muted: #A8A29E;
        --primary: #E0795E;
        --primary-hover: #EC8E74;
        --primary-tint: rgba(224, 121, 94, 0.14);
        --positive: #4FB286;
        --negative: #E07A6A;
        --accent-edit: #7FA0B0;
        --border: rgba(245, 241, 234, 0.12);
        --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
        --select-arrow: url("data:image/svg+xml;utf8,<svg fill='%23F5F1EA' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    padding-bottom: 90px; /* Space for FAB */
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-text-size-adjust: 100%; /* iOS skaliert Text nicht eigenmächtig */
}

/* --- Touch-Optimierung (Smartphone) --- */
button, .nav-item, .dashboard-group-item, .receipt-mini, .btn-member-avatar, .avatar, .split-type-btn {
    -webkit-tap-highlight-color: transparent; /* kein grauer Flash beim Tippen */
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation; /* kein 300ms-Verzögern, kein Doppeltipp-Zoom auf Buttons */
}

/* Spürbares Tipp-Feedback (Hover gibt's auf dem Handy nicht) */
.btn:active, .btn-action:active, .split-type-btn:active, .btn-settle:active,
.btn-small-action:active, .nav-item:active, .dashboard-group-item:active,
.modal-close:active, .avatar:active, .btn-member-avatar:active, .receipt-mini:active {
    transform: scale(0.95);
    opacity: 0.85;
}

.fab:active {
    transform: scale(0.92);
}

header {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    /* Safe-Area: nicht unter die Statusleiste/Notch im installierten PWA-Modus rutschen */
    padding: calc(1rem + env(safe-area-inset-top)) 1.5rem 1rem 1.5rem;
    /* Auf breiten Screens auf dieselbe zentrierte Spalte wie <main> begrenzen,
       damit Marke/Aktionen mit dem Inhalt fluchten (statt am Bildschirmrand zu kleben). */
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Obere Zeile: Marke (links) + Gruppen-Aktionen (rechts), umbruchfähig. */
.header-top {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: space-between;
    align-items: center;
}
.header-brand { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
#group-actions { display: flex; align-items: center; gap: 0.4rem; }

/* Gruppen-Banner: Cover-Bild + antippbarer Name + 📷 (nur im Gruppen-Tab sichtbar). */
#group-banner {
    position: relative;
    min-height: 120px;
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    padding: 0.6rem 0.85rem;
    background-size: cover;
    background-position: center;
    background-color: var(--bg-main);
}
#group-banner #group-selector-select {
    position: relative;
    z-index: 1;
    background-color: transparent;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    font-weight: 800;
    padding: 0 1.4rem 0 0;
    max-width: 100%;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
    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='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right center;
    background-size: 12px;
}
#group-banner #btn-group-image {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 2;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.45);
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-md);
}

/* Der Banner liegt im Inhaltsfluss (in <main>, NICHT im sticky Header) und scrollt
   natürlich aus dem Bild. Das frühere Schrumpfen per header.banner-compact änderte
   die Headerhöhe mitten im Scrollen → Inhalte sprangen/flackerten (entfernt;
   Abstände kommen vom column-gap des <main>). */

h1 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-main);
}

main {
    padding: 1.5rem;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

h2 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
    color: var(--text-main);
}

h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: background 0.3s ease, box-shadow 0.3s ease;
    box-shadow: var(--card-shadow);
}


.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

input, select, textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-tint);
}

.btn {
    display: inline-block;
    width: 100%;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary-tint);
}

.btn-danger {
    background: var(--negative);
    color: white;
}

.btn-danger:hover {
    background: #A93226;
}

/* Live-Vorschau der Aufteilung */
.split-summary {
    margin-bottom: 1rem;
}

.split-summary:empty {
    display: none;
}

.split-summary-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
    color: var(--text-muted);
    padding: 0.2rem 0;
}

.split-summary-row span:last-child {
    font-weight: 600;
    color: var(--text-main);
}

.split-summary-status {
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px dashed var(--border);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--positive);
}

.split-summary.warn .split-summary-status {
    color: #FBBF24;
}

.expense-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 0.25rem;
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
}

.expense-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.expense-icon {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    line-height: 1;
}

.expense-icon-settle {
    background: rgba(47, 125, 91, 0.1);
    border-color: rgba(47, 125, 91, 0.25);
}

.expense-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.expense-desc {
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.expense-meta {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}

.expense-meta-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.expense-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.45rem;
    flex-shrink: 0;
}

.expense-amount {
    font-weight: 700;
    font-size: 1.0625rem;
    color: var(--text-main);
    text-align: right;
    white-space: nowrap;
}

.expense-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* Wisch-Gesten: links = löschen (rot), rechts = bearbeiten (blau) */
.swipe-row {
    position: relative;
    overflow: hidden;
    /* content-visibility entfernt, da es beim Scrollen (besonders mit Bildern)
       zu starkem Flackern führte, wenn Zeilen dynamisch gerendert wurden. */
}

.swipe-bg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    padding: 0 1.4rem;
    background: transparent;
}

.swipe-bg-delete {
    background: var(--negative);
    justify-content: flex-end;
}

.swipe-bg-edit {
    background: var(--accent-edit);
    justify-content: flex-start;
}

.swipe-icon {
    font-size: 1.4rem;
    transition: transform 0.12s ease;
}

.swipe-bg.pass .swipe-icon {
    transform: scale(1.4);
}

.swipe-fg {
    position: relative;
    background: var(--bg-card);
    /* KEIN will-change hier: das erzwingt pro Listenzeile eine eigene
       Compositor-Ebene — bei langen Listen flackern/weißen Flächen beim
       Scrollen auf Mobilgeräten. Der Swipe-transform ist auch ohne flüssig. */
    touch-action: pan-y;
}

.btn-action {
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.35rem;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.btn-action-edit {
    color: var(--accent-edit);
}

.btn-action-edit:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-edit);
}

.btn-action-delete {
    color: var(--negative);
}

.btn-action-delete:hover {
    background: rgba(192, 57, 43, 0.12);
    border-color: rgba(192, 57, 43, 0.35);
}

.balance-item, .debt-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

/* Namensbereich darf schrumpfen, damit der Betrag nie überlappt. */
.balance-item .name-with-avatar {
    flex: 1;
    min-width: 0;
}

.balance-item:last-child, .debt-item:last-child {
    border-bottom: none;
}

/* „Wer zahlt an wen": Zahler oben, Pfeil, Empfänger unten (gestapelt) */
.debt-flow {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1;
    min-width: 0;
}

.debt-flow .name-with-avatar {
    min-width: 0;
}

.debt-flow .name-with-avatar strong {
    /* Lange Namen umbrechen statt abschneiden (kein Ellipsis mehr). */
    white-space: normal;
    overflow-wrap: anywhere;
}

.debt-arrow {
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    padding-left: 7px; /* unter den Avatar einrücken */
}

/* Schuldenzeile gestapelt: oben „Zahler ↓ Empfänger" (volle Breite), darunter Betrag + Aktionen. */
.debt-item {
    flex-direction: column;
    align-items: stretch;
}
.debt-right {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
    white-space: nowrap;
    margin-top: 0.25rem;
}

.btn-settle {
    background: rgba(47, 125, 91, 0.10);
    color: var(--positive);
    border: 1px solid rgba(47, 125, 91, 0.30);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.55rem 0.8rem;
    min-height: 40px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

.btn-settle:hover {
    background: rgba(47, 125, 91, 0.18);
}


.split-member-toggle {
    padding: 0.35rem 0;
}

.balance-positive {
    color: var(--positive);
    font-weight: 600;
}

.balance-negative {
    color: var(--negative);
    font-weight: 600;
}

.balance-neutral {
    color: var(--text-muted);
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Kräftig abdunkeln: auf Geräten ohne backdrop-filter-Unterstützung bleibt
       sonst der Seiteninhalt deutlich sichtbar („Hintergrund scheint durch"). */
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: flex-start; /* flex-start + margin: auto im Child erlaubt perfektes Scrollen ohne Abschneiden */
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    /* Das Overlay selbst ist scrollbar, falls der Inhalt höher als der Bildschirm ist. */
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Hintergrund (Haupt-App) sperren, solange ein Modal offen ist. */
body:has(.modal-overlay.active) {
    overflow: hidden;
}

.modal-content {
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    width: 100%;
    max-width: 400px;
    /* Keine fixen max-heights mehr! Wenn das Modal höher ist als der Bildschirm,
       wächst es natürlich mit und das .modal-overlay übernimmt das Scrollen. */
    /* margin: auto zentriert kurze Modals vertikal, während hohe Modals dank
       align-items: flex-start oben anfangen und unten nicht abgeschnitten werden. */
    margin: auto;
    /* Lange, nicht umbrechbare Strings (E-Mails, IBANs, PayPal-Links) umbrechen statt überlaufen.
       Bewusst NICHT word-break/anywhere auf dem ganzen Dialog: das bricht sonst Button-Labels
       mitten im Wort um („Kame ra"). break-word greift nur, wenn ein Wort allein zu lang ist. */
    overflow-wrap: break-word;
    transform: translateY(20px);
    transition: transform 0.3s ease;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

/* Primär-Aktion im (scrollbaren) Ausgaben-Dialog immer sichtbar am unteren Rand anheften. */
#btn-submit-expense {
    margin-top: 1rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    /* Komfortable Tipp-Fläche */
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: -0.5rem -0.5rem -0.5rem 0; /* optischer Ausgleich, ohne Layout zu sprengen */
    flex-shrink: 0;
}

.split-type-selector {
    display: flex;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    margin-bottom: 1rem;
}

.split-type-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.7rem 0.5rem;
    min-height: 44px;
    border-radius: calc(var(--radius-md) - 2px);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.split-type-btn.active {
    background: var(--bg-card);
    color: var(--text-main);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.split-members-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.split-member-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.split-member-name {
    flex: 1;
    min-width: 0;            /* erlaubt das Schrumpfen im Flex-Container */
    font-size: 0.875rem;
    white-space: nowrap;     /* kein zeichenweiser Umbruch langer Namen */
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Beide Betragsfelder (Aufteilung UND Mehrere-Zahler) fix breit halten und NICHT schrumpfen –
   sonst quetscht das Eingabefeld die Namensspalte auf ~1 Zeichen (vertikaler Namensumbruch). */
.split-member-input,
.payer-input {
    width: 100px;
    flex-shrink: 0;
    padding: 0.5rem;
    text-align: right;
}

.fab {
    position: fixed;
    bottom: calc(32px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: 64px;
    height: 64px;
    border-radius: 32px;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    box-shadow: 0 6px 18px rgba(194, 86, 47, 0.35);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1000;
    border: 4px solid var(--bg-main);
}

.fab:hover {
    transform: translateX(-50%) scale(1.08);
}

#group-selector-select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    width: auto;
    max-width: 45vw;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    appearance: none;
    -webkit-appearance: none;
    background-image: var(--select-arrow);
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1.25rem;
    outline: none;
    transition: all 0.2s ease;
}

#group-selector-select:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
}

#group-selector-select option {
    background: var(--bg-main);
    color: var(--text-main);
    padding: 0.5rem;
}

/* --- Tab Views & Bottom Navigation --- */
.view-content {
    display: none;
}

.view-content.active {
    display: block;
}



.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    /* Auf breiten Screens mittig auf die Inhaltsspalte begrenzen (sonst stehen die
       Tabs weit auseinander, während der Inhalt zentriert ist). */
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    height: 64px;
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 999;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    gap: 0.2rem;
    outline: none;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item.active .nav-icon {
    transform: translateY(-1px);
}

.nav-icon {
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nav-icon svg { display: block; }

/* --- Kleine Nutzer-Avatare (überall in Listen) --- */
.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    line-height: 1;
    vertical-align: middle;
}

.name-with-avatar {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.btn-member-avatar {
    background: none;
    border: none;
    padding: 0;
    width: auto;
    cursor: pointer;
    display: inline-flex;
    border-radius: 50%;
    transition: transform 0.15s ease;
}

.btn-member-avatar:hover {
    transform: scale(1.08);
}

/* --- Profilbild / Avatar (Hauptnutzer, Dashboard) --- */
.avatar {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.1);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 0 0 3px var(--primary-tint);
}

.avatar.has-image .avatar-placeholder {
    display: none;
}

.avatar-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    pointer-events: none;
}

.avatar-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--negative);
    color: white;
    border: 2px solid var(--bg-main);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Unsichtbare, größere Tipp-Fläche fürs kleine ×-Symbol */
.avatar-remove::after {
    content: '';
    position: absolute;
    inset: -10px;
}

/* Bei gesetztem Bild: Entfernen-Knopf statt Kamera-Badge zeigen */
.avatar.has-image .avatar-badge {
    display: none;
}

.avatar.has-image .avatar-remove {
    display: flex;
}

/* --- Dashboard-Karten (flach, farbiger Rand statt Glow) --- */
.dashboard-card {
    background: var(--bg-card);
    transition: border-color 0.3s ease;
}

.dashboard-card.glow-green {
    border-color: rgba(47, 125, 91, 0.45);
    border-left: 3px solid var(--positive);
}

.dashboard-card.glow-red {
    border-color: rgba(192, 57, 43, 0.45);
    border-left: 3px solid var(--negative);
}

.dashboard-card.glow-neutral {
    border-color: var(--border);
}

/* --- Member Badges --- */
.member-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    padding: 0.25rem 0.6rem 0.25rem 0.3rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-main);
    transition: all 0.2s ease;
}

.member-badge:hover {
    background: var(--border);
    border-color: rgba(255, 255, 255, 0.2);
}

/* --- Dashboard Elements --- */
.dashboard-group-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1rem;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.dashboard-group-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
    transform: translateX(3px);
}

.dashboard-detail-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 1rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.dashboard-detail-item:last-child {
    border-bottom: none;
}

.dashboard-detail-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.dashboard-detail-right {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Action Buttons inside lists */
.btn-share-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.btn-small-action {
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.8125rem;
    padding: 0.5rem 0.7rem;
    min-height: 38px;
    border-radius: 8px;
    transition: all 0.2s ease;
    color: var(--text-main);
}

.btn-small-action:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
}

/* Modal Member Row */
.manage-member-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: 8px;
}

/* --- Beleg / Quittung --- */
#receipt-preview {
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.receipt-thumb {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    cursor: pointer;
}

.receipt-mini {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.receipt-mini:hover {
    transform: scale(1.08);
    border-color: var(--primary);
}

/* Lightbox (Beleg vergrößern) */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.lightbox-overlay.active {
    display: flex;
}

.lightbox-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-md);
    cursor: zoom-in;
}

.lightbox-img.zoomed {
    max-width: none;
    max-height: none;
    width: auto;
    cursor: zoom-out;
}

.lightbox-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: none;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    z-index: 2010;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Statistik --- */
.stat-row {
    margin-bottom: 0.9rem;
}

.stat-row-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
    margin-bottom: 0.4rem;
    gap: 0.5rem;
}

.stat-row-head span:last-child {
    color: var(--text-muted);
    white-space: nowrap;
}

.stat-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
}

.stat-row-head strong {
    color: var(--text-main);
}

.stat-bar {
    height: 9px;
    border-radius: 5px;
    background: rgba(148, 163, 184, 0.18);
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 5px;
    transition: width 0.4s ease;
    min-width: 4px;
}

/* Monatstrend (Säulen) */
.trend-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.5rem;
    height: 110px;
}

.trend-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.trend-bar-track {
    width: 70%;
    max-width: 34px;
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: rgba(148, 163, 184, 0.12);
    border-radius: 6px;
    overflow: hidden;
}

.trend-bar-fill {
    width: 100%;
    background: rgba(148, 163, 184, 0.5);
    border-radius: 6px;
    transition: height 0.4s ease;
}

.trend-bar-fill.current {
    background: var(--primary);
}

.trend-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

.trend-label.current {
    color: var(--text-main);
    font-weight: 700;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


.btn-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}
.btn-close:hover {
    color: var(--text-main);
}

/* --- Start-Lade-Indikator --- */
.app-loader {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: var(--bg-main);
    color: var(--text-muted);
}
.app-loader-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    animation: app-spin 0.8s linear infinite;
}
.app-loader-text {
    font-size: 0.875rem;
    letter-spacing: 0.01em;
}
@keyframes app-spin { to { transform: rotate(360deg); } }

/* --- Aktivitäts-Badge am Nav-Tab (Ersatz für Server-Push auf dem Spark-Plan) --- */
.nav-badge {
    position: absolute;
    top: -4px;
    right: -8px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--negative);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Skeleton-Platzhalter (Dashboard lädt) --- */
/* Schimmernde Balken statt „0,00 € / Alles ausgeglichen", bis die echten Daten da sind —
   sonst sieht es kurz so aus, als wären alle Salden weg. */
.skeleton {
    display: inline-block;
    height: 1em;
    max-width: 100%;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--bg-card-hover) 25%, var(--border) 50%, var(--bg-card-hover) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

/* --- Editorial-Feinschliff --- */
/* Große Beträge in der Display-Serife, Ziffern tabellarisch ausgerichtet. */
#dashboard-total-balance,
#stats-total {
    font-family: var(--font-display);
    font-feature-settings: "tnum" 1;
    letter-spacing: -0.01em;
}
.expense-amount,
.split-member-input,
.balance-item strong,
.debt-right {
    font-variant-numeric: tabular-nums;
}

/* Marke: „Split" in Tinte, Wortmarke in der Serife (im h1 schon gesetzt). */
#brand-home { font-family: var(--font-display); }

/* Buttons: ruhiger, kein Schwung-Lift im Editorial-Look. */
.btn { transition: background-color 0.18s ease, border-color 0.18s ease; }

/* --- Gast-Modus (Einladungslink, ohne Konto): nur HINZUFÜGEN erlaubt --- */
/* Ändern/Löschen/Verwalten ausblenden. FAB (Ausgabe hinzufügen) bleibt sichtbar.
   Die eigentliche Durchsetzung liegt in firestore.rules; das hier ist nur die UI. */
body.guest-mode .btn-action-edit,
body.guest-mode .btn-action-delete,
body.guest-mode .btn-edit-payment,
body.guest-mode .btn-settlement-delete,
body.guest-mode .btn-recurring-stop,
body.guest-mode #btn-manage-members,
body.guest-mode #btn-manage-budgets,
body.guest-mode #btn-share-group,
body.guest-mode #btn-edit-main-user,
body.guest-mode #main-user-subtitle,
body.guest-mode #main-user-avatar .avatar-badge,
body.guest-mode #main-user-avatar .avatar-remove {
    display: none !important;
}

body.guest-mode #main-user-avatar {
    pointer-events: none;
    cursor: default;
}
