/* SWG Mortgage Analyzer — Frontend Styles
   Light theme, electric blue (#38A8D8) accent, mobile-first. */

.swgma-app {
	--swg-bg: #ffffff;
	--swg-surface: #f7f9fa;
	--swg-surface-hover: #eef2f5;
	--swg-line: #e1e5ea;
	--swg-text: #1d2327;
	--swg-muted: #6b7280;
	--swg-accent: #38A8D8;
	--swg-accent-soft: rgba(56, 168, 216, 0.12);
	--swg-accent-dark: #1d6588;
	--swg-success: #10b981;
	--swg-error: #d63638;
	--swg-warning: #f0a142;

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif;
	color: var(--swg-text);
	line-height: 1.5;
	background: var(--swg-bg);
	max-width: 1100px;
	margin: 0 auto;
	box-sizing: border-box;
	/* v1.1.1 fix — defensive containment so any rogue child can't push the
	   document body wider than the viewport on small screens (375px QA showed
	   ~5px overflow at the body level even though calculator content fit). */
	overflow-x: hidden;
}
.swgma-app, .swgma-app * { max-width: 100%; }

.swgma-app *, .swgma-app *::before, .swgma-app *::after { box-sizing: border-box; }

/* Form */
.swgma-form { background: var(--swg-surface); border: 1px solid var(--swg-line); border-radius: 8px; padding: 24px; }
/* Form / section titles use accent-dark per the agency Visual & semantic standard.
   --swg-accent-dark passes WCAG AA (5.4:1 on white). Pure --swg-accent (2.8:1) does not. */
.swgma-form__title { margin: 0 0 16px; font-size: 22px; font-weight: 700; color: var(--swg-accent-dark); }
.swgma-form__title.is-h1 { font-size: 28px; }
.swgma-form__title.is-h3 { font-size: 18px; }
.swgma-form__title.is-h4 { font-size: 16px; }
.swgma-field { margin-bottom: 16px; }
.swgma-field label, .swgma-field-label { display: block; font-size: 14px; font-weight: 600; color: var(--swg-text); margin-bottom: 6px; }
.swgma-field input[type="text"],
.swgma-field input[type="email"],
.swgma-field input[type="tel"],
.swgma-field input[type="url"],
.swgma-field input[type="number"],
.swgma-field select,
.swgma-field textarea {
	width: 100%;
	padding: 10px 12px;
	font-size: 16px;
	color: var(--swg-text);
	background: var(--swg-bg);
	border: 1px solid var(--swg-line);
	border-radius: 6px;
	font-family: inherit;
	line-height: 1.4;
}
.swgma-field textarea { resize: vertical; max-height: 240px; }
.swgma-field input:focus, .swgma-field select:focus, .swgma-field textarea:focus {
	outline: none;
	border-color: var(--swg-accent);
	box-shadow: 0 0 0 3px var(--swg-accent-soft);
}
.swgma-field.has-error input,
.swgma-field.has-error select,
.swgma-field.has-error textarea { border-color: var(--swg-error); }
.swgma-field-help { margin: 6px 0 0; font-size: 13px; color: var(--swg-muted); }
.swgma-field-error { margin: 6px 0 0; font-size: 13px; color: var(--swg-error); display: none; }
.swgma-field-error.is-shown { display: block; }
.swgma-required { color: var(--swg-error); }

.swgma-input-with-prefix, .swgma-input-with-suffix {
	display: flex; align-items: stretch; border: 1px solid var(--swg-line); border-radius: 6px; background: var(--swg-bg); overflow: hidden;
}
.swgma-input-with-prefix input, .swgma-input-with-suffix input {
	border: none !important; box-shadow: none !important; flex: 1; min-width: 0; background: transparent;
}
.swgma-input-prefix, .swgma-input-suffix { padding: 0 12px; display: flex; align-items: center; background: var(--swg-surface); color: var(--swg-muted); font-weight: 600; font-size: 14px; }
.swgma-input-prefix { border-right: 1px solid var(--swg-line); }
.swgma-input-suffix { border-left: 1px solid var(--swg-line); }
.swgma-input-with-prefix:focus-within, .swgma-input-with-suffix:focus-within { border-color: var(--swg-accent); box-shadow: 0 0 0 3px var(--swg-accent-soft); }

