:root {
	--font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
	--font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, ui-monospace, monospace;

	--bg-canvas: #f8fafc;
	--bg-surface: #ffffff;
	--bg-elevated: #ffffff;
	--bg-hover: #f1f5f9;
	--bg-subtle: #f8fafc;

	--text-primary: #0f172a;
	--text-muted: #475569;
	--text-subtle: #94a3b8;

	--border-default: #e2e8f0;
	--border-strong: #cbd5e1;

	--brand-50: #eef0fb;
	--brand-100: #dde0f7;
	--brand-500: #7b85dc;
	--brand-600: #4f46e5;
	--brand-700: #4338ca;
	--brand-fg: #4f46e5;
	--brand-bg-subtle: #eef0fb;

	--success-fg: #15803d;
	--success-bg: #dcfce7;
	--warning-fg: #b45309;
	--warning-bg: #fef3c7;
	--error-fg: #b91c1c;
	--error-bg: #fee2e2;

	--shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
	--shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px 0 rgba(15, 23, 42, 0.04);
	--shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
	--shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
	--shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.06);

	--ring-focus: 0 0 0 3px rgba(79, 70, 229, 0.2);
	--ring-error: 0 0 0 3px rgba(220, 38, 38, 0.16);

	--radius-sm: 4px;
	--radius-md: 6px;
	--radius-lg: 10px;
	--radius-xl: 14px;
	--radius-full: 9999px;
}

[data-theme="dark"],
.dark {
	--bg-canvas: #090d16;
	--bg-surface: #111827;
	--bg-elevated: #1a2234;
	--bg-hover: #1e293b;
	--bg-subtle: #131d2e;

	--text-primary: #f8fafc;
	--text-muted: #94a3b8;
	--text-subtle: #64748b;

	--border-default: #1f293d;
	--border-strong: #334155;

	--brand-50: rgba(99, 102, 241, 0.15);
	--brand-100: rgba(99, 102, 241, 0.25);
	--brand-500: #818cf8;
	--brand-600: #6366f1;
	--brand-700: #4f46e5;
	--brand-fg: #a5b4fc;
	--brand-bg-subtle: rgba(99, 102, 241, 0.16);

	--success-fg: #4ade80;
	--success-bg: rgba(34, 197, 94, 0.16);
	--warning-fg: #fbbf24;
	--warning-bg: rgba(245, 158, 11, 0.16);
	--error-fg: #f87171;
	--error-bg: rgba(239, 68, 68, 0.16);

	--shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
	--shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5);
	--shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.6);
	--shadow-lg: 0 12px 20px -6px rgba(0, 0, 0, 0.65);
	--shadow-xl: 0 20px 28px -8px rgba(0, 0, 0, 0.75);

	--ring-focus: 0 0 0 3px rgba(129, 140, 248, 0.3);
}

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

body {
	background: var(--bg-canvas);
	color: var(--text-primary);
	font-family: var(--font-sans);
	font-size: 13.5px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
	min-height: 100vh;
}

.tabular {
	font-variant-numeric: tabular-nums;
	font-family: var(--font-mono);
}

/* App Shell */
.app-container {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

.top-navbar {
	background: var(--bg-surface);
	border-bottom: 1px solid var(--border-default);
	padding: 0.75rem 1.5rem;
	position: sticky;
	top: 0;
	z-index: 30;
	backdrop-filter: blur(8px);
}

.navbar-inner {
	max-width: 1240px;
	margin: 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}

.brand-badge {
	display: flex;
	align-items: center;
	gap: 0.65rem;
	font-weight: 600;
	font-size: 1rem;
	letter-spacing: -0.01em;
	color: var(--text-primary);
}

.brand-icon {
	width: 32px;
	height: 32px;
	background: linear-gradient(135deg, var(--brand-600), #7c3aed);
	color: white;
	border-radius: var(--radius-md);
	display: grid;
	place-items: center;
	font-weight: 700;
	box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);
}

.main-content {
	max-width: 1240px;
	margin: 0 auto;
	padding: 1.5rem;
	width: 100%;
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
}

/* Month Bar / Selector */
.month-selector-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	padding: 0.85rem 1.25rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 1rem;
	box-shadow: var(--shadow-xs);
}

