:root,
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121418;
    --surface: #1b1e24;
    --surface-2: #242830;
    --border: #2e333d;
    --text: #eceef2;
    --muted: #949bab;
    --accent: #f6b23c;
    --accent-ink: #1a1408;
    --positive: #5ad38c;
    --negative: #ff7a73;
    --fuel: #f6b23c;
    --trip: #4fd1c5;
    --expense: #b794f6;
    --transfer: #63b3ed;
    --shadow: 0 1px 0 rgb(255 255 255 / 0.03) inset, 0 8px 24px rgb(0 0 0 / 0.25);
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f2ee;
    --surface: #ffffff;
    --surface-2: #f0ede7;
    --border: #e2ddd4;
    --text: #1d1f24;
    --muted: #6b7180;
    --accent: #d9901a;
    --accent-ink: #ffffff;
    --positive: #1f9d55;
    --negative: #d64545;
    --fuel: #c97d0c;
    --trip: #1f9c90;
    --expense: #7c56c9;
    --transfer: #2b7bc0;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 8px 24px rgb(0 0 0 / 0.06);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font:
        16px/1.5 system-ui,
        -apple-system,
        "Segoe UI",
        Roboto,
        sans-serif;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

a {
    color: inherit;
}

h1 {
    font-size: 1.6rem;
    line-height: 1.2;
    margin: 0.5rem 0 1rem;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.05rem;
    margin: 0;
}

small {
    color: var(--muted);
    font-weight: 400;
}

.icon {
    width: 1.25em;
    height: 1.25em;
    flex: none;
}

.icon-sm {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
}

.muted {
    color: var(--muted);
}

/* --- layout --------------------------------------------------------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: calc(0.75rem + env(safe-area-inset-top)) 1rem 0.75rem;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.04em;
    text-decoration: none;
    color: var(--accent);
    min-width: 0;
}

.brand-car {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.9rem;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.me-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.8rem 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.me-chip .icon {
    width: 1rem;
    height: 1rem;
    color: var(--muted);
}

.page {
    max-width: 34rem;
    margin: 0 auto;
    padding: 0.5rem 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.page > h1 {
    margin-bottom: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.card > h2 {
    margin-bottom: 0.75rem;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.section-head a {
    color: var(--muted);
    font-size: 0.875rem;
    text-decoration: none;
}

.footer {
    text-align: center;
    padding: 0 1rem 1.5rem;
}

.link-button {
    background: none;
    border: 0;
    color: var(--muted);
    font: inherit;
    font-size: 0.8rem;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    padding: 0.5rem;
}

/* --- hero ----------------------------------------------------------------------------------------------------- */