.swgma-field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .swgma-field-pair { grid-template-columns: 1fr; gap: 0; } }

.swgma-fieldset { margin-top: 16px; padding: 12px 16px; border: 1px solid var(--swg-line); border-radius: 6px; background: var(--swg-bg); }
.swgma-fieldset summary { font-weight: 600; cursor: pointer; padding: 4px 0; }
.swgma-fieldset[open] summary { margin-bottom: 12px; }

.swgma-radio-group { display: flex; flex-wrap: wrap; gap: 8px; }
.swgma-radio-card { flex: 1 1 30%; min-width: 100px; padding: 12px; border: 2px solid var(--swg-line); border-radius: 8px; cursor: pointer; background: var(--swg-bg); transition: border-color 0.15s, background 0.15s; }
/* Active state is JS-managed (.is-active class scoped to the form) so multiple
   instances of the same shortcode on one page don't all light up at once. */
.swgma-radio-card.is-active { border-color: var(--swg-accent); background: var(--swg-accent-soft); }
.swgma-radio-card input { display: none; }
.swgma-radio-card__label { display: block; font-size: 14px; font-weight: 600; }
.swgma-radio-pill { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 2px solid var(--swg-line); border-radius: 999px; cursor: pointer; }
.swgma-radio-pill.is-active { border-color: var(--swg-accent); background: var(--swg-accent-soft); }
.swgma-radio-pill input { display: none; }

.swgma-form__actions { margin-top: 20px; }
.swgma-button { padding: 12px 20px; font-size: 16px; font-weight: 600; border: none; border-radius: 6px; cursor: pointer; font-family: inherit; transition: background 0.15s, transform 0.05s; min-height: 44px; }
/* Primary buttons use accent-dark for WCAG AA compliance — white-on-#38A8D8 fails (2.6:1);
   white-on-#1d6588 passes (5.4:1). Hover stays slightly darker. */
