:root {
  --color-primary: #176b3a;
  --color-primary-dark: #14532d;
  --color-primary-soft: #eaf5ee;
  --color-page: #f4f8f5;
  --color-surface: #ffffff;
  --color-text: #1f2937;
  --color-text-soft: #667085;
  --color-border: #d6e2d9;
  --color-danger: #b42318;
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --shadow-soft: 0 10px 30px rgba(20, 83, 45, 0.07);
}

body {
  min-height: 100vh;
  color: var(--color-text);
  background: var(--color-page);
}

.site-header {
  color: #fff;
  background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary));
}

.site-header .lead {
  max-width: 46rem;
  color: rgba(255, 255, 255, 0.82);
  font-size: 1.05rem;
}

.site-header-content {
  display: grid;
  grid-template-areas:
    "eyebrow language"
    "title language"
    "lead language";
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1.5rem;
  row-gap: 0.35rem;
  align-items: start;
}

.site-header-topline {
  display: contents;
}

.site-header-topline .eyebrow {
  grid-area: eyebrow;
  margin-bottom: 0;
}

.site-header .display-6 { grid-area: title; }
.site-header .lead { grid-area: lead; }

.language-switcher {
  grid-area: language;
  width: 11rem;
  flex: 0 0 auto;
}

.language-switcher .form-label {
  margin-bottom: 0.35rem;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.78rem;
}

