.amort-calc-app {
	--amort-purple: #6d5cf6;
	--amort-purple-dark: #5b46e8;
	--amort-green: #16a34a;
	--amort-orange: #ea580c;
	--amort-blue: #2563eb;
	--amort-red: #dc2626;
	--amort-dark: #1f2328;
	--amort-gray: #6b7280;
	--amort-border: #e5e7eb;
	--amort-bg: #f7f7f8;
	--amort-card-bg: #ffffff;

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

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

/* Buttons */
.amort-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(--amort-dark);
}
.amort-btn-ghost { background: #fff; color: var(--amort-dark) !important; border-color: var(--amort-border); }
.amort-btn-ghost:hover { background: #f3f4f6; }
.amort-btn-primary { background: var(--amort-purple); color: #fff !important; }
.amort-btn-primary:hover { background: var(--amort-purple-dark); }
.amort-btn-outline { background: #fff; border-color: var(--amort-border); color: var(--amort-dark) !important; }
.amort-btn-outline:hover { background: #f3f4f6; }
.amort-btn-block { width: 100%; }
.amort-btn-report {
	background: #fff;
	color: var(--amort-gray) !important;
	border: 1px solid var(--amort-border);
	text-decoration: none;
}
.amort-btn-report:hover { background: #f9f4f0; color: var(--amort-orange) !important; border-color: var(--amort-orange); }
/* 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. */
.amort-btn-ghost:active, .amort-btn-ghost:focus,
.amort-btn-outline:active, .amort-btn-outline:focus {
	color: #fff !important;
}

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

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

/* Fields */
.amort-field { margin-bottom: 16px; }
.amort-field label {
	display: block;
	font-size: 13.5px;
	font-weight: 600;
	margin-bottom: 6px;
	color: var(--amort-dark);
}
.amort-field input[type="number"],
.amort-field input[type="date"],
.amort-field select {
	width: 100%;
	padding: 10px 12px;
	border-radius: 8px;
	border: 1px solid var(--amort-border);
	font-size: 14px;
	background: #fff;
	color: var(--amort-dark);
}
.amort-field input:focus, .amort-field select:focus {
	outline: none;
	border-color: var(--amort-purple);
	box-shadow: 0 0 0 3px rgba(109,92,246,0.15);
}

.amort-dual-input { display: grid; grid-template-columns: 1.6fr 1fr; gap: 8px; }
.amort-dual-secondary { min-width: 0; }

.amort-input-prefix, .amort-input-suffix-wrap { position: relative; display: flex; align-items: center; min-width: 0; }
.amort-input-prefix input[type="number"] { padding-left: 26px !important; }
.amort-input-suffix-wrap input[type="number"] { padding-right: 30px !important; }
.amort-input-prefix .amort-prefix {
	position: absolute;
	left: 12px;
	top: 50%;
	transform: translateY(-50%);
	color: var(--amort-gray);
	font-size: 13px;
	line-height: 1;
	pointer-events: none;
}
.amort-input-suffix-wrap .amort-suffix {
	position: absolute;
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	color: var(--amort-gray);
	font-size: 13px;
	line-height: 1;
	pointer-events: none;
}
/* Native number-input spin arrows collide with our $/% affix labels. */
.amort-input-prefix input[type="number"]::-webkit-outer-spin-button,
.amort-input-prefix input[type="number"]::-webkit-inner-spin-button,
.amort-input-suffix-wrap input[type="number"]::-webkit-outer-spin-button,
.amort-input-suffix-wrap input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}
.amort-input-prefix input[type="number"],
.amort-input-suffix-wrap input[type="number"] {
	-moz-appearance: textfield;
	appearance: textfield;
}

.amort-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.amort-error { color: var(--amort-red); font-size: 13px; margin-top: 12px; }
.amort-error[hidden] { display: none; }

/* About / Formula card */
.amort-formula-toggle,
.amort-calc-app button.amort-formula-toggle {
	width: 100%;
	background: transparent !important;
	border: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	cursor: pointer;
	padding: 0;
	color: var(--amort-dark) !important;
}
.amort-formula-toggle .amort-card-title,
.amort-formula-toggle .amort-chevron {
	color: var(--amort-purple) !important;
}
.amort-formula-toggle .amort-card-title { margin-bottom: 0; }
.amort-chevron {
	color: var(--amort-purple) !important;
	transition: transform .2s ease;
	font-size: 12px;
}
.amort-chevron.amort-collapsed { transform: rotate(180deg); }
.amort-formula-body { margin-top: 16px; }
.amort-formula-body[hidden] { display: none; }
.amort-formula-intro { font-size: 13.5px; color: var(--amort-gray); line-height: 1.6; margin: 0 0 16px; }
.amort-formula-heading { font-size: 13.5px; font-weight: 700; color: var(--amort-purple); margin: 0 0 10px; }
.amort-formula-katex {
	background: #f6f6f7;
	border-radius: 8px;
	padding: 16px;
	margin-bottom: 14px;
	overflow-x: auto;
	text-align: center;
}
.amort-formula-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.amort-formula-legend li { font-size: 13px; color: var(--amort-dark); }
.amort-formula-legend strong { color: var(--amort-purple); font-style: italic; }

/* Summary */
.amort-summary-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: 12px;
}
.amort-summary-item { border: 1px solid var(--amort-border); border-radius: 10px; padding: 14px; }
.amort-summary-icon { font-size: 16px; display: block; margin-bottom: 8px; }
.amort-summary-label { font-size: 12px; color: var(--amort-gray); margin: 0 0 6px; font-weight: 600; }
.amort-summary-value { font-size: 19px; font-weight: 700; margin: 0; }
.amort-color-purple { color: var(--amort-purple); }
.amort-color-green { color: var(--amort-green); }
.amort-color-orange { color: var(--amort-orange); }
.amort-color-blue { color: var(--amort-blue); }

.amort-info-strip {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
	gap: 12px;
	background: #f9fafb;
	border-radius: 10px;
	padding: 14px;
}
.amort-info-strip-item { text-align: center; }
.amort-info-strip-label { font-size: 11.5px; color: var(--amort-gray); margin: 0 0 4px; }
.amort-info-strip-value { font-size: 15px; font-weight: 700; color: var(--amort-dark); margin: 0; }

/* Charts */
.amort-chart-stack { display: flex; flex-direction: column; gap: 20px; }
.amort-chart-card { min-width: 0; }

.amort-icon-btn {
	width: 32px;
	height: 32px;
	border-radius: 8px;
	border: 1px solid var(--amort-border);
	background: #fff;
	cursor: pointer;
	color: var(--amort-gray);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.amort-icon-btn:hover { background: #f3f4f6; }

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

.amort-donut-wrap { position: relative; min-height: 220px; display: flex; align-items: center; justify-content: center; min-width: 0; }
.amort-donut-empty { color: var(--amort-gray); font-size: 14px; }
.amort-donut-canvas-wrap[hidden] { display: none; }
.amort-donut-canvas-wrap { position: relative; width: 100%; max-width: 220px; height: 220px; margin: 0 auto; }
.amort-donut-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
.amort-donut-center {
	position: absolute;
	top: 50%; left: 50%;
	transform: translate(-50%, -50%);
	text-align: center;
	pointer-events: none;
}
.amort-donut-center-label { display: block; font-size: 11px; color: var(--amort-gray); }
.amort-donut-center-value { display: block; font-size: 15px; font-weight: 700; color: var(--amort-dark); }
.amort-donut-legend { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.amort-donut-legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.amort-donut-legend-value { margin-left: auto; font-weight: 600; }
.amort-donut-legend-pct { color: var(--amort-gray); font-size: 12px; min-width: 40px; text-align: right; }
.amort-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.amort-dot-green { background: var(--amort-green); }
.amort-dot-orange { background: var(--amort-orange); }

/* Schedule table */
.amort-schedule-controls { display: flex; gap: 10px; align-items: center; flex-wrap: nowrap; }
.amort-view-select {
	padding: 9px 12px;
	border-radius: 8px;
	border: 1px solid var(--amort-border);
	font-size: 13.5px;
	background: #fff;
	color: var(--amort-dark);
}
.amort-table-wrap { position: relative; min-height: 200px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.amort-table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.amort-table thead th {
	text-align: left;
	padding: 10px 12px;
	background: #f6f6f7;
	color: #55585d;
	font-weight: 600;
	border-bottom: 1px solid var(--amort-border);
}
.amort-table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--amort-border); }
.amort-table-wrap.has-data .amort-schedule-empty { display: none; }
.amort-table-wrap:not(.has-data) #amort-schedule-table { display: none; }

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

.amort-pagination { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.amort-pagination[hidden] { display: none; }
.amort-pagination-info { font-size: 12.5px; color: var(--amort-gray); margin: 0; }
.amort-pagination-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.amort-page-btn {
	min-width: 32px;
	height: 32px;
	padding: 0 8px;
	border-radius: 6px;
	border: 1px solid var(--amort-border);
	background: #fff;
	color: var(--amort-dark) !important;
	font-size: 13px;
	cursor: pointer;
}
.amort-page-btn:hover { background: #f3f4f6; }
.amort-page-btn.amort-page-active { background: var(--amort-purple); border-color: var(--amort-purple); color: #fff !important; }
.amort-page-btn:disabled { opacity: .4; cursor: not-allowed; }
.amort-page-btn:active, .amort-page-btn:focus { color: #fff !important; }
.amort-page-btn.amort-page-active:active, .amort-page-btn.amort-page-active:focus { color: #fff !important; }

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

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