:root {
    --bg: #0c0e0c;
    --card: #161a16;
    --card-2: #1e231e;
    --border: #262c26;
    --border-light: #333a33;
    --text: #f2f4f1;
    --text-soft: #9aa29a;
    --green: #a9e17e;
    --green-dark: #8fd160;
    --green-ink: #0f1c0a;
    --green-tint: #1c2618;
    --danger: #f0806a;
    --r-card: 22px;
    --r-field: 14px;
    --sans: "Plus Jakarta Sans", -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1.25rem 5rem;
}

a { color: var(--green); }

/* ============ App bar ============ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(12, 14, 12, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    margin-bottom: 2.5rem;
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: 960px;
    margin: 0 auto;
    padding: 0.9rem 1.25rem;
}
.brand {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.logo-mark {
    /* The torn edge and the motion marks need room; below ~26px they blur. */
    height: 1.7em;
    width: auto;
    color: var(--green);
    flex-shrink: 0;
}
.topnav { display: flex; align-items: center; gap: 0.9rem; }
.topnav .muted { font-size: 0.85rem; }
.topnav form { display: inline; }

/* ============ Typography ============ */
h1 {
    font-size: clamp(1.6rem, 4.5vw, 2.2rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin: 0.25rem 0 0.75rem;
}
.standfirst {
    font-size: 1rem;
    color: var(--text-soft);
    max-width: 36em;
    margin: 0.6rem 0 2.25rem;
}
.standfirst strong { color: var(--text); font-weight: 700; }
.eyebrow {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--green);
    background: var(--green-tint);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.8rem;
    margin: 0 0 0.9rem;
}
h2 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 1.1rem;
}
h3 {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-soft);
    margin: 1.75rem 0 0.75rem;
}
.muted { color: var(--text-soft); }
.small { font-size: 0.8rem; }

/* ============ Layout ============ */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}
.grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 1.25rem;
    align-items: start;
}
@media (max-width: 760px) {
    .grid { grid-template-columns: 1fr; }
}

/* ============ Forms ============ */
label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-soft);
}
input, select {
    width: 100%;
    padding: 0.7rem 0.95rem;
    margin-top: 0.4rem;
    border: 1px solid var(--border-light);
    border-radius: var(--r-field);
    font-size: 0.95rem;
    font-family: var(--sans);
    background: var(--card-2);
    color: var(--text);
    transition: border-color 0.15s;
}
input::placeholder { color: #6b736b; }
input:focus, select:focus {
    outline: none;
    border-color: var(--green);
}
input[type="date"] { color-scheme: dark; }
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239aa29a' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.9rem center;
    padding-right: 2.2rem;
}

.stack { display: flex; flex-direction: column; gap: 1.2rem; }
.inline-form { display: flex; gap: 0.6rem; align-items: stretch; }
.inline-form input { margin-top: 0; flex: 1; }
.form-row {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1.1rem 1rem;
    align-items: end;
}
@media (max-width: 480px) {
    .form-row { grid-template-columns: 1fr; }
}
fieldset { border: 0; padding: 0; margin: 0; }
legend {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-soft);
    padding: 0;
    margin-bottom: 0.6rem;
}

/* Participant chips */
.checkbox-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip { position: relative; display: inline-block; }
.chip input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.chip span {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.85rem 0.4rem 0.6rem;
    border: 1px solid var(--border-light);
    border-radius: 9px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-soft);
    background: transparent;
    transition: all 0.13s;
    user-select: none;
}
.chip span::before {
    content: "";
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    border: 1.5px solid var(--border-light);
    border-radius: 4px;
    background: var(--card-2) no-repeat center;
    background-size: 10px;
    transition: all 0.13s;
}
.chip input:checked + span {
    border-color: var(--green);
    background: var(--green-tint);
    color: var(--text);
    font-weight: 600;
}
.chip input:checked + span::before {
    border-color: var(--green);
    background-color: var(--green);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 6.2l2.6 2.6L10 3.4' stroke='%230f1c0a' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.chip input:hover + span { border-color: var(--green); color: var(--text); }
.chip input:focus-visible + span { outline: 2px solid var(--green); outline-offset: 2px; }

/* "Alle"/"Keine" shortcut — a text action, kept flat so it reads as neither */
.chip-all {
    padding: 0.4rem 0.7rem;
    border: 1px dashed var(--border-light);
    border-radius: 9px;
    background: transparent;
    color: var(--text-soft);
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 600;
    min-width: 3.9rem;
    cursor: pointer;
    transition: all 0.13s;
}
.chip-all:hover { border-color: var(--green); color: var(--green); }
.chip-all:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ============ Buttons ============ */
.btn {
    display: inline-block;
    padding: 0.7rem 1.5rem;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: var(--card-2);
    color: var(--text);
    font-family: var(--sans);
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.btn:hover { border-color: var(--green); color: var(--green); }
.btn-primary {
    background: var(--green);
    border-color: var(--green);
    color: var(--green-ink);
}
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); color: var(--green-ink); }
.btn-danger {
    border: none;
    background: transparent;
    color: var(--danger);
    padding: 0.4rem 0;
    font-size: 0.82rem;
    font-weight: 600;
}
.btn-danger:hover { text-decoration: underline; border: none; color: var(--danger); }
.btn-ghost {
    border: none;
    background: transparent;
    color: var(--text-soft);
    padding: 0.25rem 0.5rem;
}
.btn-ghost:hover { color: var(--danger); border: none; }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.8rem; }
.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.6rem;
    padding-top: 1.2rem;
    border-top: 1px solid var(--border);
}