.eyebrow,
.section-kicker {
  display: block;
  margin-bottom: 0.35rem;
  color: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-kicker { color: var(--color-primary); }

.surface-card {
  padding: 1.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.section-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.5rem;
}

.section-heading h2 {
  margin: 0;
  color: var(--color-primary-dark);
  font-size: 1.4rem;
  font-weight: 700;
}

.section-description {
  margin: 0.35rem 0 0;
  color: var(--color-text-soft);
}

.form-label,
legend.form-label {
  color: var(--color-text);
  font-weight: 600;
}

.form-control,
.form-select,
.input-group-text {
  min-height: 2.75rem;
  border-color: var(--color-border);
}

.form-control:focus,
.form-select:focus,
.btn:focus-visible,
.selection-card:focus-visible,
.installments-table-wrap:focus-visible {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 0.25rem rgba(23, 107, 58, 0.18);
}

.input-group-text {
  color: var(--color-text-soft);
  background: #f8faf8;
}

.btn-primary {
  --bs-btn-bg: var(--color-primary);
  --bs-btn-border-color: var(--color-primary);
  --bs-btn-hover-bg: var(--color-primary-dark);
  --bs-btn-hover-border-color: var(--color-primary-dark);
  --bs-btn-active-bg: var(--color-primary-dark);
  --bs-btn-active-border-color: var(--color-primary-dark);
}

.btn-outline-primary {
  --bs-btn-color: var(--color-primary);
  --bs-btn-border-color: var(--color-primary);
  --bs-btn-hover-bg: var(--color-primary);
  --bs-btn-hover-border-color: var(--color-primary);
}

.selection-card {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1rem;
  color: var(--color-text-soft);
  cursor: pointer;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.selection-card:hover { border-color: var(--color-primary); }

.btn-check:checked + .selection-card {
  color: var(--color-primary-dark);
  background: var(--color-primary-soft);
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}

.btn-check:focus-visible + .selection-card {
  box-shadow: 0 0 0 0.25rem rgba(23, 107, 58, 0.18);
}

.selection-title {
  color: var(--color-primary-dark);
  font-weight: 700;
}

.financing-config-grid {
  align-items: flex-start;
}

.financing-config-field {
  min-width: 0;
}

.field-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.field-header .form-label {
  min-width: 0;
  margin-bottom: 0;
}

.field-label-with-action {
  display: inline-flex;
  min-width: 0;
  align-items: baseline;
  gap: 0.4rem;
}

.field-header-actions {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 0.82rem;
  white-space: nowrap;
}

.tr-action-button {
  font-size: inherit;
  text-decoration: none;
}

.tr-action-button:hover,
.tr-action-button:focus-visible {
  text-decoration: underline;
}

.field-header a,
.field-header .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.required-marker {
  color: var(--bs-danger);
  margin-left: 0.15rem;
}

.info-icon-button {
  display: inline-grid;
  width: 1.35rem;
  height: 1.35rem;
  flex: 0 0 auto;
  place-items: center;
  color: var(--color-primary);
  background: var(--color-primary-soft);
  border: 1px solid #b9d9c4;
  border-radius: 50%;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
}

.info-icon-button:hover,
.info-icon-button:focus-visible {
  color: #fff;
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.info-icon-button:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 0.25rem rgba(23, 107, 58, 0.18);
}

.correction-rate-group {
  flex-wrap: nowrap;
}

.correction-rate-group .form-control {
  min-width: 5.5rem;
}

.correction-rate-group .btn {
  white-space: nowrap;
}

.empty-state {
  padding: 1.5rem;
  color: var(--color-text-soft);
  text-align: center;
  background: #fafcfb;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
}

.empty-icon {
  display: grid;
  width: 2rem;
  height: 2rem;
  margin: 0 auto 0.65rem;
  place-items: center;
  color: var(--color-primary);
  background: var(--color-primary-soft);
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: 700;
}

.extra-card {
  padding: 1rem;
  background: #fbfdfb;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.extra-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.8rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.extra-card-header h3 {
  display: inline;
  margin: 0 0 0 0.45rem;
  color: var(--color-primary-dark);
  font-size: 1rem;
}

.extra-number {
  display: inline-grid;
  width: 1.55rem;
  height: 1.55rem;
  place-items: center;
  color: #fff;
  background: var(--color-primary);
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
}

.stat-card {
  height: 100%;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

.stat-card.primary {
  color: #fff;
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}

.stat-card.positive {
  color: var(--color-primary-dark);
  background: var(--color-primary-soft);
  border-color: #b9d9c4;
}

.stat-label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--color-text-soft);
  font-size: 0.82rem;
}

.stat-card.primary .stat-label { color: rgba(255, 255, 255, 0.72); }
.stat-value { display: block; font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.comparison-table th:not(:first-child),
.comparison-table td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }

.comparison-highlights {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.highlight-pill {
  padding: 0.55rem 0.8rem;
  color: var(--color-primary-dark);
  background: var(--color-primary-soft);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
}

.chart-panel h3 {
  margin: 0 0 0.75rem;
  color: var(--color-primary-dark);
  font-size: 1rem;
  font-weight: 700;
}

.chart-wrap {
  position: relative;
  height: 22rem;
}

.chart-wrap canvas {
  width: 100%;
  height: 100%;
}

.chart-print-image {
  display: none;
  width: 100%;
  height: auto;
}

.table-controls {
  padding: 1rem;
  margin-bottom: 1rem;
  background: #f8faf8;
  border-radius: var(--radius-md);
}

.installments-table-wrap {
  max-height: 38rem;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.installments-table {
  min-width: 1580px;
  font-variant-numeric: tabular-nums;
}

.installments-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding-block: 0.8rem;
  color: var(--color-primary-dark);
  white-space: nowrap;
  background: #edf4ef;
  box-shadow: inset 0 -1px var(--color-border);
}

.installments-table th,
.installments-table td { white-space: nowrap; }
.installments-table td:nth-child(n + 3):nth-child(-n + 13) { text-align: right; }
.installments-table tr.has-extra > * { background: var(--color-primary-soft); }

.print-table-brand-row,
.print-table-title-row {
  display: none;
}

.goal-badge {
  color: var(--color-primary-dark);
  background: #d6eadc;
  border: 1px solid #b9d9c4;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
}

.estimate-notice {
  padding: 1rem 1.25rem;
  color: #4b5563;
  text-align: justify;
  background: #eef3ef;
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.print-only {
  display: none;
}

.print-report-root {
  display: none;
}

.invalid-feedback { color: var(--color-danger); }

@media (min-width: 768px) {
  .surface-card { padding: 1.5rem; }

  .field-header {
    min-height: 3rem;
    align-items: flex-start;
  }
}

@media (min-width: 1200px) {
  .financing-config-field-wide {
    flex: 0 0 40%;
    max-width: 40%;
    width: 40%;
  }
}

@media (max-width: 767.98px) {
  .site-header .container {
    padding-top: 1.1rem !important;
    padding-bottom: 1.25rem !important;
  }

  .section-heading,
  .pagination-bar { align-items: stretch; flex-direction: column; }

  .site-header-content {
    grid-template-areas:
      "eyebrow language"
      "title title"
      "lead lead";
    column-gap: 0.75rem;
    row-gap: 0.55rem;
    align-items: center;
  }

  .site-header-topline .eyebrow {
    margin-top: 0;
  }

  .language-switcher {
    width: 8.75rem;
    min-width: 0;
  }

  .language-switcher .form-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .language-switcher .form-select {
    min-height: 2.15rem;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
    font-size: 0.86rem;
  }

  .site-header .lead {
    font-size: 0.98rem;
  }

  .section-heading .btn { width: 100%; }

  .section-actions {
    width: 100%;
  }

  .section-actions .btn {
    flex: 1 1 0;
  }

  .charts-grid { grid-template-columns: 1fr; }
  .chart-wrap { height: 18rem; }
  .surface-card { padding: 1rem; }
  .site-header .display-6 { font-size: 1.9rem; }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  *,
  *::before,
  *::after {
    box-shadow: none !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body {
    color: #111827;
    background: #fff;
  }

  body > :not(#print-report-root) {
    display: none !important;
  }

  #print-report-root {
    display: block !important;
  }

  .print-report-header {
    position: relative;
    z-index: 2;
    display: flex !important;
    align-items: center;
    gap: 1rem;
    min-height: 4.75rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    color: #fff;
    background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary));
    border-radius: 0.5rem;
    break-after: avoid;
    break-inside: avoid;
  }

  .print-report-logo {
    width: 3.25rem;
    height: 3.25rem;
    flex: 0 0 auto;
    padding: 0.35rem;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, 0.85);
    object-fit: contain;
    border-radius: 0.55rem;
  }

  .print-report-header h2 {
    margin: 0;
    color: inherit;
    font-size: 1.45rem;
    font-weight: 700;
  }

  #summary-grid {
    display: none !important;
  }

  .surface-card {
    padding: 0;
    margin-bottom: 1rem !important;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  .section-heading {
    margin-bottom: 0.75rem;
    break-after: avoid;
  }

  .section-heading h2 {
    font-size: 1.1rem;
  }

  .section-kicker {
    font-size: 0.65rem;
  }

  .stat-card,
  .comparison-table,
  .estimate-notice {
    break-inside: avoid;
  }

  .stat-card {
    padding: 0.75rem;
    border-color: #d1d5db;
  }

  .stat-card.primary {
    color: #111827;
    background: #f3f4f6;
    border-color: #d1d5db;
  }

  .stat-card.primary .stat-label {
    color: #4b5563;
  }

  .charts-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    break-inside: auto;
  }

  .chart-wrap {
    width: 100%;
    height: auto;
    overflow: visible;
  }

  .chart-panel {
    flex: 1 1 calc(50% - 0.25rem);
    max-width: calc(50% - 0.25rem);
    min-width: 0;
    overflow: visible;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .chart-panel h3 {
    margin-bottom: 0.35rem;
    font-size: 0.72rem;
  }

  .chart-wrap canvas {
    max-width: 100% !important;
    max-height: 100% !important;
  }

  .print-charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
  }

  .print-charts-grid .chart-panel {
    max-width: none;
    width: 100%;
  }

  .print-chart-image {
    display: block;
    width: 100%;
    height: auto;
  }

  .installments-section {
    break-before: page;
    page-break-before: always;
  }

  .installments-section > .section-heading {
    display: none;
  }

  .installments-table thead {
    display: table-header-group;
  }

  .print-table-brand-row,
  .print-table-title-row {
    display: table-row;
  }

  .table-responsive,
  .installments-table-wrap {
    max-height: none;
    overflow: visible;
    border: 0;
  }

  .comparison-table,
  .print-summary-table,
  .print-parameters-table,
  .installments-table {
    min-width: 0;
    width: 100%;
    font-size: 0.62rem;
  }

  .installments-table thead th {
    position: static;
    color: #111827;
    background: #eef3ef;
    box-shadow: none;
  }

  .installments-table th,
  .installments-table td,
  .print-summary-table th,
  .print-summary-table td,
  .print-parameters-table th,
  .print-parameters-table td,
  .comparison-table th,
  .comparison-table td {
    padding: 0.25rem;
    white-space: normal;
  }

  .installments-table .print-table-brand-row th {
    position: static;
    padding: 0 0 0.3rem;
    color: var(--color-primary-dark);
    background: #fff;
    border: 0;
    border-bottom: 1px solid var(--color-border);
    box-shadow: none;
    text-align: left;
  }

  .installments-table .print-table-title-row th {
    position: static;
    padding: 0.35rem 0 0.55rem;
    color: var(--color-primary-dark);
    background: #fff;
    border: 0;
    box-shadow: none;
    text-align: left;
  }

  .print-table-title {
    display: block;
    margin: 0;
    color: var(--color-primary-dark);
    font-size: 1.1rem;
    font-weight: 700;
  }

  .print-table-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  .print-table-brand-logo {
    width: 0.9rem;
    height: 0.9rem;
    object-fit: contain;
  }

  .print-summary-table th,
  .print-parameters-table th {
    width: 18%;
    color: #4b5563;
    font-weight: 600;
  }

  .print-summary-table td,
  .print-parameters-table td {
    width: 32%;
    font-variant-numeric: tabular-nums;
  }

  .comparison-highlights {
    gap: 0.4rem;
  }

  .highlight-pill {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
  }

  .estimate-notice {
    padding: 0.75rem;
    background: #f3f4f6;
    border-left-color: #9ca3af;
    font-size: 0.8rem;
  }

  .print-legal-notice {
    margin-bottom: 1rem;
    break-after: avoid;
    font-size: 0.72rem;
  }
}
