:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --border: #e4e9f2;
    --primary: #111827;
    --primary-soft: #eef2ff;
    --success: #087a55;
    --success-soft: #e9f9f2;
    --danger: #c9364f;
    --danger-soft: #fff0f2;
    --warning: #b76700;
    --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    background: var(--bg);
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 8% 2%, rgba(79, 70, 229, 0.08), transparent 28%),
        radial-gradient(circle at 92% 0%, rgba(14, 165, 233, 0.08), transparent 25%),
        var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.6; }

[hidden] { display: none !important; }

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}

.brand-mark {
    display: inline-flex;
    align-items: baseline;
    letter-spacing: -0.13em;
    font-size: 25px;
    font-weight: 900;
    line-height: 1;
    transform: skew(-6deg);
}

.brand-mark span:nth-child(1) { color: #4f46e5; }
.brand-mark span:nth-child(2) { color: #0ea5e9; transform: translateY(-2px); }
.brand-mark span:nth-child(3) { color: #ec4899; }
.brand-name {
    font-size: 19px;
    font-weight: 750;
    letter-spacing: -0.03em;
}

.brand-login {
    justify-content: center;
    margin-bottom: 30px;
}
.brand-login .brand-mark { font-size: 38px; }
.brand-login .brand-name { font-size: 28px; }

.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-page { width: min(100%, 460px); }
.login-panel {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 30px;
    box-shadow: var(--shadow);
    padding: 38px;
    backdrop-filter: blur(18px);
}

.login-copy { text-align: center; margin-bottom: 26px; }
.login-copy h1 { margin: 5px 0 8px; font-size: clamp(28px, 6vw, 38px); letter-spacing: -0.045em; }
.login-copy p:last-child { margin: 0; color: var(--muted); line-height: 1.6; }
.login-note { margin: 22px 0 0; color: var(--muted); text-align: center; font-size: 13px; }

.eyebrow, .modal-kicker {
    margin: 0;
    color: #4f46e5;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.login-form, .form-stack { display: grid; gap: 17px; }
label { display: grid; gap: 7px; color: #344054; font-size: 14px; font-weight: 650; }
input, textarea, select {
    width: 100%;
    border: 1px solid #d7deea;
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    padding: 12px 14px;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
input:focus, textarea:focus, select:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}
textarea { min-height: 95px; resize: vertical; }
.input-hint { margin: -2px 0 0; color: var(--muted); font-size: 12px; font-weight: 500; }

.button {
    display: inline-flex;
    min-height: 43px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 10px 16px;
    font-weight: 750;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.button:active { transform: translateY(1px); }
.button-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 8px 18px rgba(17, 24, 39, 0.16);
}
.button-primary:hover { background: #252f42; }
.button-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.button-secondary:hover, .button-ghost:hover { background: #f7f8fc; }
.button-danger { background: var(--danger); color: #fff; }
.button-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.button-full { width: 100%; }

.alert {
    margin-bottom: 18px;
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.45;
}
.alert-error { background: var(--danger-soft); color: #9f2038; border: 1px solid #ffd5dc; }

.app-shell { min-height: 100vh; }
.topbar {
    position: sticky;
    z-index: 50;
    top: 0;
    display: flex;
    min-height: 72px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    background: rgba(255, 255, 255, 0.88);
    padding: 0 max(22px, calc((100vw - 1440px) / 2));
    backdrop-filter: blur(16px);
}
.topbar-actions { position: relative; display: flex; align-items: center; gap: 10px; }
.icon-button {
    display: inline-grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font-size: 22px;
    line-height: 1;
}
.icon-button:hover { background: #f7f8fc; }
.profile-button {
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #111827, #4f46e5);
    color: #fff;
    font-size: 14px;
    font-weight: 850;
}
.account-menu {
    position: absolute;
    z-index: 80;
    top: calc(100% + 10px);
    right: 0;
    width: 210px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.14);
}
.account-menu-head { display: grid; gap: 3px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.account-menu-head span { color: var(--muted); font-size: 11px; }
.account-menu button {
    width: 100%;
    border: 0;
    background: transparent;
    padding: 11px 16px;
    color: var(--text);
    text-align: left;
    font-size: 14px;
}
.account-menu button:hover { background: var(--surface-soft); }
.danger-text { color: var(--danger) !important; }

.main-content {
    width: min(100%, 1480px);
    margin: 0 auto;
    padding: 42px 24px calc(40px + var(--safe-bottom));
}
.hero-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 22px;
    margin-bottom: 36px;
}
.hero-row h1 { margin: 7px 0 8px; font-size: clamp(32px, 5vw, 50px); letter-spacing: -0.055em; line-height: 1; }
.hero-description { max-width: 630px; margin: 0; color: var(--muted); line-height: 1.55; }
.cards-section { min-width: 0; }
.cards-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.cards-toolbar h2 { margin: 0; font-size: 18px; letter-spacing: -0.02em; }
.scroll-controls { display: flex; gap: 8px; }
.scroll-controls .icon-button { width: 38px; height: 38px; }

.cards-track {
    display: flex;
    gap: 18px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 4px 24px;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 4px;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    scrollbar-color: #c6cfdf transparent;
}
.cards-track::-webkit-scrollbar { height: 8px; }
.cards-track::-webkit-scrollbar-thumb { background: #c6cfdf; border-radius: 20px; }

.finance-card {
    --card-color: #2563eb;
    position: relative;
    display: flex;
    width: min(390px, calc(100vw - 42px));
    min-width: min(390px, calc(100vw - 42px));
    height: min(650px, calc(100vh - 220px));
    min-height: 520px;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.9);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
    scroll-snap-align: start;
}
.finance-card::before {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 7px;
    background: var(--card-color);
    content: "";
}
.card-summary {
    position: relative;
    padding: 25px 23px 20px;
    background: linear-gradient(155deg, color-mix(in srgb, var(--card-color) 10%, white), #fff 62%);
    border-bottom: 1px solid var(--border);
}
.card-topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title { margin: 0; font-size: 20px; letter-spacing: -0.035em; overflow-wrap: anywhere; }
.card-menu-wrap { position: relative; }
.card-menu-button { width: 35px; height: 35px; border: 0; background: rgba(255,255,255,0.72); font-size: 21px; }
.card-menu {
    position: absolute;
    z-index: 15;
    top: calc(100% + 6px);
    right: 0;
    width: 205px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.17);
}
.card-menu button { width: 100%; border: 0; background: transparent; padding: 11px 13px; text-align: left; color: var(--text); font-size: 13px; }
.card-menu button:hover { background: var(--surface-soft); }
.balance-label { display: block; margin-top: 20px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.balance-value { margin: 4px 0 0; font-size: 34px; font-weight: 850; letter-spacing: -0.055em; overflow-wrap: anywhere; }
.balance-value.negative { color: var(--danger); }
.card-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 20px; }
.stat { min-width: 0; border: 1px solid rgba(255,255,255,0.9); border-radius: 11px; background: rgba(255,255,255,0.68); padding: 9px; }
.stat span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }
.stat strong { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-income strong { color: var(--success); }
.stat-expense strong { color: var(--danger); }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.transaction-button { min-height: 42px; }
.transaction-button.income { background: var(--success-soft); color: var(--success); border-color: #c9eddf; }
.transaction-button.expense { background: var(--danger-soft); color: var(--danger); border-color: #ffd6dc; }
.transaction-list-wrap { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.transaction-heading { display: flex; align-items: center; justify-content: space-between; padding: 15px 19px 8px; }
.transaction-heading h3 { margin: 0; font-size: 14px; }
.transaction-count { color: var(--muted); font-size: 12px; }
.transaction-list { min-height: 0; flex: 1; overflow-y: auto; padding: 0 12px 14px; scrollbar-width: thin; }
.transaction-item {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    border-bottom: 1px solid #edf0f5;
    padding: 11px 7px;
}
.transaction-item:last-child { border-bottom: 0; }
.transaction-icon { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 11px; font-weight: 900; }
.transaction-item.income .transaction-icon { background: var(--success-soft); color: var(--success); }
.transaction-item.expense .transaction-icon { background: var(--danger-soft); color: var(--danger); }
.transaction-copy { min-width: 0; }
.transaction-date { display: block; color: var(--muted); font-size: 11px; }
.transaction-comment { display: block; margin-top: 3px; overflow: hidden; color: #344054; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.transaction-comment.no-comment { color: #98a2b3; font-style: italic; }
.transaction-value { text-align: right; }
.transaction-value strong { display: block; font-size: 13px; white-space: nowrap; }
.transaction-item.income .transaction-value strong { color: var(--success); }
.transaction-item.expense .transaction-value strong { color: var(--danger); }
.transaction-tools { display: flex; justify-content: flex-end; gap: 2px; margin-top: 4px; }
.mini-button { border: 0; background: transparent; color: var(--muted); padding: 2px 4px; font-size: 11px; }
.mini-button:hover { color: var(--text); }
.mini-button.delete:hover { color: var(--danger); }
.empty-transactions { display: grid; min-height: 170px; place-items: center; padding: 24px; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.55; }

.empty-state {
    display: grid;
    width: min(100%, 720px);
    min-height: 340px;
    flex: 0 0 100%;
    place-items: center;
    border: 1px dashed #cbd5e1;
    border-radius: var(--radius-lg);
    background: rgba(255,255,255,0.64);
    padding: 36px;
    text-align: center;
}
.empty-state-icon { display: grid; width: 68px; height: 68px; place-items: center; margin: 0 auto 18px; border-radius: 22px; background: var(--primary-soft); color: #4f46e5; font-size: 31px; }
.empty-state h3 { margin: 0 0 8px; font-size: 23px; }
.empty-state p { max-width: 440px; margin: 0 auto 20px; color: var(--muted); line-height: 1.55; }
.cards-loading { display: flex; align-items: center; gap: 10px; min-height: 180px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 2px solid rgba(99,102,241,0.2); border-top-color: #6366f1; border-radius: 50%; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-backdrop {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: grid;
    place-items: center;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.52);
    padding: 20px;
    backdrop-filter: blur(5px);
}
.modal {
    width: min(100%, 500px);
    max-height: min(92vh, 780px);
    overflow-y: auto;
    border-radius: 23px;
    background: #fff;
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.28);
}
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--border); padding: 20px 22px; }
.modal-header h2 { margin: 4px 0 0; font-size: 23px; letter-spacing: -0.035em; }
.modal-body { padding: 22px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.type-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-option { position: relative; }
.type-option input { position: absolute; opacity: 0; pointer-events: none; }
.type-option span { display: flex; min-height: 47px; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--muted); }
.type-option input[value="income"]:checked + span { border-color: #70caa9; background: var(--success-soft); color: var(--success); font-weight: 750; }
.type-option input[value="expense"]:checked + span { border-color: #f2a9b5; background: var(--danger-soft); color: var(--danger); font-weight: 750; }

.toast-region { position: fixed; z-index: 150; right: 18px; bottom: calc(18px + var(--safe-bottom)); display: grid; width: min(380px, calc(100vw - 36px)); gap: 9px; }
.toast { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; border: 1px solid var(--border); border-radius: 14px; background: #fff; box-shadow: 0 16px 40px rgba(15,23,42,0.16); padding: 13px 14px; animation: toast-in 0.2s ease-out; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast button { border: 0; background: transparent; color: var(--muted); font-size: 18px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.page-busy { position: fixed; z-index: 200; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,0.35); backdrop-filter: blur(1px); }
.page-busy .spinner { width: 34px; height: 34px; border-width: 3px; }

@supports not (background: color-mix(in srgb, red 10%, white)) {
    .card-summary { background: #f8fafc; }
}

@media (max-width: 720px) {
    .login-body { padding: 14px; }
    .login-panel { padding: 30px 22px; border-radius: 24px; }
    .topbar { min-height: 64px; padding: 0 16px; }
    .topbar .brand-name { font-size: 17px; }
    .install-button { min-height: 38px; padding: 8px 11px; font-size: 12px; }
    .main-content { padding: 30px 16px calc(28px + var(--safe-bottom)); }
    .hero-row { align-items: stretch; flex-direction: column; margin-bottom: 27px; }
    .hero-row .button { width: 100%; }
    .hero-row h1 { font-size: 38px; }
    .hero-description { font-size: 14px; }
    .scroll-controls { display: none; }
    .cards-track { margin-right: -16px; padding-right: 16px; }
    .finance-card { width: calc(100vw - 36px); min-width: calc(100vw - 36px); height: calc(100dvh - 210px); min-height: 500px; }
    .card-summary { padding: 23px 19px 18px; }
    .balance-value { font-size: 30px; }
    .card-stats { gap: 6px; }
    .stat { padding: 8px 7px; }
    .modal-backdrop { align-items: end; padding: 0; }
    .modal { width: 100%; max-height: 92dvh; border-radius: 24px 24px 0 0; padding-bottom: var(--safe-bottom); }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .button { width: 100%; }
}

@media (max-width: 390px) {
    .brand-mark { font-size: 22px; }
    .brand-name { font-size: 16px !important; }
    .main-content { padding-inline: 12px; }
    .cards-track { margin-right: -12px; padding-right: 12px; }
    .finance-card { width: calc(100vw - 28px); min-width: calc(100vw - 28px); }
}
