/* ============================================
   Design tokens
   ============================================ */
:root {
    --bg: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #9ca3af;
    --text-tertiary: #d1d5db;

    --income-dark: #1a1b2e;
    --income-dark-2: #2a2b3e;
    --expense-purple: #8b5cf6;
    --expense-purple-2: #a78bfa;
    --expense-purple-soft: #c4b5fd;

    --border-soft: #e5e7eb;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    --fab-shadow: 0 8px 24px rgba(139, 92, 246, 0.45);

    --income-bar: #1a1b2e;
    --expense-bar: #8b5cf6;

    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-pill: 999px;

    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============================================
   Base
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    background: #f3f4f6;
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
}

input, select {
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
}

a {
    color: inherit;
    text-decoration: none;
}

ul {
    list-style: none;
}

/* ============================================
   App container — mobile shell
   ============================================ */
.app {
    position: relative;
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    background: var(--bg);
    overflow: hidden;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
}

@media (min-width: 481px) {
    body {
        background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
    }
    .app {
        margin-top: 16px;
        margin-bottom: 16px;
        height: calc(100vh - 32px);
        height: calc(100dvh - 32px);
        border-radius: 28px;
    }
}

/* ============================================
   Screens
   ============================================ */
.screen {
    position: absolute;
    inset: 0;
    bottom: 84px;
    padding: 20px 22px 24px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.screen.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.page-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

/* ============================================
   Home / Statistic screen
   ============================================ */
.balance-block {
    text-align: left;
    margin-bottom: 26px;
}

.balance-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
}

.balance-amount {
    font-size: 2.1rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.overview-block {
    margin-bottom: 24px;
}

.overview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.overview-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.month-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-pill);
    font-size: 0.82rem;
    color: var(--text-primary);
    font-weight: 500;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.month-pill:hover {
    border-color: var(--expense-purple);
    background: #faf5ff;
}

.month-pill .chevron {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ============================================
   Chart
   ============================================ */
.chart-wrapper {
    position: relative;
    display: flex;
    height: 180px;
    margin-bottom: 4px;
}

.chart-y-axis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 30px;
    padding: 4px 6px 22px 0;
    font-size: 0.65rem;
    color: var(--text-tertiary);
    text-align: right;
    flex-shrink: 0;
}

.chart-area {
    flex: 1;
    position: relative;
    border-bottom: 1px solid transparent;
    background-image: repeating-linear-gradient(
        to top,
        transparent 0,
        transparent calc(20% - 1px),
        var(--border-soft) calc(20% - 1px),
        var(--border-soft) 20%
    );
    background-size: 100% 100%;
    background-position: 0 0;
    background-repeat: no-repeat;
}

.chart-area::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(
        to top,
        transparent 0,
        transparent calc(20% - 1px),
        #e5e7eb calc(20% - 1px),
        #e5e7eb 20%
    );
    opacity: 0.7;
    pointer-events: none;
}

.chart-bars {
    position: absolute;
    inset: 4px 0 22px 0;
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    gap: 0;
}

.chart-month {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
    height: 100%;
}

.chart-bar {
    width: 10px;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.chart-bar.income {
    background: var(--income-bar);
}

.chart-bar.expense {
    background: var(--expense-bar);
}

.chart-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 0.85rem;
    font-style: italic;
}

