/* ============================================================
   JBF Solutions — Borrowing Power Calculator
   calculator.css — site-integrated, scoped version

   All component rules are scoped under .calc-page to avoid
   conflicts with the main site stylesheet (styles.css).
   Site CSS variables (--color-*, --space-*, etc.) are reused
   throughout; only calc-specific tokens are added here.
   ============================================================ */

/* ── Calc-specific tokens not in site :root ── */
.calc-page {
  --calc-primary-light: #E8F0FB;   /* pale blue — form active states, result bg */
  --calc-warning-bg:    #FFF8EC;   /* amber tint — compliance notice */
  --calc-error-bg:      #FDF2F2;   /* pale red — error input bg */
}

/* ── Utility: screen-reader only ── */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ── Calc-page field label modifiers ── */
.calc-page .optional {
  font-size: var(--text-xs);
  color: var(--color-muted);
  font-weight: 400;
}
.calc-page .required { color: var(--color-error); }

/* ── Ghost button (not in site styles.css) ── */
.btn-ghost {
  background: transparent;
  color: var(--color-muted);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
}
.btn-ghost:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

/* ============================================================
   CALCULATOR CARD
   ============================================================ */
.calc-card {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: var(--space-12);
  border: 1px solid var(--color-border);
}

/* ============================================================
   FORM STRUCTURE
   ============================================================ */
.calc-page fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

/* Override site's minimal .form-group inside calc */
.calc-page .form-group {
  margin-bottom: var(--space-12);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid var(--color-border);
}
.calc-page .form-group:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.group-legend {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary);
  padding-bottom: var(--space-4);
  margin-bottom: var(--space-4);
  border-bottom: 2px solid var(--calc-primary-light);
  width: 100%;
  display: block;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-6) var(--space-8);
}

.field-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.calc-page label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
  display: block;
}

/* ── Input styles (calc uses bare elements, not .form-input class) ── */
.calc-page input[type="text"],
.calc-page input[type="email"],
.calc-page input[type="tel"],
.calc-page input[type="number"],
.calc-page select,
.calc-page textarea {
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-white);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.875rem;
  min-height: 44px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  appearance: none;
  -webkit-appearance: none;
  line-height: 1.5;
}

.calc-page input[type="text"]:focus,
.calc-page input[type="email"]:focus,
.calc-page input[type="tel"]:focus,
.calc-page input[type="number"]:focus,
.calc-page select:focus,
.calc-page textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0,74,173,0.12);
}

.calc-page select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235f6673' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  background-color: var(--color-white);
  padding-right: 2.25rem;
  cursor: pointer;
}

.calc-page textarea { resize: vertical; min-height: 72px; }

.calc-page input.input-error,
.calc-page select.input-error,
.calc-page textarea.input-error {
  border-color: var(--color-error);
  background-color: var(--calc-error-bg);
}

.input-prefix-wrap,
.input-suffix-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prefix {
  position: absolute;
  left: 0.875rem;
  color: var(--color-muted);
  font-size: var(--text-base);
  font-weight: 600;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}

/* High-specificity override: the base rule
   .calc-page input[type="text"] sets padding: 0.75rem 0.875rem and beats a
   bare ".input-prefix-wrap input" selector on specificity, so the typed
   digits sit underneath the $ sign. We match the base rule's specificity
   and add .input-prefix-wrap to win. */
.calc-page .input-prefix-wrap input[type="text"],
.calc-page .input-prefix-wrap input[type="tel"],
.calc-page .input-prefix-wrap input[type="number"] {
  padding-left: 2.25rem;
}

.input-suffix {
  position: absolute;
  right: 0.875rem;
  color: var(--color-muted);
  font-size: var(--text-base);
  font-weight: 600;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}

.calc-page .input-suffix-wrap input[type="text"],
.calc-page .input-suffix-wrap input[type="tel"],
.calc-page .input-suffix-wrap input[type="number"] {
  padding-right: 2.5rem;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--color-muted);
  line-height: var(--leading-relaxed);
}

.field-error {
  font-size: var(--text-sm);
  color: var(--color-error);
  font-weight: 600;
  min-height: 1.2em;
  display: block;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding-top: var(--space-8);
  flex-wrap: wrap;
}

