@font-face {
    font-family: Vazirmatn;
    src: url('/static/fonts/Vazirmatn-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: Vazirmatn;
    src: url('/static/fonts/Vazirmatn-Medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: Vazirmatn;
    src: url('/static/fonts/Vazirmatn-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg: #f8fafc;
    --bg-elevated: #ffffff;
    --bg-hover: #f1f5f9;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --income: #10b981;
    --expense: #ef4444;
    --balance-pos: #059669;
    --balance-neg: #dc2626;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 10px 40px rgba(15, 23, 42, 0.12);
    --radius: 14px;
    --radius-sm: 10px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-elevated: #1e293b;
    --bg-hover: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.4);
    --sidebar-bg: #020617;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: Vazirmatn, Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100dvh;
    transition: background var(--transition), color var(--transition);
}
body.has-offline-banner { padding-top: 2.5rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* Auth */
.auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg-elevated) 100%);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.auth-logo { font-size: 3rem; margin-bottom: 0.5rem; }
.auth-card h1 { font-size: 1.75rem; margin-bottom: 0.25rem; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.95rem; }
.auth-hint { margin-top: 1rem; font-size: 0.8rem; color: var(--text-muted); }
.auth-form { text-align: right; }

/* Layout */
.app-shell {
    display: flex;
    min-height: 100dvh;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 1rem;
}
.brand-icon { font-size: 1.5rem; }
.brand-text { font-weight: 700; font-size: 1.15rem; }

.nav-links { list-style: none; flex: 1; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    opacity: 0.75;
    transition: all var(--transition);
    margin-bottom: 0.25rem;
}
.nav-link:hover, .nav-link.active {
    opacity: 1;
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.nav-link span { font-size: 1.1rem; }

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.user-name { font-size: 0.85rem; opacity: 0.8; }

.main-content {
    flex: 1;
    margin-right: 260px;
    padding: 1.5rem 2rem 5rem;
    max-width: 1200px;
}

.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    padding: 0.5rem;
    z-index: 100;
    justify-content: space-around;
}
.mobile-nav-item {
    font-size: 1.5rem;
    padding: 0.5rem 1.5rem;
    opacity: 0.5;
    transition: opacity var(--transition);
}
.mobile-nav-item.active { opacity: 1; }

/* Header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.75rem; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }

/* Cards */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.card-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 1rem; }
.card-header .card-title { margin-bottom: 0; }
.form-card .card-title { margin-bottom: 1.25rem; }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: transform var(--transition);
}
.stat-card:hover { transform: translateY(-2px); }
.stat-icon { font-size: 2rem; }
.stat-label { display: block; font-size: 0.85rem; color: var(--text-muted); }
.stat-value { display: block; font-size: 1.15rem; font-weight: 700; margin-top: 0.15rem; }
.stat-income { border-right: 4px solid var(--income); }
.stat-expense { border-right: 4px solid var(--expense); }
.stat-balance.positive { border-right: 4px solid var(--balance-pos); }
.stat-balance.negative { border-right: 4px solid var(--balance-neg); }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
.chart-wrap { height: 280px; position: relative; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
}
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}
input, select, textarea {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.type-toggle { display: flex; gap: 0.5rem; }
.type-option input { display: none; }
.type-btn {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--transition);
}
.type-option input:checked + .type-btn.type-expense {
    background: var(--expense);
    color: #fff;
    border-color: var(--expense);
}
.type-option input:checked + .type-btn.type-income {
    background: var(--income);
    color: #fff;
    border-color: var(--income);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-icon {
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    font-size: 1.2rem;
}

/* Lists */
.transaction-feed, .transaction-list { list-style: none; }
.feed-item, .tx-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}
.feed-item:last-child, .tx-item:last-child { border-bottom: none; }
.feed-icon, .tx-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.feed-body, .tx-body { flex: 1; min-width: 0; }
.feed-title, .tx-title { display: block; font-weight: 500; font-size: 0.95rem; }
.feed-meta, .tx-meta { display: block; font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-amount, .tx-amount { font-weight: 700; font-size: 0.9rem; white-space: nowrap; }
.feed-expense .feed-amount, .tx-expense .tx-amount { color: var(--expense); }
.feed-income .feed-amount, .tx-income .tx-amount { color: var(--income); }

.filter-tabs { display: flex; gap: 0.35rem; }
.filter-tab {
    padding: 0.35rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
}
.filter-tab.active, .filter-tab:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Categories */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
    list-style: none;
}
.category-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    border-right: 4px solid var(--cat-color);
    background: var(--bg);
}
.cat-icon { font-size: 1.5rem; }
.cat-name { font-weight: 500; display: block; }
.badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    margin-top: 0.15rem;
}
.badge-expense { background: rgba(239,68,68,0.15); color: var(--expense); }
.badge-income { background: rgba(16,185,129,0.15); color: var(--income); }