.chart-x-axis {
    display: flex;
    justify-content: space-around;
    padding: 6px 0 0 30px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.chart-x-axis span {
    flex: 1;
    text-align: center;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 22px;
    margin-top: 14px;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot-income {
    background: var(--income-dark);
}

.dot-expense {
    background: var(--expense-purple);
}

/* ============================================
   Hero cards
   ============================================ */
.hero-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 8px;
}

.hero-card {
    position: relative;
    border-radius: var(--r-lg);
    padding: 16px;
    height: 130px;
    color: #fff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: var(--card-shadow);
}

.hero-card-income {
    background: linear-gradient(135deg, #1a1b2e 0%, #2a2b3e 100%);
}

.hero-card-expense {
    background: linear-gradient(135deg, #8b5cf6 0%, #a78bfa 100%);
}

.hero-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    backdrop-filter: blur(4px);
}

.hero-watermark {
    position: absolute;
    right: -8px;
    bottom: -28px;
    font-size: 110px;
    font-weight: 900;
    line-height: 1;
    color: rgba(255, 255, 255, 0.08);
    pointer-events: none;
    user-select: none;
}

.hero-text {
    position: relative;
    z-index: 1;
}

.hero-label {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.75);
    margin-bottom: 2px;
    font-weight: 500;
}

.hero-amount {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ============================================
   Stats screen
   ============================================ */
.stats-block {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 26px;
}

.stat-tile {
    background: #f9fafb;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    padding: 14px;
}

.stat-tile-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.stat-tile-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.section-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: #f9fafb;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
}

.category-row-name {
    font-size: 0.9rem;
    font-weight: 500;
}

.category-row-amount {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.category-row.income .category-row-amount {
    color: #10b981;
}

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

/* ============================================
   Transactions screen
   ============================================ */
.txn-toolbar {
    margin-bottom: 14px;
}

.filter-pills {
    display: flex;
    gap: 8px;
}

.filter-pill {
    padding: 7px 16px;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-pill);
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
    transition: all 0.15s ease;
}

.filter-pill.active {
    background: var(--expense-purple);
    color: #fff;
    border-color: var(--expense-purple);
}

.txn-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.txn-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: #f9fafb;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    transition: transform 0.15s ease;
}

.txn-item:active {
    transform: scale(0.98);
}

.txn-item-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.95rem;
    font-weight: 700;
}

.txn-item.income .txn-item-icon {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
}

.txn-item.expense .txn-item-icon {
    background: rgba(139, 92, 246, 0.12);
    color: var(--expense-purple);
}

.txn-item-main {
    flex: 1;
    min-width: 0;
}

.txn-item-desc {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.txn-item-meta {
    font-size: 0.74rem;
    color: var(--text-secondary);
}

.txn-item-amount {
    font-size: 0.95rem;
    font-weight: 700;
    flex-shrink: 0;
}

.txn-item.income .txn-item-amount {
    color: #10b981;
}

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

.txn-delete {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.1rem;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
}

.txn-delete:hover {
    color: #ef4444;
    background: #fef2f2;
}

.empty-msg {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 16px;
    font-size: 0.88rem;
    font-style: italic;
}

.empty-msg.show {
    display: block;
}

.empty-msg[hidden] {
    display: none;
}

/* ============================================
   Profile screen
   ============================================ */
.profile-card {
    text-align: center;
    padding: 20px 0 28px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 20px;
}

.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--expense-purple), var(--expense-purple-2));
    color: #fff;
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.3);
}

.profile-name {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.profile-sub {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.profile-menu {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.profile-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #f9fafb;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease;
    width: 100%;
    text-align: left;
}

.profile-menu-item + .profile-menu-item {
    margin-top: 8px;
}

.profile-menu-item:hover {
    background: #f3f4f6;
}

.profile-menu-item .chevron {
    color: var(--text-tertiary);
    font-size: 1.1rem;
}

.profile-foot {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.78rem;
    margin-top: 32px;
}

/* ============================================
   FAB
   ============================================ */
.fab {
    position: absolute;
    left: 50%;
    bottom: calc(48px + var(--safe-bottom));
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--expense-purple);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--fab-shadow);
    z-index: 50;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.fab:hover {
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 12px 30px rgba(139, 92, 246, 0.55);
}

.fab:active {
    transform: translateX(-50%) scale(0.95);
}

/* ============================================
   Bottom nav
   ============================================ */
.bottom-nav {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(72px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: #fff;
    border-top: 1px solid var(--border-soft);
    display: grid;
    grid-template-columns: 1fr 1fr 80px 1fr 1fr;
    align-items: center;
    z-index: 40;
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
    transition: color 0.15s ease;
}

.nav-item.active {
    color: var(--expense-purple);
}

.nav-fab-spacer {
    width: 80px;
    height: 1px;
}

/* ============================================
   Modal (Add transaction, Month picker)
   ============================================ */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.2s ease;
    padding: 0;
}

.modal-overlay[hidden] {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    width: 100%;
    background: #fff;
    border-radius: 24px 24px 0 0;
    padding: 12px 22px 28px;
    max-height: 88%;
    overflow-y: auto;
    animation: slideUp 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-sm {
    max-height: 60%;
}

.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border-soft);
    border-radius: 2px;
    margin: 0 auto 14px;
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
}