/* ============================================================
   RESULTS SECTION
   ============================================================ */
.results-section {
  padding: var(--space-8) 0;
  animation: calcFadeInUp 0.35s ease both;
}

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

.results-card {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.results-header {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: var(--color-white);
  padding: var(--space-8) var(--space-12);
}

.results-header h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: var(--color-white);
  letter-spacing: -0.01em;
}

.results-disclaimer-inline {
  font-size: var(--text-sm);
  opacity: 0.85;
  color: var(--color-white);
}

.results-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  border-bottom: 1px solid var(--color-border);
}

.result-metric {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: var(--space-8);
  border-right: 1px solid var(--color-border);
}
.result-metric:last-child { border-right: none; }
.result-metric--primary { background: var(--calc-primary-light); }

.result-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.result-value {
  font-size: var(--text-4xl);
  font-weight: 800;
  color: var(--color-primary);
  line-height: 1.1;
}

.result-value--secondary {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--color-text);
}

.result-range {
  font-size: var(--text-sm);
  color: var(--color-muted);
  font-weight: 500;
}

.results-compliance-primary {
  padding: var(--space-4) var(--space-12);
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: var(--leading-relaxed);
  background: var(--calc-warning-bg);
  border-bottom: 1px solid #F0DFA8;
}

.results-explanation {
  padding: var(--space-6) var(--space-12);
  font-size: var(--text-base);
  color: var(--color-text);
  line-height: var(--leading-relaxed);
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
}

.results-explanation p { margin-bottom: var(--space-4); }
.results-explanation p:last-child { margin-bottom: 0; }

.assumptions-disclosure { border-bottom: 1px solid var(--color-border); }

.assumptions-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-4) var(--space-12);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  transition: background var(--t-fast);
  list-style: none;
}
.assumptions-trigger::-webkit-details-marker { display: none; }
.assumptions-trigger::marker { display: none; content: ''; }
.assumptions-trigger:hover { background: var(--calc-primary-light); }
.assumptions-trigger:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: -3px;
}

details[open] .chevron { transform: rotate(180deg); }
.chevron { transition: transform var(--t-fast); display: inline-block; }

.assumptions-body {
  padding: var(--space-4) var(--space-12) var(--space-6);
  font-size: 0.8375rem;
  color: var(--color-muted);
  line-height: var(--leading-relaxed);
  background: var(--color-surface);
}
.assumptions-body ul { margin-top: var(--space-3); padding-left: var(--space-6); }
.assumptions-body li { margin-bottom: 0.3rem; }

.results-compliance-note {
  padding: var(--space-4) var(--space-12);
  font-size: var(--text-xs);
  color: var(--color-muted);
  line-height: var(--leading-relaxed);
  background: var(--color-surface);
}

/* ============================================================
   LEAD / ENQUIRY SECTION
   ============================================================ */
.lead-section { padding: var(--space-8) 0 var(--space-16); }

.lead-card {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: 1fr 2fr;
  overflow: hidden;
  animation: calcFadeInUp 0.35s ease both;
}

.lead-intro {
  background: var(--calc-primary-light);
  padding: var(--space-12);
  border-right: 1px solid var(--color-border);
}

.lead-intro h2 {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-4);
  line-height: var(--leading-snug);
}

.lead-intro p {
  font-size: var(--text-base);
  color: var(--color-muted);
  line-height: var(--leading-relaxed);
  margin-bottom: var(--space-4);
}

.lead-response-time {
  font-size: var(--text-sm) !important;
  font-weight: 600;
  color: var(--color-accent-hover) !important;
  background: rgba(0,191,99,0.08);
  border-left: 3px solid var(--color-accent);
  padding: 0.5rem var(--space-3) !important;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: var(--space-6) !important;
  display: block;
}

.lead-trust-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}
.lead-trust-list li {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  padding-left: 1.5rem;
  position: relative;
}
.lead-trust-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--color-accent);
  font-weight: 700;
}

.lead-commission-note {
  font-size: var(--text-xs) !important;
  color: var(--color-muted) !important;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3) !important;
  margin-top: var(--space-4) !important;
  margin-bottom: 0 !important;
  line-height: var(--leading-relaxed);
}