.month-nav {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.month-heading {
	font-size: 1.15rem;
	font-weight: 700;
	letter-spacing: -0.02em;
	min-width: 170px;
	text-align: center;
}

.quick-tag {
	font-size: 0.75rem;
	font-weight: 500;
	padding: 0.15rem 0.5rem;
	border-radius: var(--radius-sm);
	background: var(--brand-bg-subtle);
	color: var(--brand-fg);
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

/* Stats / KPI Strip */
.kpi-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	gap: 1rem;
}

.kpi-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	padding: 1.15rem 1.25rem;
	box-shadow: var(--shadow-xs);
	position: relative;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card.highlight {
	border-color: var(--brand-500);
	background: linear-gradient(to bottom right, var(--bg-surface), var(--brand-50));
}

.kpi-title {
	font-size: 0.8rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-muted);
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.kpi-value {
	font-size: 1.75rem;
	font-weight: 700;
	letter-spacing: -0.03em;
	margin: 0.35rem 0 0.15rem;
	color: var(--text-primary);
}

.kpi-meta {
	font-size: 0.75rem;
	color: var(--text-muted);
	display: flex;
	align-items: center;
	gap: 0.35rem;
}

.budget-bar-track {
	height: 6px;
	border-radius: var(--radius-full);
	background: var(--border-default);
	margin-top: 0.65rem;
	overflow: hidden;
	position: relative;
}

.budget-bar-fill {
	height: 100%;
	border-radius: var(--radius-full);
	transition: width 0.4s ease, background-color 0.2s ease;
}

/* Category Filter & Spend Distribution */
.breakdown-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	padding: 1.25rem;
	box-shadow: var(--shadow-xs);
}

.card-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 1rem;
	gap: 0.5rem;
	flex-wrap: wrap;
}

.card-header h2 {
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--text-primary);
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.segmented-progress {
	height: 12px;
	border-radius: var(--radius-md);
	background: var(--border-default);
	overflow: hidden;
	display: flex;
	width: 100%;
	margin-bottom: 1.25rem;
}

.segment-slice {
	height: 100%;
	transition: width 0.3s ease;
	position: relative;
}

.category-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.category-chip {
	display: inline-flex;
	align-items: center;
	gap: 0.45rem;
	padding: 0.35rem 0.75rem;
	border-radius: var(--radius-full);
	font-size: 0.8rem;
	font-weight: 500;
	border: 1px solid var(--border-default);
	background: var(--bg-surface);
	color: var(--text-primary);
	cursor: pointer;
	transition: all 0.15s ease;
	user-select: none;
}

.category-chip:hover {
	border-color: var(--border-strong);
	background: var(--bg-hover);
}

.category-chip.active {
	background: var(--brand-600);
	color: white;
	border-color: var(--brand-600);
	box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

.category-chip.active .chip-badge {
	background: rgba(255, 255, 255, 0.25);
	color: white;
}

.chip-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	flex-shrink: 0;
}

.chip-badge {
	font-size: 0.75rem;
	padding: 0.1rem 0.4rem;
	border-radius: var(--radius-full);
	background: var(--bg-subtle);
	color: var(--text-muted);
	font-family: var(--font-mono);
}

/* Two-column layout for Form + Table */
.content-layout {
	display: grid;
	grid-template-columns: 340px 1fr;
	gap: 1.5rem;
	align-items: start;
}

@media (max-width: 960px) {
	.content-layout {
		grid-template-columns: 1fr;
	}
}

/* Add Expense Form Card */
.form-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	padding: 1.25rem;
	box-shadow: var(--shadow-xs);
}

.form-group {
	margin-bottom: 0.9rem;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
}

.form-label {
	font-size: 0.8rem;
	font-weight: 600;
	color: var(--text-muted);
}

.input,
.select,
.textarea {
	width: 100%;
	padding: 0.5rem 0.75rem;
	border: 1px solid var(--border-default);
	border-radius: var(--radius-md);
	background: var(--bg-surface);
	color: var(--text-primary);
	font-family: inherit;
	font-size: 0.875rem;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
.select:focus,
.textarea:focus {
	outline: none;
	border-color: var(--brand-600);
	box-shadow: var(--ring-focus);
}

.input-currency-wrapper {
	position: relative;
	display: flex;
	align-items: center;
}

.currency-symbol {
	position: absolute;
	left: 0.75rem;
	font-weight: 600;
	color: var(--text-muted);
	pointer-events: none;
}

.input-currency-wrapper input {
	padding-left: 1.65rem;
	font-family: var(--font-mono);
	font-weight: 600;
	font-size: 1.05rem;
}

.preset-buttons {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin-top: 0.25rem;
}

.preset-btn {
	font-size: 0.75rem;
	padding: 0.2rem 0.5rem;
	border-radius: var(--radius-sm);
	border: 1px dashed var(--border-strong);
	background: var(--bg-subtle);
	color: var(--text-muted);
	cursor: pointer;
	transition: all 0.12s ease;
}

.preset-btn:hover {
	background: var(--brand-50);
	border-color: var(--brand-500);
	color: var(--brand-fg);
}

/* Expenses Table Card */
.table-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-xs);
	overflow: hidden;
}

.table-toolbar {
	padding: 0.85rem 1.25rem;
	border-bottom: 1px solid var(--border-default);
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 0.75rem;
}

.search-box {
	position: relative;
	min-width: 220px;
	flex: 1;
	max-width: 320px;
}

.search-box input {
	padding-left: 2rem;
	height: 32px;
	font-size: 0.8rem;
}

.search-icon {
	position: absolute;
	left: 0.65rem;
	top: 50%;
	transform: translateY(-50%);
	color: var(--text-subtle);
	pointer-events: none;
	width: 14px;
	height: 14px;
}