/* ============ Flash + errors ============ */
.flash {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--green-tint);
    border: 1px solid var(--green);
    border-radius: var(--r-field);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.8rem 1.1rem;
    margin: 0 0 1.5rem;
}
.flash::before { content: "✓"; color: var(--green); font-weight: 800; }
.error {
    color: var(--danger);
    font-size: 0.83rem;
    margin: 0.45rem 0 0;
    padding-left: 1.1rem;
}
p.error { padding-left: 0; }

/* ============ Auth ============ */
.auth-card {
    max-width: 420px;
    margin: 2.5rem auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    padding: 2rem;
}
.auth-card h1 { text-align: center; font-size: 1.5rem; margin-bottom: 1.75rem; }
.auth-card .muted { text-align: center; margin-top: 1.75rem; font-size: 0.85rem; }
.auth-card .btn { width: 100%; margin-top: 0.25rem; }

/* ============ Group index ============ */
.group-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.9rem; }
.group-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, transform 0.15s;
}
.group-link:hover { border-color: var(--green); transform: translateY(-1px); }
.group-link strong { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.group-link .muted { font-size: 0.82rem; white-space: nowrap; }
.group-link .muted::after { content: " ›"; color: var(--green); font-weight: 800; }
.empty {
    padding: 1.25rem 0;
    color: var(--text-soft);
    font-size: 0.95rem;
}

/* ============ Page head ============ */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}
.page-head h1 { margin-bottom: 0; }
.breadcrumb { margin: 0 0 1.25rem; font-size: 0.82rem; font-weight: 600; }
.breadcrumb a { color: var(--text-soft); text-decoration: none; }
.breadcrumb a:hover { color: var(--green); }

/* ============ Avatars ============ */
.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--green-tint);
    border: 1px solid var(--border-light);
    color: var(--green);
    font-size: 0.9rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ============ Members ============ */
