.cf-calc-app {
	--cf-blue: #2563eb;
	--cf-indigo: #4f46e5;
	--cf-green: #16a34a;
	--cf-orange: #ea580c;
	--cf-purple: #9333ea;
	--cf-red: #dc2626;
	--cf-dark: #1f2328;
	--cf-gray: #6b7280;
	--cf-border: #e5e7eb;
	--cf-bg: #f7f7f8;
	--cf-card-bg: #ffffff;

	background: var(--cf-bg);
	border-radius: 12px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: var(--cf-dark);
	box-sizing: border-box;
}
.cf-calc-app *,
.cf-calc-app *::before,
.cf-calc-app *::after {
	box-sizing: border-box;
}

/* Header */
.cf-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
	margin-bottom: 20px;
	flex-wrap: wrap;
}
.cf-header-left { display: flex; gap: 14px; align-items: flex-start; }
.cf-header-icon {
	background: var(--cf-indigo);
	color: #fff;
	width: 44px;
	height: 44px;
	min-width: 44px;
	border-radius: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
}
.cf-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; line-height: 1.25; }
.cf-subtitle { font-size: 13.5px; color: var(--cf-gray); margin: 0; }
.cf-header-actions { display: flex; gap: 10px; }

/* Buttons */
.cf-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	font-size: 14px;
	font-weight: 600;
	padding: 10px 18px;
	border-radius: 8px;
	border: 1px solid transparent;
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, opacity .15s ease;
	white-space: nowrap;
	color: var(--cf-dark);
}
.cf-btn-ghost { background: #fff; color: var(--cf-dark) !important; border-color: var(--cf-border); }
.cf-btn-ghost:hover { background: #f3f4f6; }
.cf-btn-primary { background: var(--cf-blue); color: #fff !important; }
.cf-btn-primary:hover { background: #1d4ed8; }
.cf-btn-block { width: 100%; }
.cf-btn-outline { background: #fff; border-color: var(--cf-border); color: var(--cf-dark) !important; }
.cf-btn-outline:hover { background: #f3f4f6; }
/* The theme applies its own dark background to buttons on :active/:focus,
   independent of our styles, which collides with our default dark text and
   makes the label unreadable at the moment of clicking. Force light text
   for that state so it stays legible either way. */
.cf-btn-ghost:active, .cf-btn-ghost:focus,
.cf-btn-outline:active, .cf-btn-outline:focus {
	color: #fff !important;
}
.cf-btn-report {
	background: #fff;
	color: var(--cf-gray) !important;
	border: 1px solid var(--cf-border);
	text-decoration: none;
}
.cf-btn-report:hover { background: #f9f4f0; color: var(--cf-orange) !important; border-color: var(--cf-orange); }

/* Grid layout */
.cf-grid {
	display: grid;
	grid-template-columns: minmax(280px, 440px) minmax(0, 1fr);
	gap: 20px;
	align-items: start;
}
@media (max-width: 900px) {
	.cf-grid { grid-template-columns: minmax(0, 1fr); }
}
.cf-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* Card */
.cf-card {
	background: var(--cf-card-bg);
	border: 1px solid var(--cf-border);
	border-radius: 12px;
	padding: 22px;
	min-width: 0;
}
.cf-card-title {
	font-size: 16px;
	font-weight: 700;
	margin: 0 0 16px;
	display: flex;
	align-items: center;
	gap: 6px;
}
.cf-card-header-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 10px;
	margin-bottom: 6px;
}
.cf-card-header-row .cf-card-title { margin-bottom: 0; }
.cf-help {
	width: 16px;
	height: 16px;
	font-size: 11px;
	border-radius: 50%;
	border: 1px solid var(--cf-blue);
	color: var(--cf-blue);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: help;
	font-weight: 700;
}

/* Fields */
.cf-field { margin-bottom: 16px; }
.cf-field label {
	display: block;
	font-size: 13.5px;
	font-weight: 600;
	margin-bottom: 6px;
	color: var(--cf-dark);
}
.cf-field input[type="number"] {
	width: 100%;
	padding: 10px 12px;
	border-radius: 8px;
	border: 1px solid var(--cf-border);
	font-size: 14px;
	background: #fff;
	color: var(--cf-dark);
}
.cf-field input[type="number"]:focus,
.cf-ri-input-wrap input:focus {
	outline: none;
	border-color: var(--cf-blue);
	box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.cf-field input.cf-negative { color: var(--cf-red); font-weight: 600; }
.cf-hint { font-size: 12px; color: var(--cf-gray); margin: 6px 0 0; }
.cf-hint-center { text-align: center; }
.cf-field-label { font-size: 13.5px; font-weight: 600; margin: 0 0 10px; }

.cf-input-prefix, .cf-input-suffix-wrap {
	position: relative;
	display: flex;
	align-items: center;
}
.cf-input-prefix input, .cf-input-suffix-wrap input { padding-right: 34px; }
.cf-input-prefix .cf-suffix, .cf-input-suffix-wrap .cf-suffix {
	position: absolute;
	right: 12px;
	color: var(--cf-gray);
	font-size: 13px;
	pointer-events: none;
}
/* Native number-input spin arrows sit in the same corner as our suffix
   label ($ / %) and visually collide with it, so we hide them on any
   suffix/prefix-wrapped field and rely on manual typing instead. */
.cf-input-prefix input[type="number"]::-webkit-outer-spin-button,
.cf-input-prefix input[type="number"]::-webkit-inner-spin-button,
.cf-input-suffix-wrap input[type="number"]::-webkit-outer-spin-button,
.cf-input-suffix-wrap input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}
.cf-input-prefix input[type="number"],
.cf-input-suffix-wrap input[type="number"] {
	-moz-appearance: textfield;
	appearance: textfield;
}

/* Entries table */
.cf-entries-wrap { margin-bottom: 12px; overflow-x: auto; }
.cf-entries-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cf-entries-table thead th {
	text-align: left;
	padding: 8px 6px;
	color: var(--cf-gray);
	font-weight: 600;
	border-bottom: 1px solid var(--cf-border);
	white-space: nowrap;
}
.cf-entries-table tbody td { padding: 6px; vertical-align: middle; }
.cf-entries-table input[type="number"] {
	width: 100%;
	min-width: 70px;
	padding: 7px 8px;
	border-radius: 6px;
	border: 1px solid var(--cf-border);
	font-size: 13px;
}
.cf-entries-table .cf-amount-input { color: var(--cf-green); font-weight: 600; }
.cf-entries-table .cf-amount-input.cf-negative { color: var(--cf-red); }
.cf-period-cell { font-weight: 600; color: var(--cf-dark); white-space: nowrap; }
.cf-freq-cell { display: flex; align-items: center; gap: 6px; }
.cf-freq-cell input { max-width: 60px; }
.cf-freq-cell span { font-size: 12px; color: var(--cf-gray); white-space: nowrap; }
.cf-row-actions { display: flex; gap: 6px; }
.cf-row-btn {
	width: 28px;
	height: 28px;
	border-radius: 6px;
	border: 1px solid var(--cf-border);
	background: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
}
.cf-row-btn svg { width: 15px; height: 15px; }
.cf-row-btn-delete {
	color: var(--cf-red) !important;
	border-color: #fbd5d5;
}
.cf-row-btn-delete:hover { background: #fef2f2; border-color: var(--cf-red); }
.cf-row-actions-empty { color: var(--cf-gray); font-size: 12px; }

.cf-add-flow {
	width: 100%;
	background: none;
	border: 1px dashed var(--cf-border);
	border-radius: 8px;
	padding: 10px;
	color: var(--cf-blue) !important;
	font-weight: 600;
	font-size: 14px;
	cursor: pointer;
	margin-bottom: 6px;
}
.cf-add-flow:hover { background: #f3f6ff; }
.cf-add-flow:disabled { opacity: 0.5; cursor: not-allowed; }

.cf-actions { margin-top: 10px; }
.cf-actions-row { display: flex; gap: 10px; }
.cf-actions-row .cf-btn { flex: 1; }

.cf-error { color: var(--cf-red); font-size: 13px; margin-top: 12px; }
.cf-error[hidden] { display: none; }

/* Formulas card */
.cf-formulas-toggle,
.cf-calc-app button.cf-formulas-toggle {
	width: 100%;
	background: transparent !important;
	border: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	cursor: pointer;
	padding: 0;
	color: var(--cf-dark) !important;
}
.cf-formulas-toggle .cf-card-title,
.cf-formulas-toggle .cf-chevron {
	color: var(--cf-dark) !important;
}
.cf-formulas-toggle .cf-card-title { margin-bottom: 0; }
.cf-chevron {
	color: var(--cf-gray) !important;
	transition: transform .2s ease;
	font-size: 12px;
}
.cf-chevron.cf-collapsed { transform: rotate(180deg); }
.cf-formulas-body { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.cf-formula-intro { font-size: 13.5px; color: var(--cf-gray); margin: 0 0 4px; line-height: 1.5; }
.cf-formula-legend { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cf-formula-legend li { font-size: 13px; color: var(--cf-dark); }
.cf-formula-legend strong { color: var(--cf-blue); font-style: italic; }
.cf-formula-row {
	background: #f6f6f7;
	border-radius: 6px;
	padding: 12px 14px;
	font-size: 14px;
	color: #3a3d42;
	overflow-x: auto;
}
.cf-formula-row .katex { font-size: 1.05em; }
.cf-formula-note { color: var(--cf-gray) !important; font-size: 12px; line-height: 1.5; margin: 4px 0 0; }

/* Timeline */
.cf-timeline-toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.cf-icon-btn {
	width: 32px;
	height: 32px;
	border-radius: 8px;
	border: 1px solid var(--cf-border);
	background: #fff;
	cursor: pointer;
	color: var(--cf-gray);
	display: flex;
	align-items: center;
	justify-content: center;
}

.cf-timeline { position: relative; min-height: 280px; display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.cf-timeline-empty {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--cf-gray);
	font-size: 14px;
}
.cf-timeline-empty[hidden] { display: none; }
.cf-timeline-canvas-wrap {
	width: 100%;
	height: 280px;
	position: relative;
	overflow-x: auto;
	overflow-y: hidden;
	-webkit-overflow-scrolling: touch;
}
.cf-timeline-canvas-wrap[hidden] { display: none; }
.cf-timeline-canvas-inner { height: 100%; min-width: 100%; }
.cf-timeline-canvas-wrap canvas { width: 100% !important; height: 100% !important; }

.cf-legend { display: flex; gap: 22px; justify-content: center; margin-top: 14px; font-size: 13px; }
.cf-legend-item { display: flex; align-items: center; gap: 6px; }
.cf-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.cf-dot-orange { background: var(--cf-orange); }
.cf-dot-green { background: var(--cf-green); }

/* Results */
.cf-results-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: 12px;
}
.cf-result-item {
	border: 1px solid var(--cf-border);
	border-radius: 10px;
	padding: 14px;
}
.cf-result-label { font-size: 12.5px; color: var(--cf-gray); margin: 0 0 6px; font-weight: 600; }
.cf-result-value { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.cf-result-value .cf-unit { font-size: 12px; font-weight: 500; color: var(--cf-gray); }
.cf-result-sub { font-size: 11.5px; color: var(--cf-gray); margin: 0; }
.cf-color-blue { color: var(--cf-blue); }
.cf-color-green { color: var(--cf-green); }
.cf-color-purple { color: var(--cf-purple); }
.cf-color-orange { color: var(--cf-orange); }

/* Table */
.cf-table-wrap { position: relative; min-height: 200px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cf-table { width: 100%; border-collapse: collapse; font-size: 13.5px; white-space: nowrap; }
.cf-table thead th {
	text-align: left;
	padding: 10px 12px;
	background: #f6f6f7;
	color: #55585d;
	font-weight: 600;
	border-bottom: 1px solid var(--cf-border);
}
.cf-table tbody td, .cf-table tfoot td {
	padding: 10px 12px;
	border-bottom: 1px solid var(--cf-border);
}
.cf-table tfoot td { font-weight: 700; border-bottom: none; border-top: 2px solid var(--cf-border); }
.cf-table-wrap.has-data .cf-details-empty { display: none; }
.cf-table-wrap:not(.has-data) #cf-details-table { display: none; }

.cf-details-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 50px 20px;
	color: var(--cf-gray);
}
.cf-details-empty-icon { font-size: 26px; margin-bottom: 10px; opacity: .6; }
.cf-details-empty-title { font-weight: 600; color: var(--cf-dark); margin: 0 0 4px; }
.cf-details-empty-sub { font-size: 13px; margin: 0; }

.cf-value-positive { color: var(--cf-green); }
.cf-value-negative { color: var(--cf-red); }

.cf-footnote { text-align: center; font-size: 12.5px; color: var(--cf-gray); margin-top: 24px; }

.cf-report-wrap { display: flex; justify-content: center; margin-top: 16px; }

/* Responsive */
@media (max-width: 640px) {
	.cf-header { flex-direction: column; }
	.cf-header-actions { width: 100%; }
	.cf-header-actions .cf-btn { flex: 1; }
	.cf-card-header-row { flex-direction: column; align-items: flex-start; }
	.cf-results-grid { grid-template-columns: repeat(2, 1fr); }
	.cf-table { font-size: 12px; }
	.cf-table thead th, .cf-table tbody td { padding: 8px 6px; }
	.cf-entries-table { font-size: 12px; }
}