.lead-form { padding: var(--space-12); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}

.lead-form-actions {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  flex-wrap: wrap;
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
}

.lead-privacy-note {
  font-size: var(--text-xs);
  color: var(--color-muted);
  margin-top: var(--space-4);
  line-height: var(--leading-relaxed);
}

/* Success state */
.lead-success {
  padding: var(--space-16) var(--space-12);
  text-align: center;
  grid-column: 1 / -1;
  animation: calcFadeInUp 0.3s ease both;
}

.success-icon {
  width: 56px; height: 56px;
  background: var(--color-accent);
  color: var(--color-white);
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-2xl);
  font-weight: 700;
  margin: 0 auto var(--space-6);
}

.lead-success h3 {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-3);
}

.lead-success p {
  font-size: var(--text-base);
  color: var(--color-muted);
  max-width: 480px;
  margin: 0 auto var(--space-3);
  line-height: var(--leading-relaxed);
}

/* ============================================================
   SUPPORTING CONTENT SECTIONS
   ============================================================ */
.content-sections {
  padding: var(--space-8) 0 var(--space-16);
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
}

.content-block {
  margin-bottom: var(--space-16);
  padding-bottom: var(--space-16);
  border-bottom: 1px solid var(--color-border);
}
.content-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.content-block h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-4);
  line-height: var(--leading-snug);
  letter-spacing: -0.01em;
}

.content-block h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-3);
}

.content-block p {
  font-size: var(--text-base);
  color: var(--color-muted);
  line-height: var(--leading-relaxed);
  margin-bottom: var(--space-4);
}
.content-block p:last-child { margin-bottom: 0; }
.content-block strong { font-weight: 600; color: var(--color-text); }

.content-list {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.content-list li {
  font-size: var(--text-base);
  color: var(--color-muted);
  line-height: var(--leading-relaxed);
}
ol.content-list { list-style: decimal; }
ul.content-list { list-style: disc; }

ul.checklist { list-style: none; padding-left: 0; }
ul.checklist li { padding-left: 1.75rem; position: relative; }
ul.checklist li::before {
  content: '☐';
  position: absolute;
  left: 0;
  color: var(--color-primary);
}

.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-12);
  margin-top: var(--space-6);
}

/* Worked example block */
.example-block {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  padding: var(--space-12);
  box-shadow: var(--shadow-sm);
}

.example-label {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-accent-hover);
  background: var(--color-accent-light);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  margin-bottom: var(--space-3);
}

.example-table-wrap {
  overflow-x: auto;
  margin: var(--space-6) 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.example-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.example-table th {
  background: var(--color-primary);
  color: var(--color-white);
  font-weight: 600;
  padding: 0.75rem 1rem;
  text-align: left;
}
.example-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-muted);
  vertical-align: top;
  line-height: var(--leading-normal);
}
.example-table tr:last-child td { border-bottom: none; }
.example-table tr:nth-child(even) td { background: var(--color-surface); }
.example-table td:first-child { font-weight: 600; color: var(--color-text); }

.example-note {
  font-size: var(--text-xs);
  color: var(--color-muted);
  font-style: italic;
  margin-top: var(--space-4);
}

/* ============================================================
   CALC FAQ (overrides site's max-height animation approach;
   uses aria-expanded + hidden-attribute model instead)
   ============================================================ */
.calc-page .faq-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: var(--space-6);
}

/* Neutralise site's max-height transition on these FAQ items */
.calc-page .faq-answer {
  max-height: none !important;
  overflow: visible;
  padding: 0;
  transition: none;
}

.calc-page .faq-answer:not([hidden]) {
  padding: 0 var(--space-8) var(--space-6);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.calc-page .faq-item { border-bottom: 1px solid var(--color-border); }
.calc-page .faq-item:last-child { border-bottom: none; }

.calc-page .faq-question {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-8);
  text-align: left;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-white);
  border: none;
  cursor: pointer;
  transition: background var(--t-fast);
  min-height: 44px;
}
.calc-page .faq-question:hover { background: var(--calc-primary-light); color: var(--color-primary); }
.calc-page .faq-question[aria-expanded="true"] {
  color: var(--color-primary);
  background: var(--calc-primary-light);
}
.calc-page .faq-question[aria-expanded="true"] .faq-chevron { transform: rotate(180deg); }
.calc-page .faq-question:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: -3px;
}