/* FAB */
.fab-group {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 50;
}
.fab {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition);
}
.fab:hover { transform: scale(1.08); color: #fff; }
.fab-expense { background: var(--expense); }
.fab-income { background: var(--income); }

/* Alerts & misc */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error { background: rgba(239,68,68,0.12); color: var(--expense); border: 1px solid rgba(239,68,68,0.25); }
.empty-state { text-align: center; color: var(--text-muted); padding: 2rem 1rem; }
.loading { text-align: center; color: var(--text-muted); padding: 1rem; }
.link { font-size: 0.85rem; }

/* Offline banner */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 0.5rem 1rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.offline-banner.hidden { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.offline-banner.online { background: rgba(16, 185, 129, 0.95); color: #fff; }
.offline-banner.offline { background: rgba(239, 68, 68, 0.95); color: #fff; }
.offline-banner.syncing { background: rgba(234, 179, 8, 0.95); color: #1e293b; }

.pending-badge {
    background: var(--expense);
    color: #fff;
    font-size: 0.7rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    margin-right: 0.35rem;
}

.pending-section {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--border);
}
.pending-title {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.tx-pending { opacity: 0.85; }
.tx-pending .pending-icon { background: rgba(234, 179, 8, 0.15); }
.tx-failed { border-right: 3px solid var(--expense); }

/* Toast */
#toast-container {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    max-width: 90vw;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--income); }
.toast-error { border-color: var(--expense); }
.toast-info { border-color: var(--primary); }

/* OCR */
.ocr-card .card-desc {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0.25rem 0 1rem;
}
.ocr-status {
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}
.ocr-status.ok { background: rgba(16,185,129,0.12); color: var(--income); }
.ocr-status.warn { background: rgba(234,179,8,0.12); color: #ca8a04; }
.ocr-status.error { background: rgba(239,68,68,0.12); color: var(--expense); }
.ocr-upload {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
}
.ocr-upload input[type="file"] {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem;
}
.ocr-preview {
    margin-bottom: 1rem;
    text-align: center;
}
.ocr-preview img {
    max-width: 100%;
    max-height: 240px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.ocr-result {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    line-height: 1.8;
}
.ocr-result div { margin-bottom: 0.25rem; }
.ocr-notes span { display: block; color: var(--expense); font-size: 0.85rem; }
.ocr-raw { margin-top: 0.75rem; }
.ocr-raw pre {
    white-space: pre-wrap;
    font-size: 0.75rem;
    color: var(--text-muted);
    max-height: 120px;
    overflow-y: auto;
    margin-top: 0.5rem;
}
.offline-msg { font-size: 0.9rem; }

/* Budgets & accounts */
.alerts-bar { margin-bottom: 1rem; }
.alert-warning { background: rgba(234, 179, 8, 0.12); color: #ca8a04; border: 1px solid rgba(234, 179, 8, 0.3); }
.account-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
}
.account-stat {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    border-right: 4px solid var(--acc-color);
    text-align: center;
}
.acc-icon { font-size: 1.5rem; display: block; }
.acc-name { display: block; font-size: 0.85rem; color: var(--text-muted); margin: 0.25rem 0; }
.acc-net { font-weight: 700; font-size: 0.95rem; }
.acc-net.positive { color: var(--income); }
.acc-net.negative { color: var(--expense); }

.budget-list { list-style: none; }
.budget-list.compact .budget-item { margin-bottom: 0.75rem; }
.budget-item { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.budget-item:last-child { border-bottom: none; }
.budget-header { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 0.35rem; }
.budget-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.budget-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.budget-meta { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.35rem; font-size: 0.8rem; color: var(--text-muted); }
.budget-exceeded .budget-fill { background: var(--expense) !important; }
.budget-warning .budget-fill { opacity: 0.85; }

.settings-list { list-style: none; margin-top: 1rem; }
.settings-item {
    display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
    padding: 0.65rem 0; border-bottom: 1px solid var(--border);
}
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.card-desc { color: var(--text-muted); font-size: 0.9rem; margin: -0.5rem 0 1rem; }
.card-subtitle { font-size: 0.95rem; margin: 1rem 0 0.5rem; }

.stats-grid-3 { grid-template-columns: repeat(3, 1fr); margin: 1rem 0; }
.stat-mini { padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); text-align: center; }
.stat-mini span { display: block; font-size: 0.8rem; color: var(--text-muted); }
.stat-mini strong { font-size: 0.95rem; }
.export-buttons { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }
.preview-cats { list-style: none; }
.preview-cats li { padding: 0.35rem 0; border-bottom: 1px solid var(--border); }

/* Responsive */
@media (max-width: 900px) {
    .sidebar { display: none; }
    .main-content { margin-right: 0; padding: 1rem 1rem 5rem; }
    .mobile-nav { display: flex; }
    .stats-grid { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .fab-group { bottom: 5rem; left: 1rem; }
}

@media (max-width: 480px) {
    .page-header h1 { font-size: 1.35rem; }
    .form-row { grid-template-columns: 1fr; }
}