/* Segmented control */
.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #f3f4f6;
    border-radius: var(--r-pill);
    padding: 4px;
    margin-bottom: 20px;
}

.segment {
    padding: 9px 0;
    border-radius: var(--r-pill);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.segment.active {
    background: #fff;
    color: var(--text-primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Amount input (big centered) */
.amount-input {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 22px;
    padding: 8px 0;
}

.currency-prefix {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.amount-input input {
    font-size: 2.2rem;
    font-weight: 800;
    border: none;
    outline: none;
    background: transparent;
    width: 60%;
    text-align: left;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.amount-input input::placeholder {
    color: var(--text-tertiary);
    font-weight: 700;
}

/* Form fields */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.field label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.field input,
.field select {
    padding: 11px 14px;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    background: #fff;
    color: var(--text-primary);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--expense-purple);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

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

/* Modal actions */
.modal-actions {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 10px;
    margin-top: 8px;
}

.btn-primary,
.btn-secondary {
    padding: 13px 20px;
    border-radius: var(--r-md);
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.15s ease;
}

.btn-primary {
    background: var(--expense-purple);
    color: #fff;
}

.btn-primary:hover {
    background: #7c3aed;
}

.btn-secondary {
    background: #f3f4f6;
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #e5e7eb;
}

/* Month list */
.month-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.month-list li {
    padding: 12px 14px;
    border-radius: var(--r-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}

.month-list li:hover {
    background: #f9fafb;
}

.month-list li.active {
    background: rgba(139, 92, 246, 0.1);
    color: var(--expense-purple);
    font-weight: 700;
}

/* ============================================
   Toast
   ============================================ */
.toast {
    position: absolute;
    left: 50%;
    bottom: 160px;
    transform: translateX(-50%);
    background: rgba(31, 41, 55, 0.95);
    color: #fff;
    padding: 10px 18px;
    border-radius: var(--r-pill);
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: toastIn 0.25s ease;
}

.toast[hidden] {
    display: none;
}

@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================
   Small screen tweaks
   ============================================ */
@media (max-width: 360px) {
    .screen {
        padding: 16px 18px 20px;
    }
    .balance-amount {
        font-size: 1.85rem;
    }
    .hero-card {
        height: 120px;
    }
}

/* ============================================
   Login screen
   ============================================ */
.login-screen {
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, #f5f3ff 0%, #ede9fe 50%, #ddd6fe 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.login-screen[hidden] {
    display: none;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: #fff;
    border-radius: 24px;
    padding: 36px 28px 28px;
    box-shadow: 0 20px 60px rgba(139, 92, 246, 0.18);
    text-align: center;
    animation: loginCardIn 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes loginCardIn {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
    font-size: 3rem;
    margin-bottom: 12px;
    line-height: 1;
}

.login-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.login-sub {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--border-soft);
    border-radius: 12px;
    font-size: 1rem;
    color: var(--text-primary);
    background: #f9fafb;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    text-align: center;
    letter-spacing: 0.1em;
}

.login-input:focus {
    outline: none;
    border-color: var(--expense-purple);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

.login-input::placeholder {
    letter-spacing: normal;
}

.login-error {
    font-size: 0.85rem;
    color: #ef4444;
    margin: 0;
    padding: 8px 12px;
    background: #fef2f2;
    border-radius: 8px;
    text-align: center;
}

.login-error[hidden] {
    display: none;
}

.login-submit {
    width: 100%;
    padding: 14px 20px;
    background: var(--expense-purple);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3);
}

.login-submit:hover {
    background: #7c3aed;
}

.login-submit:active {
    transform: scale(0.98);
}

.login-submit:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
    box-shadow: none;
}

.login-foot {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    margin-top: 22px;
    line-height: 1.5;
}