.expenses-table {
	width: 100%;
	border-collapse: collapse;
	text-align: left;
}

.expenses-table th {
	background: var(--bg-subtle);
	padding: 0.65rem 1rem;
	font-size: 0.75rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-muted);
	border-bottom: 1px solid var(--border-default);
}

.expenses-table td {
	padding: 0.75rem 1rem;
	border-bottom: 1px solid var(--border-default);
	font-size: 0.875rem;
	vertical-align: middle;
}

.expenses-table tr:hover td {
	background: var(--bg-hover);
}

.expenses-table tr:last-child td {
	border-bottom: none;
}

/* Running total badge in table */
.running-badge {
	font-size: 0.75rem;
	color: var(--text-muted);
	font-family: var(--font-mono);
	background: var(--bg-subtle);
	padding: 0.15rem 0.4rem;
	border-radius: var(--radius-sm);
	display: inline-block;
}

/* Category Badge in list */
.cat-badge {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	padding: 0.2rem 0.55rem;
	border-radius: var(--radius-full);
	font-size: 0.75rem;
	font-weight: 500;
	white-space: nowrap;
}

/* Buttons */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.45rem;
	height: 32px;
	padding: 0 0.85rem;
	border-radius: var(--radius-md);
	font-size: 0.8125rem;
	font-weight: 500;
	cursor: pointer;
	border: 1px solid transparent;
	transition: all 0.15s ease;
	font-family: inherit;
}

.btn-primary {
	background: var(--brand-600);
	color: #ffffff;
}

.btn-primary:hover {
	background: var(--brand-700);
}

.btn-secondary {
	background: var(--bg-surface);
	color: var(--text-primary);
	border-color: var(--border-default);
}

.btn-secondary:hover {
	background: var(--bg-hover);
	border-color: var(--border-strong);
}

.btn-ghost {
	background: transparent;
	color: var(--text-muted);
}

.btn-ghost:hover {
	background: var(--bg-hover);
	color: var(--text-primary);
}

.btn-danger-ghost {
	background: transparent;
	color: var(--error-fg);
}

.btn-danger-ghost:hover {
	background: var(--error-bg);
}

.btn-sm {
	height: 26px;
	padding: 0 0.55rem;
	font-size: 0.75rem;
}

.btn-icon {
	width: 30px;
	height: 30px;
	padding: 0;
	border-radius: var(--radius-md);
	display: inline-grid;
	place-items: center;
}

/* Empty State */
.empty-state {
	padding: 3rem 1.5rem;
	text-align: center;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
}

.empty-icon-wrap {
	width: 52px;
	height: 52px;
	border-radius: 50%;
	background: var(--bg-subtle);
	color: var(--text-subtle);
	display: grid;
	place-items: center;
	margin-bottom: 0.5rem;
}

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

.empty-desc {
	font-size: 0.8125rem;
	color: var(--text-muted);
	max-width: 320px;
}

/* Modal Overlay */
.modal-overlay {
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, 0.5);
	backdrop-filter: blur(4px);
	display: grid;
	place-items: center;
	z-index: 50;
	padding: 1rem;
}

.modal-content {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-xl);
	box-shadow: var(--shadow-xl);
	width: 100%;
	max-width: 440px;
	overflow: hidden;
	animation: modalSlide 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlide {
	from {
		opacity: 0;
		transform: translateY(8px) scale(0.98);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

.modal-header {
	padding: 1rem 1.25rem;
	border-bottom: 1px solid var(--border-default);
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.modal-header h3 {
	font-size: 1rem;
	font-weight: 600;
}

.modal-body {
	padding: 1.25rem;
}

.modal-footer {
	padding: 0.85rem 1.25rem;
	border-top: 1px solid var(--border-default);
	display: flex;
	justify-content: flex-end;
	gap: 0.5rem;
	background: var(--bg-subtle);
}

/* Toast */
.toast-container {
	position: fixed;
	bottom: 1.5rem;
	right: 1.5rem;
	z-index: 60;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.toast {
	background: var(--bg-elevated);
	border: 1px solid var(--border-default);
	box-shadow: var(--shadow-lg);
	border-radius: var(--radius-md);
	padding: 0.65rem 1rem;
	font-size: 0.8125rem;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	color: var(--text-primary);
	animation: toastSlide 0.2s ease-out;
}

@keyframes toastSlide {
	from {
		opacity: 0;
		transform: translateX(12px);
	}
	to {
		opacity: 1;
		transform: translateX(0);
	}
}

/* Budget quick edit popover / inline */
.budget-editor {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	margin-top: 0.5rem;
}

/* Responsive adjustments */
@media (max-width: 640px) {
	.navbar-inner {
		flex-direction: column;
		align-items: stretch;
	}
	.month-selector-card {
		flex-direction: column;
		align-items: stretch;
	}
	.month-nav {
		justify-content: space-between;
	}
	.expenses-table th:nth-child(4),
	.expenses-table td:nth-child(4) {
		display: none; /* Hide running total column on very small screens */
	}
}