.swgma-button--primary, .swgma-button--accent { background: var(--swg-accent-dark); color: #ffffff; }
.swgma-button--primary:hover, .swgma-button--accent:hover { background: #154e6c; }
.swgma-button:active { transform: translateY(1px); }
.swgma-button:disabled { opacity: 0.6; cursor: not-allowed; }
.swgma-button.is-loading { position: relative; color: transparent !important; }
.swgma-button.is-loading::after {
	content: ''; position: absolute; top: 50%; left: 50%; width: 16px; height: 16px;
	margin-top: -8px; margin-left: -8px; border: 2px solid #ffffff; border-top-color: transparent;
	border-radius: 50%; animation: swgma-spin 0.8s linear infinite;
}
@keyframes swgma-spin { to { transform: rotate(360deg); } }

@media (max-width: 600px) { .swgma-button { width: 100%; } }

/* Result block */
.swgma-result { margin-top: 24px; background: var(--swg-bg); border: 1px solid var(--swg-line); border-radius: 8px; padding: 24px; }
.swgma-result__hero { text-align: center; margin-bottom: 20px; }
.swgma-result__hero-amount { font-size: 48px; font-weight: 700; line-height: 1.1; color: var(--swg-text); }
.swgma-result__hero-caption { font-size: 14px; color: var(--swg-muted); margin-top: 4px; }
@media (max-width: 600px) { .swgma-result__hero-amount { font-size: 32px; } }

.swgma-piti-bar { display: flex; height: 24px; border-radius: 4px; overflow: hidden; background: var(--swg-line); margin: 16px 0 8px; }
.swgma-piti-bar__seg { height: 100%; }
.swgma-piti-bar__seg--principal { background: var(--swg-accent); }
.swgma-piti-bar__seg--interest { background: #2c8fbb; }
.swgma-piti-bar__seg--tax { background: var(--swg-success); }
.swgma-piti-bar__seg--insurance { background: var(--swg-warning); }
.swgma-piti-bar__seg--hoa { background: var(--swg-muted); }
.swgma-piti-bar__seg--pmi { background: var(--swg-error); }
.swgma-piti-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--swg-muted); }
.swgma-piti-legend__item { display: flex; align-items: center; gap: 6px; }
.swgma-piti-legend__swatch { width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }

.swgma-result-rows { width: 100%; border-collapse: collapse; margin: 16px 0; }
.swgma-result-rows td { padding: 8px 0; border-bottom: 1px solid var(--swg-line); }
.swgma-result-rows td:last-child { text-align: right; font-weight: 600; }
.swgma-result-rows tr.swgma-total td { font-weight: 700; padding-top: 12px; }

.swgma-inputs-echo { font-size: 13px; color: var(--swg-muted); padding: 12px; background: var(--swg-surface); border-radius: 6px; }
.swgma-detail-toggle { background: none; border: none; color: var(--swg-accent-dark); cursor: pointer; padding: 8px 0; font-size: 14px; font-weight: 600; }
.swgma-detail-panel { padding: 12px; background: var(--swg-surface); border-radius: 6px; margin-top: 8px; font-size: 14px; }

.swgma-disclaimer { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--swg-line); font-size: 12px; color: var(--swg-muted); line-height: 1.5; }

.swgma-warning-panel { margin: 12px 0; padding: 12px; background: rgba(240, 161, 66, 0.1); border-left: 4px solid var(--swg-warning); border-radius: 4px; font-size: 14px; }

/* Comparison table */
.swgma-comparison-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.swgma-comparison-table th, .swgma-comparison-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--swg-line); }
.swgma-comparison-table th { background: var(--swg-surface); font-weight: 600; font-size: 13px; }
.swgma-comparison-table tr.is-highlighted td { background: var(--swg-accent-soft); border-left: 3px solid var(--swg-accent); }
@media (max-width: 700px) {
	.swgma-comparison-table thead { display: none; }
	.swgma-comparison-table, .swgma-comparison-table tbody, .swgma-comparison-table tr, .swgma-comparison-table td { display: block; width: 100%; }
	.swgma-comparison-table tr { border: 1px solid var(--swg-line); border-radius: 6px; margin-bottom: 12px; padding: 8px; }
	.swgma-comparison-table td { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--swg-line); }
	.swgma-comparison-table td:last-child { border-bottom: none; }
	.swgma-comparison-table td::before { content: attr(data-label); font-weight: 600; color: var(--swg-muted); }
}

.swgma-term-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.swgma-term-card { padding: 16px; background: var(--swg-surface); border: 1px solid var(--swg-line); border-radius: 8px; }
.swgma-term-card__title { font-weight: 700; font-size: 16px; color: var(--swg-text); margin-bottom: 8px; }
.swgma-term-card__amount { font-size: 28px; font-weight: 700; color: var(--swg-accent); }
@media (max-width: 600px) { .swgma-term-grid { grid-template-columns: 1fr; } }

.swgma-callouts { margin: 16px 0; padding: 12px; background: var(--swg-surface); border-radius: 6px; font-size: 14px; }
.swgma-callouts ul { margin: 0; padding-left: 18px; }

/* Affordability bar */
.swgma-dti-bar { display: flex; height: 24px; border-radius: 4px; overflow: hidden; margin: 12px 0; background: var(--swg-line); }
.swgma-dti-bar__debts { background: var(--swg-error); height: 100%; }
.swgma-dti-bar__debts.is-medium { background: var(--swg-warning); }
.swgma-dti-bar__debts.is-low { background: var(--swg-success); }
.swgma-dti-bar__avail { background: var(--swg-accent); height: 100%; }