.member-list { list-style: none; padding: 0; margin: 0; }
.member-list li {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
}
.member-list li:last-child { border-bottom: none; }
.member-name { flex: 1; min-width: 0; font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
.member-name .muted { font-size: 0.75rem; font-weight: 500; overflow-wrap: anywhere; }

.badge {
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.badge-pos { color: var(--green); }
.badge-neg { color: var(--danger); }

/* ============ Share link ============ */
.share-row { display: flex; gap: 0.6rem; }
.share-row input { margin-top: 0; font-size: 0.78rem; color: var(--text-soft); }

/* ============ Settlement — green hero card ============ */
.settle-box {
    background: var(--green);
    border: none;
    border-radius: var(--r-card);
    padding: 1.75rem;
    margin-bottom: 1.25rem;
    color: var(--green-ink);
}
.settle-box h2 { color: var(--green-ink); margin-bottom: 0.75rem; }
.settle-empty { margin: 0.25rem 0 0; font-weight: 600; color: var(--green-ink); }
.settle-label {
    margin: 1rem 0 0.4rem;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: rgba(15, 28, 10, 0.62);
}
.settle-label:first-of-type { margin-top: 0.35rem; }

/* One settlement: a full-width button so the whole row is the hit area */
.settle-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.8rem 1rem;
    border: 1px solid rgba(15, 28, 10, 0.18);
    border-radius: var(--r-field);
    background: rgba(255, 255, 255, 0.28);
    color: var(--green-ink);
    font-family: var(--sans);
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.14s;
    /* Rows stay on one line while there is room and wrap by themselves once
       the column gets narrow, rather than breaking everywhere. */
    flex-wrap: wrap;
    row-gap: 0.4rem;
}
.settle-row:last-child { margin-bottom: 0; }
.settle-row:hover { background: rgba(255, 255, 255, 0.55); border-color: var(--green-ink); }
.settle-row:focus-visible { outline: 2px solid var(--green-ink); outline-offset: 2px; }
.settle-row strong { font-weight: 800; }
.settle-row-text { flex: 1 1 11rem; min-width: 0; }
.settle-row:has(.settle-row-cta) .settle-row-amount { margin-left: auto; }
.settle-row-amount {
    font-weight: 800;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.settle-row-cta {
    flex-shrink: 0;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--green-ink);
    color: var(--green);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

/* What I personally owe is the one thing to act on, so it carries the weight */
.settle-row-owe {
    background: var(--green-ink);
    border-color: var(--green-ink);
    color: var(--green);
    font-size: 1.05rem;
    padding: 0.95rem 1rem;
}
.settle-row-owe:hover { background: #17300e; border-color: #17300e; }
.settle-row-owe .settle-row-cta { background: var(--green); color: var(--green-ink); }

.settle-row-quiet {
    background: transparent;
    border-color: rgba(15, 28, 10, 0.16);
    color: rgba(15, 28, 10, 0.72);
    font-size: 0.87rem;
}
.settle-row-quiet:hover { background: rgba(255, 255, 255, 0.35); }

/* Payment dialog */
.payment-parties { margin: 0; font-size: 1.02rem; }
.amount-shortcuts { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-top: -0.4rem; }

/* "Du" marker on my own row in the member list */
.member-list li.is-me .member-name { color: var(--green); }
.you {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    background: var(--green-tint);
    border: 1px solid var(--green);
    color: var(--green);
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    vertical-align: middle;
}

/* ============ Expenses list ============ */
.toc { list-style: none; padding: 0; margin: 0; }
/* The whole row highlights and opens the edit dialog; only the delete
   action sits outside the button so it keeps its own hit area. */
.toc li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.75rem;
    margin: 0 -0.75rem;
    border-radius: var(--r-field);
    box-shadow: inset 0 -1px 0 var(--border);
    transition: background 0.13s, box-shadow 0.13s;
}
.toc li:hover { background: var(--card-2); box-shadow: none; }
.toc li:last-child { box-shadow: none; }

.toc-open {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    flex: 1;
    min-width: 0;
    padding: 0.8rem 0;
    border: 0;
    background: transparent;
    color: inherit;
    font-family: var(--sans);
    font-size: inherit;
    text-align: left;
    cursor: pointer;
}
.toc-open:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; border-radius: 8px; }
.toc-body { flex: 1; min-width: 0; line-height: 1.35; }
.toc-title { display: block; font-size: 0.98rem; font-weight: 700; }
.toc-byline { display: block; font-size: 0.76rem; color: var(--text-soft); }
.toc-amount {
    font-size: 0.98rem;
    font-weight: 800;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.toc-actions {
    display: flex;
    align-items: center;
    gap: 0.1rem;
    line-height: 1;
    opacity: 0.25;
    transition: opacity 0.15s;
}
.toc li:hover .toc-actions, .toc-actions:focus-within { opacity: 1; }

.toc-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem;
    margin-top: 0.9rem;
    padding: 0.9rem 1.1rem;
    background: var(--card-2);
    border-radius: var(--r-field);
    font-weight: 700;
}
.toc-total .toc-amount { color: var(--green); font-size: 1.05rem; }

/* ============ Quiet admin actions ============ */
.admin-row {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.btn-block { width: 100%; margin-bottom: 1.25rem; font-size: 1rem; padding: 0.9rem 1.5rem; }

/* ============ Dialog — centered on desktop, bottom sheet on mobile ======= */
.sheet {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border-light);
    border-radius: var(--r-card);
    padding: 1.75rem;
    width: calc(100% - 2.5rem);
    max-width: 560px;
    margin: auto;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.sheet::backdrop {
    background: rgba(5, 6, 5, 0.65);
    backdrop-filter: blur(4px);
}
.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.sheet-head h2 { margin: 0; }
.sheet-section {
    margin: 0 0 0.6rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-soft);
}

@media (max-width: 760px) {
    .sheet {
        border-bottom: none;
        border-radius: var(--r-card) var(--r-card) 0 0;
        padding: 1.5rem 1.25rem 2rem;
        width: 100%;
        max-width: none;
        margin: auto auto 0;
        box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
    }
}

@media (prefers-reduced-motion: no-preference) {
    .sheet[open] { animation: dialog-in 0.22s ease-out both; }
    @keyframes dialog-in {
        from { transform: scale(0.96); opacity: 0; }
        to { transform: none; opacity: 1; }
    }
    @media (max-width: 760px) {
        .sheet[open] { animation: sheet-up 0.28s cubic-bezier(0.32, 0.72, 0, 1) both; }
        @keyframes sheet-up {
            from { transform: translateY(40px); opacity: 0; }
            to { transform: none; opacity: 1; }
        }
    }
}

/* ============ Motion ============ */
@media (prefers-reduced-motion: no-preference) {
    main { animation: rise 0.4s ease-out both; }
    @keyframes rise {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: none; }
    }
}

:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
