:root {
    --bg: #f7f8f4;
    --bg-elevated: rgba(255, 255, 255, 0.78);
    --text: #0f1f24;
    --text-muted: #4d646b;
    --accent: #0e8d8a;
    --accent-strong: #0a6a67;
    --danger: #d2514f;
    --income: #1f8f63;
    --expense: #c24b45;
    --border: rgba(15, 31, 36, 0.1);
    --shadow: 0 14px 36px rgba(10, 20, 24, 0.16);
    --radius-lg: 22px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --nav-height: 72px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d161b;
        --bg-elevated: rgba(23, 34, 40, 0.86);
        --text: #edf3f5;
        --text-muted: #97aab0;
        --accent: #53c3bd;
        --accent-strong: #7ad8d2;
        --danger: #f07f7c;
        --income: #61d79d;
        --expense: #ff8f83;
        --border: rgba(237, 243, 245, 0.12);
        --shadow: 0 18px 42px rgba(0, 0, 0, 0.42);
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: "Avenir Next", "Trebuchet MS", "Gill Sans", sans-serif;
    background: radial-gradient(circle at 0% 0%, #fefcf7, transparent 40%), var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

.bg-orb {
    position: fixed;
    z-index: -1;
    border-radius: 999px;
    filter: blur(2px);
    opacity: 0.45;
    animation: drift 8s ease-in-out infinite;
}

.bg-orb-1 {
    width: 280px;
    height: 280px;
    background: linear-gradient(130deg, #ffe5a5, #ffcdb7);
    top: -120px;
    right: -90px;
}

.bg-orb-2 {
    width: 240px;
    height: 240px;
    background: linear-gradient(140deg, #86d4d0, #c9efe6);
    left: -110px;
    bottom: 120px;
    animation-delay: 1.5s;
}

@media (prefers-color-scheme: dark) {
    .bg-orb-1 {
        background: linear-gradient(130deg, #214a5b, #2f3446);
    }

    .bg-orb-2 {
        background: linear-gradient(140deg, #1f454c, #2b3b30);
    }
}

@keyframes drift {
    0%,
    100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-10px) scale(1.03);
    }
}

.page-shell {
    max-width: 780px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 28px);
}

.auth-card {
    margin: 10vh auto 0;
    padding: 22px;
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    max-width: 460px;
    animation: rise 0.32s ease-out;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 18px;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-stack.compact {
    gap: 8px;
}

.field-label {
    font-size: 13px;
    color: var(--text-muted);
}

input,
select,
button {
    font: inherit;
}

input,
select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.75);
    color: var(--text);
    padding: 12px;
}

@media (prefers-color-scheme: dark) {
    input,
    select {
        background: rgba(11, 19, 23, 0.82);
    }
}

input:focus,
select:focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
    border-color: var(--accent);
}

button {
    border: 0;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    min-height: 46px;
}

.btn-primary {
    background: linear-gradient(140deg, var(--accent), var(--accent-strong));
    color: #fff;
    font-weight: 700;
}

.btn-secondary {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    color: var(--text);
    font-weight: 650;
}

.btn-tertiary {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
}

.switch-link {
    margin-top: 14px;
    color: var(--text-muted);
}

.switch-link a {
    color: var(--accent-strong);
    font-weight: 700;
}

.error-text {
    color: var(--danger);
    min-height: 20px;
    margin: 2px 0;
}

.app-shell {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.top-bar {
    padding: 8px 2px;
}

.view-section {
    display: none;
}

.view-section.active {
    display: block;
    animation: rise 0.25s ease-out;
}

.panel {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    padding: 14px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.panel-head input[type="month"] {
    width: auto;
    max-width: 150px;
    padding: 8px 10px;
}

.list-stack,
.mini-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.list-item,
.mini-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.42);
}

@media (prefers-color-scheme: dark) {
    .list-item,
    .mini-item {
        background: rgba(0, 0, 0, 0.22);
    }
}

.list-item-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.tx-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.tx-action-btn {
    min-height: auto;
    padding: 6px 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    border-radius: 8px;
}

.tx-action-btn.danger {
    color: var(--expense);
    border-color: color-mix(in srgb, var(--expense) 55%, var(--border));
}

.meta {
    font-size: 12px;
    color: var(--text-muted);
}

.amount {
    font-weight: 800;
}

.amount.income {
    color: var(--income);
}

.amount.expense {
    color: var(--expense);
}

.totals-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.stat-card {
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.stat-card.income {
    background: color-mix(in srgb, var(--income) 10%, transparent);
}

.stat-card.expense {
    background: color-mix(in srgb, var(--expense) 10%, transparent);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.stat-value {
    font-size: 20px;
    font-weight: 800;
    margin: 0 0 8px;
}

.mini-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.mini-item button {
    background: transparent;
    color: inherit;
    border: none;
    padding: 0;
    min-height: auto;
    text-align: left;
    width: 100%;
}

.profile-email {
    font-size: 18px;
    font-weight: 650;
    margin-bottom: 16px;
}

.bottom-nav {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom) + 8px);
    width: min(760px, calc(100vw - 18px));
    height: var(--nav-height);
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    z-index: 30;
}

.nav-btn {
    background: transparent;
    color: var(--text-muted);
    font-weight: 700;
    border-radius: 12px;
}

.nav-btn.active {
    color: var(--text);
    background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.nav-btn.nav-add {
    font-size: 24px;
    line-height: 1;
}

.fab {
    position: fixed;
    right: 18px;
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 14px);
    width: 62px;
    height: 62px;
    border-radius: 50%;
    font-size: 34px;
    font-weight: 500;
    background: linear-gradient(160deg, #f07a5f, #e16b49);
    color: white;
    z-index: 35;
    box-shadow: 0 16px 28px rgba(145, 62, 45, 0.35);
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 12px;
    background: rgba(10, 16, 19, 0.45);
    z-index: 50;
}

.modal-card {
    width: min(760px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--bg);
    padding: 14px;
    animation: rise 0.2s ease-out;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    background: transparent;
    color: var(--text-muted);
    min-height: auto;
    padding: 6px;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.seg {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.seg.active {
    color: var(--text);
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.hidden {
    display: none !important;
}

@keyframes rise {
    from {
        transform: translateY(8px);
        opacity: 0.6;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@media (min-width: 800px) {
    .totals-grid {
        grid-template-columns: 1fr 1fr;
    }

    .modal {
        align-items: center;
    }

    .modal-card {
        border-radius: 22px;
    }
}