/* Tabs */
.swgma-tabs { display: flex; border-bottom: 1px solid var(--swg-line); overflow-x: auto; margin-bottom: 16px; }
.swgma-tab { padding: 12px 16px; background: none; border: none; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600; color: var(--swg-muted); border-bottom: 2px solid transparent; white-space: nowrap; transition: color 0.15s, border-color 0.15s; }
.swgma-tab:hover { color: var(--swg-text); }
.swgma-tab.is-active { color: var(--swg-accent-dark); border-bottom-color: var(--swg-accent-dark); }

/* Lead form / CTA */
.swgma-lead-cta { margin-top: 24px; padding: 20px; background: var(--swg-accent-soft); border: 1px solid var(--swg-accent); border-radius: 8px; text-align: center; }
.swgma-lead-cta h3 { margin: 0 0 8px; font-size: 18px; font-weight: 700; }
.swgma-lead-cta p { margin: 0 0 16px; }

.swgma-lead-form-wrap { margin-top: 16px; padding: 24px; background: var(--swg-surface); border: 1px solid var(--swg-line); border-radius: 8px; }
.swgma-lead-form h3 { margin-top: 0; }
.swgma-disclaimer-block { margin: 16px 0; padding: 12px; background: var(--swg-bg); border-radius: 4px; font-size: 13px; color: var(--swg-muted); line-height: 1.5; }
.swgma-consent { background: var(--swg-bg); padding: 12px; border-radius: 4px; }
.swgma-consent-label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.swgma-consent-label input { margin-top: 4px; }
.swgma-honeypot { position: absolute !important; left: -9999px !important; top: auto !important; width: 1px !important; height: 1px !important; overflow: hidden !important; }
.swgma-lead-thanks { padding: 24px; text-align: center; background: var(--swg-bg); border-radius: 6px; }
.swgma-success-icon { width: 48px; height: 48px; line-height: 48px; margin: 0 auto 12px; border-radius: 50%; background: var(--swg-success); color: #ffffff; font-size: 24px; font-weight: 700; }

.swgma-coming-soon { padding: 32px 24px; background: var(--swg-surface); border: 1px dashed var(--swg-line); border-radius: 8px; text-align: center; color: var(--swg-muted); }

/* Mobile sticky CTA (v1.1.0) — once a calculator result has been shown on a
   small screen, the lead-capture CTA pins to the bottom of the viewport so
   it stays in reach while the visitor scrolls the result. JS toggles
   .is-sticky-mobile on the .swgma-lead-cta element after first result. */
@media (max-width: 768px) {
	.swgma-lead-cta.is-sticky-mobile { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 9000; box-shadow: 0 6px 24px rgba(29, 101, 136, 0.25); padding: 12px 16px; margin: 0; }
	.swgma-lead-cta.is-sticky-mobile h3 { font-size: 15px; margin: 0 0 6px; }
	.swgma-lead-cta.is-sticky-mobile p { display: none; }
	.swgma-lead-cta.is-sticky-mobile .swgma-cta-button { width: 100%; min-height: 44px; }
	.swgma-lead-cta.is-sticky-mobile .swgma-sticky-close { position: absolute; top: 6px; right: 8px; background: none; border: none; padding: 4px 8px; font-size: 18px; line-height: 1; color: var(--swg-muted); cursor: pointer; }
	.swgma-lead-cta.is-sticky-mobile .swgma-sticky-close:hover { color: var(--swg-text); }
	body.swgma-has-sticky-cta { padding-bottom: 80px; }
}

.swgma-muted { color: var(--swg-muted); }
.swgma-result-error { padding: 16px; background: rgba(214, 54, 56, 0.1); border-left: 4px solid var(--swg-error); border-radius: 4px; color: var(--swg-error); margin: 16px 0; }
