/* Reset & Variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #a5b4fc;
    --success: #10b981;
    --success-bg: #d1fae5;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--gray-800);
    line-height: 1.5;
}

#app, .page {
    background: var(--gray-50);
    min-height: 100vh;
    padding-bottom: 80px;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 600px;
    margin: 0 auto;
}

.header-content h1 {
    font-size: 20px;
    font-weight: 700;
}

.header-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
    transition: background 0.2s;
}

.header-btn:hover {
    background: rgba(255,255,255,0.3);
}

.back-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    margin-left: -8px;
}

/* Balance Section */
.balance-section {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 0 20px 30px;
}

.balance-card {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
    color: white;
}

.balance-label {
    display: block;
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 8px;
}

.balance-amount {
    display: block;
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -1px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 600px;
    margin: -20px auto 0;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 12px;
}

.stat-icon {
    font-size: 28px;
}

.stat-info {
    flex: 1;
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--gray-500);
    margin-bottom: 2px;
}

.stat-value {
    display: block;
    font-size: 16px;
    font-weight: 700;
}

.stat-card.income .stat-value {
    color: var(--success);
}

.stat-card.expense .stat-value {
    color: var(--danger);
}

/* Filters */
.filters-section {
    max-width: 600px;
    margin: 20px auto;
    padding: 0 20px;
}

.filter-group {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.filter-group::-webkit-scrollbar {
    display: none;
}

.filter-select {
    flex-shrink: 0;
    padding: 10px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 50px;
    background: white;
    font-size: 14px;
    color: var(--gray-700);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='%236b7280'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Transactions Section */
.transactions-section {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 20px 20px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 16px;
}

.transactions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.transaction-item {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    gap: 14px;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.tx-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.transaction-item.income .tx-icon {
    background: var(--success-bg);
}

.transaction-item.expense .tx-icon {
    background: var(--danger-bg);
}

.tx-content {
    flex: 1;
    min-width: 0;
}

.tx-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 4px;
}

.tx-amount {
    font-size: 17px;
    font-weight: 700;
}

.transaction-item.income .tx-amount {
    color: var(--success);
}

.transaction-item.expense .tx-amount {
    color: var(--danger);
}

.tx-category {
    font-size: 13px;
    color: var(--gray-500);
    background: var(--gray-100);
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
}

.tx-description {
    font-size: 14px;
    color: var(--gray-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}

.tx-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--gray-400);
}

.tx-invoice {
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tx-invoice:hover {
    text-decoration: underline;
}

/* Empty & Loading States */
.loading, .empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 24px 0;
}

.page-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: white;
    border-radius: 50%;
    font-size: 20px;
    font-weight: 600;
    color: var(--gray-600);
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-btn:hover:not(:disabled) {
    background: var(--primary);
    color: white;
}

.page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-info {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-600);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.85);
}

.modal-content {
    position: relative;
    max-width: 95vw;
    max-height: 90vh;
    z-index: 1;
}

.modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius);
}

.modal-close {
    position: absolute;
    top: -50px;
    right: 0;
    width: 40px;
    height: 40px;
    border: none;
    background: white;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    display: flex;
    justify-content: center;
    gap: 0;
    padding: 8px 16px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    z-index: 100;
}

.nav-btn {
    flex: 1;
    max-width: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: var(--radius-sm);
    color: var(--gray-500);
}

.nav-btn:hover {
    background: var(--gray-100);
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn.active .nav-icon {
    transform: scale(1.1);
}

.nav-icon {
    font-size: 22px;
    transition: transform 0.2s;
}

.nav-label {
    font-size: 11px;
    font-weight: 600;
}

/* Stats Detail Page */
.stats-detail-section {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

.stats-period {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.stats-period h3 {
    font-size: 14px;
    color: var(--gray-500);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stats-item {
    text-align: center;
    padding: 16px;
    border-radius: var(--radius-sm);
}

.stats-item.income {
    background: var(--success-bg);
}

.stats-item.expense {
    background: var(--danger-bg);
}

.stats-item .stats-label {
    display: block;
    font-size: 12px;
    color: var(--gray-600);
    margin-bottom: 8px;
}

.stats-item .stats-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
}

.stats-item.income .stats-value {
    color: var(--success);
}

.stats-item.expense .stats-value {
    color: var(--danger);
}

.stats-summary {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.summary-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.summary-card.highlight {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.summary-label {
    font-size: 14px;
}

.summary-value {
    font-size: 20px;
    font-weight: 700;
}

/* Charts */
.chart-section {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.chart-section h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 16px;
    text-align: center;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 250px;
}

.chart-container.pie-container {
    height: 280px;
    max-width: 300px;
    margin: 0 auto;
}

.chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--gray-400);
    font-size: 14px;
}

/* Responsive */
@media (max-width: 380px) {
    .balance-amount {
        font-size: 28px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .filter-select {
        font-size: 13px;
        padding: 8px 12px;
    }
}
