:root {
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --darkorange: darkorange;
    --green: #16a34a;
    --red: #dc2626;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
}

* { box-sizing: border-box; }

/* Das hidden-Attribut muss immer gewinnen – sonst überschreiben
   display:flex / display:block (z. B. bei .dialog-backdrop, .view)
   das Verstecken und Elemente bleiben sichtbar. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: transparent;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Bildschirmfüllender, fixierter Hintergrund */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    background: url("melchsee.png") center center / cover no-repeat fixed;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(env(safe-area-inset-top) + 14px) 18px 14px;
    background: var(--blue);
    color: #fff;
    box-shadow: var(--shadow);
}

.app-header h1 {
    margin: 0;
    font-size: 1.3rem;
    letter-spacing: .5px;
}

.icon-btn {
    background: rgba(255, 255, 255, .18);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex: 0 0 auto;
}
.icon-btn:active { background: rgba(255, 255, 255, .32); }

main {
    max-width: 620px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}

.view { display: block; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card h2 { margin: 0 0 4px; font-size: 1.15rem; }

/* Akkordion (Start-Screen) */
.accordion { padding: 0; overflow: hidden; }
.accordion > summary {
    list-style: none;
    cursor: pointer;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}
.accordion > summary::-webkit-details-marker { display: none; }
.accordion > summary h2 { margin: 0; }
.accordion > summary::after {
    content: '';
    width: 9px;
    height: 9px;
    margin-right: 4px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform .2s ease;
    flex: 0 0 auto;
}
.accordion[open] > summary::after { transform: rotate(-135deg); }
.accordion .accordion-body { padding: 0 20px 20px; }

h3 { font-size: 1rem; margin: 20px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }

label {
    display: block;
    margin: 14px 0 0;
    font-size: .9rem;
    font-weight: 600;
    color: #334155;
}

input, select {
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font-weight: 400;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    padding: 12px 18px;
    transition: background .15s, transform .05s;
}
button:active { transform: scale(.98); }

.primary { background: var(--blue); color: #fff; margin-top: 16px; }
.primary:hover { background: var(--blue-dark); }
.primary.full { width: 100%; margin-bottom: 16px; background: var(--darkorange); color: #fff; }

.secondary { background: #e2e8f0; color: #334155; }
.secondary:hover { background: #cbd5e1; }

.link-btn {
    background: none;
    color: var(--blue);
    padding: 2px 6px;
    font-size: .85rem;
    font-weight: 600;
}
.link-btn.danger { color: var(--red); }

/* Gruppen-Banner */
.group-banner {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.group-name { font-size: 1.25rem; font-weight: 700; }
.group-code { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.group-code strong { color: var(--text); letter-spacing: 1px; }

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    background: #e2e8f0;
    padding: 4px;
    border-radius: 12px;
    margin-bottom: 16px;
}
.tab {
    flex: 1;
    background: transparent;
    color: var(--muted);
    padding: 10px;
    font-size: .92rem;
}
.tab.active {
    background: #fff;
    color: var(--blue);
    box-shadow: var(--shadow);
}

/* Listen */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
    background: var(--card);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.item-main { min-width: 0; flex: 1; }
.item-title { font-weight: 600; }
.item-sub { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.item-amount {
    font-weight: 700;
    white-space: nowrap;
    text-align: right;
    min-width: 78px;
    flex: 0 0 auto;
}

.del-btn {
    background: none;
    color: #000;
    font-size: 1.1rem;
    padding: 4px 8px;
    flex: 0 0 auto;
    width: 34px;
    text-align: center;
}

/* Beleg-Button / Platzhalter mit fester Breite für die Spaltenausrichtung */
.receipt-btn {
    flex: 0 0 auto;
    width: 30px;
    text-align: center;
    background: none;
    border: none;
    padding: 4px 0;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    color: #000;
}
.receipt-btn.placeholder { cursor: default; }

/* Bearbeiten-Button mit fester Breite für die Spaltenausrichtung */
.edit-btn {
    flex: 0 0 auto;
    width: 30px;
    text-align: center;
    background: none;
    border: none;
    padding: 4px 0;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    color: #000;
}
.edit-btn.placeholder { cursor: default; }

.inline-form { display: flex; gap: 8px; margin-bottom: 14px; }
.inline-form input, .inline-form select { margin-top: 0; }
.inline-form button { margin: 0; white-space: nowrap; }

/* Mitglied hinzufügen: Blöcke */
.member-add { margin-bottom: 12px; }
.member-add > label { margin: 0 0 6px; }

/* Badge für verknüpfte Benutzerkonten */
.badge {
    display: inline-block;
    font-size: .68rem;
    font-weight: 700;
    color: var(--blue);
    background: #dbeafe;
    padding: 1px 7px;
    border-radius: 10px;
    vertical-align: middle;
    margin-left: 4px;
}

/* Salden-Farben */
.pos { color: var(--green); font-weight: 700; }
.neg { color: var(--red); font-weight: 700; }

/* Begrüßung + klickbare Gruppen-Einträge */
.greeting { font-size: 1.05rem; font-weight: 600; margin: 4px 4px 12px; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.list li.clickable { cursor: pointer; }
.list li.clickable:active { background: #f8fafc; }
.chevron { color: var(--muted); font-size: 1.4rem; font-weight: 700; }

/* Auth-Tabs etwas Abstand nach unten */
.auth-tabs { margin-bottom: 4px; }

/* Dialog */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 50;
}
.dialog {
    background: #fff;
    width: 100%;
    max-width: 620px;
    border-radius: 18px 18px 0 0;
    padding: 22px 20px calc(env(safe-area-inset-bottom) + 22px);
    max-height: 92vh;
    overflow-y: auto;
    animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.dialog h2 { margin: 0 0 8px; }

/* Beleg-Scan */
.scan-btn { margin-top: 4px; margin-bottom: 4px; }
.photo-actions {
    display: flex;
    gap: 8px;
    margin: 4px 0;
}
.photo-actions .scan-btn { flex: 1; }
.scan-status {
    font-size: .85rem;
    padding: 8px 12px;
    border-radius: 10px;
    background: #eff6ff;
    color: #1e40af;
    margin: 8px 0 4px;
}
.scan-status.error { background: #fef2f2; color: var(--red); }

/* Beleg-Vorschau im Dialog */
.photo-preview {
    display: block;
    max-width: 100%;
    max-height: 220px;
    margin: 8px auto 4px;
    border-radius: 12px;
    border: 1px solid var(--border, #e2e8f0);
    object-fit: contain;
}

/* Beleg-Anzeige (Lightbox) */
.receipt-viewer {
    align-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, .85);
    cursor: zoom-out;
}
.receipt-viewer img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}

fieldset {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin: 16px 0 0;
    padding: 10px 14px 14px;
}
legend { font-size: .85rem; font-weight: 600; color: #334155; padding: 0 6px; }
.participants-header { display: flex; gap: 6px; justify-content: flex-end; }

.participants { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.chk {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    font-weight: 400;
    margin: 0;
    cursor: pointer;
}
.chk input { width: auto; margin: 0; }

.dialog-actions { display: flex; gap: 10px; margin-top: 20px; }
.dialog-actions button { flex: 1; margin: 0; }

/* Toast */
.toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom) + 20px);
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #fff;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: .9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
    z-index: 100;
    max-width: 90%;
    text-align: center;
}
.toast.error { background: var(--red); }