.hero {
    text-align: center;
    padding: 1.75rem 1.25rem;
    background:
        radial-gradient(120% 120% at 50% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
        var(--surface);
}

.hero + .hero {
    margin-top: 0;
}

.hero-label {
    margin: 0;
    color: var(--muted);
    font-weight: 600;
}

.hero-amount {
    margin: 0.25rem 0 1rem;
    font-size: clamp(2.5rem, 12vw, 3.5rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.1;
}

.hero-amount:last-child,
.hero-zero {
    margin-bottom: 0;
}

.hero-zero {
    color: var(--positive);
}

.hero-plain h1 {
    color: var(--accent);
    font-size: 2.5rem;
    margin: 0;
}

/* --- buttons -------------------------------------------------------------------------------------------------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 3rem;
    padding: 0.75rem 1.25rem;
    border-radius: 0.9rem;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition:
        transform 0.08s ease,
        filter 0.15s ease;
}

.button:active {
    transform: scale(0.98);
}

.button-primary {
    width: 100%;
    background: var(--accent);
    color: var(--accent-ink);
}

.button-primary:hover {
    filter: brightness(1.05);
}

.button-ghost {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

.button-danger {
    width: 100%;
    background: transparent;
    border-color: color-mix(in srgb, var(--negative) 40%, transparent);
    color: var(--negative);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.stack .button {
    width: 100%;
    font-size: 1.1rem;
}

/* --- quick actions -------------------------------------------------------------------------------------------- */

.actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.action {
    --c: var(--accent);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 1rem;
    border-radius: 1.1rem;
    border: 1px solid var(--border);
    background: linear-gradient(160deg, color-mix(in srgb, var(--c) 14%, var(--surface)), var(--surface) 70%);
    font-weight: 700;
    text-decoration: none;
    transition: transform 0.08s ease;
}

.action:active {
    transform: scale(0.97);
}

.action .icon {
    width: 1.75rem;
    height: 1.75rem;
    color: var(--c);
}

.action-tanken,
.entry-tanken {
    --c: var(--fuel);
}

.action-fahrt,
.entry-fahrt {
    --c: var(--trip);
}

.action-ausgabe,
.entry-ausgabe {
    --c: var(--expense);
}

.action-ausgleich,
.entry-ausgleich {
    --c: var(--transfer);
}

.notice {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    text-decoration: none;
    font-size: 0.9rem;
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.notice .icon {
    color: var(--accent);
}

/* --- stats ---------------------------------------------------------------------------------------------------- */

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.stat {
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    border-radius: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    min-width: 0;
}

.stat-value {
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--muted);
}

/* --- entries -------------------------------------------------------------------------------------------------- */

.entries {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    overflow: hidden;
}

.entries li + li {
    border-top: 1px solid var(--border);
}

.entry {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.8rem 1rem;
    text-decoration: none;
}

.entry:hover {
    background: var(--surface-2);
}

.entry-icon {
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    flex: none;
    border-radius: 0.8rem;
    color: var(--c);
    background: color-mix(in srgb, var(--c) 15%, transparent);
}

.entry-icon .icon {
    width: 1.2rem;
    height: 1.2rem;
}

.entry-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.entry-title {
    font-weight: 600;
}

.entry-detail {
    color: var(--muted);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entry-value {
    font-weight: 700;
    white-space: nowrap;
}

.entry-fahrt .entry-value {
    color: var(--trip);
}

.entry-ausgleich .entry-value {
    color: var(--transfer);
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 1.5rem 1rem;
}

.month {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin: 0 0 0.5rem 0.25rem;
}

.filters {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -1rem;
    padding: 0 1rem;
}

.filters a {
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.filters a[aria-current] {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}

/* --- forms ---------------------------------------------------------------------------------------------------- */

.form-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-head h1 {
    margin: 0;
}

.back {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    margin-left: -0.5rem;
    border-radius: 999px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
}

.optional {
    font-weight: 400;
    opacity: 0.7;
}

.field input:not([type="radio"]),
.field select {
    width: 100%;
    min-height: 3rem;
    padding: 0.7rem 0.9rem;
    border-radius: 0.8rem;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 1.05rem; /* >= 16px keeps iOS from zooming */
    appearance: none;
}

.field input[type="date"] {
    display: block;
}

.field-amount input {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.has-error input {
    border-color: var(--negative);
}

.help {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.error {
    margin: 0;
    font-size: 0.85rem;
    color: var(--negative);
    font-weight: 600;
}

.pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.pill {
    position: relative;
}

.pill input {
    position: absolute;
    opacity: 0;
    inset: 0;
    margin: 0;
    cursor: pointer;
}

.pill span {
    display: inline-flex;
    align-items: center;
    min-height: 2.6rem;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-weight: 600;
    transition:
        background 0.12s ease,
        color 0.12s ease;
}

.pill input:checked + span {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.pill input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.meta {
    margin: -0.5rem 0 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--muted);
}

/* --- settlement ----------------------------------------------------------------------------------------------- */

.account-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.account-head h2 {
    font-size: 1.25rem;
}

.balance {
    font-size: 1.25rem;
    font-weight: 800;
}

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

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

.rows {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.45rem 0;
    margin: 0;
    font-size: 0.92rem;
}

.rows dt {
    color: var(--muted);
}

.rows dt small {
    display: block;
    font-size: 0.75rem;
}

.rows dd {
    margin: 0;
    padding-left: 1rem;
    text-align: right;
    font-weight: 600;
    white-space: nowrap;
}

.rows-sep {
    border-top: 1px solid var(--border);
    padding-top: 0.45rem;
}

.card .help {
    margin-top: 0.75rem;
}

.refunds {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.refunds li {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
}

.refund-title {
    font-weight: 600;
}

.refund-math {
    color: var(--muted);
}

.refund-math strong {
    color: var(--positive);
}

.rules ul {
    margin: 0;
    padding-left: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.rules strong {
    color: var(--text);
}

/* --- toasts & tab bar ----------------------------------------------------------------------------------------- */

.toasts {
    position: fixed;
    left: 50%;
    top: calc(4rem + env(safe-area-inset-top));
    z-index: 20;
    transform: translateX(-50%);
    width: min(32rem, calc(100% - 2rem));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 0.9rem;
    background: var(--text);
    color: var(--bg);
    font-weight: 600;
    box-shadow: var(--shadow);
    animation: toast 3.2s ease forwards;
}

.toast .icon {
    color: var(--positive);
}

@keyframes toast {
    0% {
        opacity: 0;
        transform: translateY(-0.5rem);
    }
    8%,
    80% {
        opacity: 1;
        transform: none;
    }
    100% {
        opacity: 0;
        transform: translateY(-0.5rem);
    }
}

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.4rem 0.5rem calc(0.4rem + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
}

.tabbar a {
    flex: 1;
    max-width: 9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.35rem;
    border-radius: 0.8rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
}

.tabbar .icon {
    width: 1.4rem;
    height: 1.4rem;
}

.tabbar a[aria-current="page"] {
    color: var(--accent);
}

@media (min-width: 40rem) {
    .actions {
        grid-template-columns: repeat(4, 1fr);
    }
}

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