.faq-chevron {
  flex-shrink: 0;
  color: var(--color-primary);
  font-size: 0.75rem;
  transition: transform var(--t-fast);
}

/* ============================================================
   FINAL CTA BLOCK
   ============================================================ */
.final-cta-block {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  border-radius: var(--radius-xl);
  padding: var(--space-12) var(--space-16);
  color: var(--color-white);
  text-align: center;
  border-bottom: none !important;
  margin-bottom: 0 !important;
  padding-bottom: var(--space-12) !important;
}

.final-cta-block h2 {
  color: var(--color-white) !important;
  font-size: var(--text-3xl);
  margin-bottom: var(--space-4);
}

.final-cta-block p {
  color: rgba(255,255,255,0.85) !important;
  max-width: 600px;
  margin: 0 auto var(--space-8);
  font-size: var(--text-base);
}

.final-cta-actions {
  display: flex;
  gap: var(--space-4);
  justify-content: center;
  flex-wrap: wrap;
}

.final-cta-block .btn-outline {
  border-color: rgba(255,255,255,0.7);
  color: var(--color-white);
}
.final-cta-block .btn-outline:hover {
  background: rgba(255,255,255,0.15);
  color: var(--color-white);
  border-color: var(--color-white);
}

/* ============================================================
   MOBILE STICKY CTA
   ============================================================ */
.mobile-sticky-cta {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 90;
  padding: var(--space-3) var(--space-6) calc(var(--space-3) + env(safe-area-inset-bottom));
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.10);
  transform: translateY(110%);
  transition: transform 0.3s ease;
  display: none;
}

@media (max-width: 720px) {
  .mobile-sticky-cta { display: block; transform: translateY(110%); }
  .mobile-sticky-cta.visible { transform: translateY(0); }
  body.has-sticky-cta { padding-bottom: 80px; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .lead-card { grid-template-columns: 1fr; }
  .lead-intro { border-right: none; border-bottom: 1px solid var(--color-border); }
  .results-grid { grid-template-columns: 1fr; }
  .result-metric { border-right: none; border-bottom: 1px solid var(--color-border); }
  .result-metric:last-child { border-bottom: none; }
  .two-col-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .calc-card { padding: var(--space-6); border-radius: var(--radius-lg); }
  .form-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { width: 100%; justify-content: center; }

  .results-header { padding: var(--space-6); }
  .result-metric { padding: var(--space-6); }
  .results-explanation { padding: var(--space-4) var(--space-6); }
  .results-compliance-primary { padding: var(--space-4) var(--space-6); }
  .assumptions-trigger { padding: var(--space-4) var(--space-6); }
  .assumptions-body { padding: var(--space-4) var(--space-6); }
  .results-compliance-note { padding: var(--space-4) var(--space-6); }

  .lead-intro { padding: var(--space-6); }
  .lead-form { padding: var(--space-6); }
  .lead-form-actions { flex-direction: column; }
  .lead-form-actions .btn { width: 100%; justify-content: center; }

  .final-cta-block { padding: var(--space-8) var(--space-6) !important; }
  .final-cta-block h2 { font-size: var(--text-2xl); }

  .result-value { font-size: var(--text-3xl); }
  .result-value--secondary { font-size: var(--text-2xl); }

  .calc-page .faq-question { padding: var(--space-4) var(--space-6); font-size: var(--text-sm); }
  .calc-page .faq-answer:not([hidden]) { padding: 0 var(--space-6) var(--space-4); }

  .content-block { margin-bottom: var(--space-12); padding-bottom: var(--space-12); }
  .content-block h2 { font-size: var(--text-xl); }
  .example-block { padding: var(--space-6); }
  .content-sections { padding: var(--space-6) 0 var(--space-12); }
}

@media (max-width: 480px) {
  .results-header { padding: var(--space-4); }
  .result-value { font-size: var(--text-2xl); }
  .result-value--secondary { font-size: var(--text-xl); }
}
