/* mortgage-styles.css - shared by mortgage_calculator.html and mortgage_recast.html.
   Extracted from mortgage_calculator.html; both pages use the same card, field,
   input, section-card, amort-* and badge styles. */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      background: #f0f4f8;
      color: #2d3748;
      min-height: 100vh;
      padding: 2rem 1rem;
    }

    h1 {
      text-align: center;
      font-size: 1.8rem;
      font-weight: 700;
      color: #1a365d;
      margin-bottom: 0.25rem;
    }

    .subtitle {
      text-align: center;
      color: #718096;
      font-size: 0.95rem;
      margin-bottom: 2rem;
    }

    .layout {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 1.5rem;
      max-width: 1000px;
      margin: 0 auto;
    }

    @media (max-width: 700px) {
      .layout { grid-template-columns: 1fr; }
    }

    .card {
      background: #fff;
      border-radius: 12px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.08);
      padding: 1.5rem;
    }

    .card h2 {
      font-size: 1rem;
      font-weight: 600;
      color: #2b6cb0;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-bottom: 1.25rem;
      padding-bottom: 0.5rem;
      border-bottom: 2px solid #ebf4ff;
    }

    .field { margin-bottom: 1rem; }
    .field:last-child { margin-bottom: 0; }

    .field label {
      display: block;
      font-size: 0.85rem;
      font-weight: 500;
      color: #4a5568;
      margin-bottom: 0.3rem;
    }

    .input-row {
      display: flex;
      gap: 0.4rem;
      align-items: center;
    }

    .input-wrapper {
      position: relative;
      flex: 1;
    }

    .input-prefix, .input-suffix {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      color: #718096;
      font-size: 0.9rem;
      pointer-events: none;
    }

    .input-prefix { left: 10px; }
    .input-suffix { right: 10px; }

    input[type="number"], input[type="text"], select {
      width: 100%;
      padding: 0.55rem 0.75rem;
      font-size: 0.95rem;
      border: 1.5px solid #cbd5e0;
      border-radius: 7px;
      background: #f7fafc;
      color: #2d3748;
      transition: border-color 0.15s, box-shadow 0.15s;
      appearance: none;
      -webkit-appearance: none;
    }

    input[type="number"].has-prefix { padding-left: 1.75rem; }
    input[type="number"].has-suffix { padding-right: 2rem; }

    input:focus, select:focus {
      outline: none;
      border-color: #4299e1;
      box-shadow: 0 0 0 3px rgba(66,153,225,0.2);
      background: #fff;
    }

    input.error, select.error {
      border-color: #fc8181;
      box-shadow: 0 0 0 3px rgba(252,129,129,0.2);
    }

    .error-msg {
      font-size: 0.78rem;
      color: #e53e3e;
      margin-top: 0.25rem;
      display: none;
    }
    .error-msg.visible { display: block; }

    .toggle-group {
      display: flex;
      border: 1.5px solid #cbd5e0;
      border-radius: 7px;
      overflow: hidden;
    }

    .toggle-group button {
      flex: 1;
      padding: 0.55rem 0.5rem;
      background: #f7fafc;
      border: none;
      cursor: pointer;
      font-size: 0.88rem;
      color: #718096;
      transition: background 0.15s, color 0.15s;
    }

    .toggle-group button.active {
      background: #2b6cb0;
      color: #fff;
      font-weight: 600;
    }

    .zip-row {
      display: flex;
      gap: 0.4rem;
      margin-top: 0.5rem;
      align-items: flex-end;
    }

    .zip-row .field { flex: 1; margin-bottom: 0; }

    .btn-lookup {
      padding: 0.55rem 0.85rem;
      background: #4299e1;
      color: #fff;
      border: none;
      border-radius: 7px;
      cursor: pointer;
      font-size: 0.85rem;
      font-weight: 600;
      white-space: nowrap;
      transition: background 0.15s;
    }

    .btn-lookup:hover { background: #3182ce; }
    .btn-lookup:disabled { background: #a0aec0; cursor: not-allowed; }

    .zip-status {
      font-size: 0.78rem;
      margin-top: 0.3rem;
      min-height: 1rem;
      color: #718096;
    }

    .zip-status.ok { color: #38a169; }
    .zip-status.err { color: #e53e3e; }

    .pmi-notice {
      background: #fffbeb;
      border: 1px solid #f6e05e;
      border-radius: 7px;
      padding: 0.5rem 0.75rem;
      font-size: 0.82rem;
      color: #744210;
      margin-top: 0.25rem;
      display: none;
    }
    .pmi-notice.visible { display: block; }

    /* Output card */
    .output-card {
      grid-column: 1 / -1;
      background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%);
      color: #fff;
      border-radius: 12px;
      padding: 1.75rem;
      box-shadow: 0 4px 16px rgba(43,108,176,0.3);
    }

    .output-card h2 {
      font-size: 1rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      opacity: 0.75;
      margin-bottom: 1.25rem;
      padding-bottom: 0.5rem;
      border-bottom: 1px solid rgba(255,255,255,0.2);
    }

    .total-monthly {
      text-align: center;
      margin-bottom: 1.5rem;
    }

    .total-monthly .label {
      font-size: 0.9rem;
      opacity: 0.8;
      margin-bottom: 0.25rem;
    }

    .total-monthly .amount {
      font-size: 3rem;
      font-weight: 700;
      letter-spacing: -0.02em;
    }

    .total-monthly .per-month { font-size: 1rem; opacity: 0.7; }

    .breakdown {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
      gap: 1rem;
      margin-bottom: 1.5rem;
    }

    .breakdown-item {
      background: rgba(255,255,255,0.12);
      border-radius: 8px;
      padding: 0.75rem 1rem;
    }

    .breakdown-item .b-label {
      font-size: 0.78rem;
      opacity: 0.75;
      margin-bottom: 0.2rem;
    }

    .breakdown-item .b-amount {
      font-size: 1.2rem;
      font-weight: 700;
    }

    .breakdown-item.pmi-item { display: none; }
    .breakdown-item.pmi-item.visible { display: block; }

    .closing-section {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 1rem;
      padding-top: 1.25rem;
      border-top: 1px solid rgba(255,255,255,0.2);
    }

    @media (max-width: 600px) {
      .closing-section { grid-template-columns: 1fr 1fr; }
      .total-monthly .amount { font-size: 2.2rem; }
    }

    @media (max-width: 400px) {
      .closing-section { grid-column: 1fr; }
    }

    .closing-item .c-label {
      font-size: 0.82rem;
      opacity: 0.75;
      margin-bottom: 0.2rem;
    }

    .closing-item .c-amount {
      font-size: 1.4rem;
      font-weight: 700;
    }

    .closing-item .c-pct {
      font-size: 0.82rem;
      opacity: 0.65;
      margin-top: 0.15rem;
    }

    .placeholder-msg {
      text-align: center;
      opacity: 0.55;
      font-size: 1rem;
      padding: 1rem 0;
    }

    .results-content { display: none; }
    .results-content.visible { display: block; }
    .placeholder-msg.hidden { display: none; }

    /* ── Amortization Analysis Charts ──────────────────────────────────── */
    .chart-card {
      grid-column: 1 / -1;
      background: #fff;
      border-radius: 12px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.08);
      padding: 1.5rem;
      display: none;
    }

    .chart-card h2 {
      font-size: 1rem;
      font-weight: 600;
      color: #2b6cb0;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-bottom: 1.25rem;
      padding-bottom: 0.5rem;
      border-bottom: 2px solid #ebf4ff;
    }

    .chart-metrics {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
      gap: 10px;
      margin-bottom: 1.5rem;
    }

    .chart-metric {
      background: #f7fafc;
      border-radius: 8px;
      padding: 12px 14px;
      border: 1px solid #e2e8f0;
    }

    .chart-metric-label { font-size: 11px; color: #718096; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
    .chart-metric-value { font-size: 18px; font-weight: 700; color: #2d3748; }

    .chart-legend {
      display: flex;
      flex-wrap: wrap;
      gap: 14px;
      margin-bottom: 10px;
      font-size: 12px;
      color: #718096;
    }

    .chart-legend-item { display: flex; align-items: center; gap: 6px; }

    .chart-section-divider {
      border: none;
      border-top: 1px solid #e2e8f0;
      margin: 1.5rem 0 1rem;
    }

    .chart-section-label {
      font-size: 0.78rem;
      font-weight: 600;
      color: #4a5568;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-bottom: 0.75rem;
    }

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

    /* ── Amortization Schedule ─────────────────────────────────────────── */
    .amort-card {
      grid-column: 1 / -1;
      background: #fff;
      border-radius: 12px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.08);
      overflow: hidden;
    }

    .amort-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 1.25rem 1.5rem;
      border-bottom: 2px solid #ebf4ff;
      cursor: pointer;
      user-select: none;
    }

    .amort-header h2 {
      font-size: 1rem;
      font-weight: 600;
      color: #2b6cb0;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin: 0;
      padding: 0;
      border: none;
    }

    .amort-toggle-btn {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.4rem 0.85rem;
      background: #ebf4ff;
      color: #2b6cb0;
      border: 1.5px solid #bee3f8;
      border-radius: 7px;
      cursor: pointer;
      font-size: 0.82rem;
      font-weight: 600;
      transition: background 0.15s;
      white-space: nowrap;
    }

    .amort-toggle-btn:hover { background: #bee3f8; }

    .amort-toggle-icon {
      transition: transform 0.2s;
      font-style: normal;
      display: inline-block;
    }

    .amort-toggle-icon.open { transform: rotate(180deg); }

    .amort-body {
      display: none;
      padding: 1.5rem;
    }

    .amort-body.visible { display: block; }

    /* Summary bar */
    .amort-summary {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
      gap: 1rem;
      margin-bottom: 1.5rem;
    }

    .amort-stat {
      background: #f7fafc;
      border: 1.5px solid #e2e8f0;
      border-radius: 10px;
      padding: 0.85rem 1rem;
    }

    .amort-stat .as-label {
      font-size: 0.78rem;
      color: #718096;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      margin-bottom: 0.25rem;
    }

    .amort-stat .as-value {
      font-size: 1.25rem;
      font-weight: 700;
      color: #1a365d;
    }

    .amort-stat .as-sub {
      font-size: 0.75rem;
      color: #a0aec0;
      margin-top: 0.15rem;
    }

    .amort-stat.highlight {
      background: #ebf4ff;
      border-color: #90cdf4;
    }

    .amort-stat.highlight .as-value { color: #2b6cb0; }

    /* PMI callout */
    .pmi-callout {
      display: none;
      background: #fffbeb;
      border: 1px solid #f6e05e;
      border-radius: 8px;
      padding: 0.65rem 1rem;
      font-size: 0.83rem;
      color: #744210;
      margin-bottom: 1.25rem;
    }

    .pmi-callout.visible { display: block; }

    /* View mode toggle */
    .amort-controls {
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 0.75rem;
      margin-bottom: 1rem;
    }

    .amort-controls-label {
      font-size: 0.85rem;
      font-weight: 500;
      color: #4a5568;
    }

    .view-toggle {
      display: flex;
      border: 1.5px solid #cbd5e0;
      border-radius: 7px;
      overflow: hidden;
    }

    .view-toggle button {
      padding: 0.4rem 0.85rem;
      background: #f7fafc;
      border: none;
      cursor: pointer;
      font-size: 0.83rem;
      color: #718096;
      transition: background 0.15s, color 0.15s;
    }

    .view-toggle button.active {
      background: #2b6cb0;
      color: #fff;
      font-weight: 600;
    }

    /* Table */
    .amort-table-wrap {
      overflow-x: auto;
      border-radius: 8px;
      border: 1.5px solid #e2e8f0;
      max-height: 420px;
      overflow-y: auto;
    }

    .amort-table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
    .amort-table-wrap::-webkit-scrollbar-track { background: #f0f4f8; }
    .amort-table-wrap::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 3px; }

    table.amort-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.83rem;
    }

    table.amort-table thead {
      position: sticky;
      top: 0;
      z-index: 1;
    }

    table.amort-table thead th {
      background: #1a365d;
      color: #fff;
      padding: 0.6rem 0.85rem;
      text-align: right;
      font-weight: 600;
      font-size: 0.78rem;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      white-space: nowrap;
    }

    table.amort-table thead th:first-child { text-align: left; }

    table.amort-table tbody tr {
      border-bottom: 1px solid #edf2f7;
      transition: background 0.1s;
    }

    table.amort-table tbody tr:hover { background: #ebf4ff; }

    table.amort-table tbody tr.pmi-row { background: #fffff8; }
    table.amort-table tbody tr.pmi-row:hover { background: #fefce8; }

    table.amort-table tbody tr.equity-milestone {
      background: #f0fff4;
      font-weight: 600;
    }

    table.amort-table tbody tr.equity-milestone:hover { background: #c6f6d5; }

    table.amort-table td {
      padding: 0.5rem 0.85rem;
      text-align: right;
      color: #2d3748;
      white-space: nowrap;
    }

    table.amort-table td:first-child { text-align: left; color: #4a5568; font-weight: 500; }

    td.td-principal { color: #2b6cb0; font-weight: 600; }
    td.td-interest  { color: #718096; }
    td.td-pmi       { color: #d69e2e; font-size: 0.78rem; }
    td.td-balance   { color: #1a365d; font-weight: 600; }
    td.td-equity    { color: #38a169; font-weight: 600; }
    td.td-extra     { color: #1d9e75; font-weight: 600; }
    td.td-badge     { text-align: left; }

    .milestone-badge {
      display: inline-block;
      font-size: 0.7rem;
      font-weight: 700;
      padding: 0.15rem 0.45rem;
      border-radius: 4px;
      margin-left: 0.4rem;
      vertical-align: middle;
    }

    .badge-pmi-off  { background: #fefce8; color: #92400e; border: 1px solid #fde68a; }
    .badge-equity50 { background: #f0fff4; color: #22543d; border: 1px solid #9ae6b4; }
    .badge-equity100 { background: #ebf4ff; color: #1a365d; border: 1px solid #90cdf4; }

    /* Annual summary rows */
    tr.year-row td {
      background: #f7fafc;
      font-size: 0.8rem;
      color: #4a5568;
    }

    tr.year-row td:first-child {
      font-weight: 700;
      color: #2b6cb0;
    }

    /* ── Amortization Analysis (Chart.js section) ──────────────────────── */
    .amort-metrics {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
      gap: 10px;
      margin-bottom: 1.5rem;
    }

    .amort-metric {
      background: #f7fafc;
      border-radius: 8px;
      padding: 12px 14px;
      border: 1px solid #e2e8f0;
    }

    .amort-metric-label { font-size: 11px; color: #718096; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
    .amort-metric-value { font-size: 18px; font-weight: 700; color: #2d3748; }

    .amort-legend {
      display: flex;
      flex-wrap: wrap;
      gap: 14px;
      margin-bottom: 10px;
      font-size: 12px;
      color: #718096;
    }

    .amort-legend-item { display: flex; align-items: center; gap: 5px; }

    .amort-bar-legend {
      display: flex;
      flex-wrap: wrap;
      gap: 14px;
      margin-bottom: 10px;
      font-size: 12px;
      color: #718096;
    }

    .amort-section-divider {
      border: none;
      border-top: 1px solid #e2e8f0;
      margin: 1.5rem 0 1rem;
    }

    .amort-section-label {
      font-size: 0.78rem;
      font-weight: 600;
      color: #4a5568;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-bottom: 0.75rem;
    }

    .amort-placeholder {
      text-align: center;
      color: #a0aec0;
      font-size: 0.9rem;
      padding: 2rem 0;
    }

    /* ── Recast & Sensitivity cards ────────────────────────────────────── */
    .section-card {
      grid-column: 1 / -1;
      background: #fff;
      border-radius: 12px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.08);
      padding: 1.5rem;
    }

    .section-card > h2 {
      font-size: 1rem;
      font-weight: 600;
      color: #2b6cb0;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-bottom: 1.25rem;
      padding-bottom: 0.5rem;
      border-bottom: 2px solid #ebf4ff;
    }

    .section-intro {
      font-size: 0.82rem;
      color: #718096;
      margin: -0.75rem 0 1.25rem;
    }

    .inline-fields {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
      gap: 1rem;
      margin-bottom: 1.25rem;
    }

    .inline-fields .field { margin-bottom: 0; }

    /* Grouped before/after header for the merged recast table */
    table.amort-table thead th.grp-label { text-align: center; }
    table.amort-table thead th.grp-before { background: #4a5568; }
    table.amort-table thead th.grp-after  { background: #276749; }

    table.amort-table tbody tr.recast-row { background: #ebf4ff; font-weight: 600; }
    table.amort-table tbody tr.recast-row:hover { background: #bee3f8; }

    td.td-saved { color: #276749; font-weight: 600; }

    .badge-recast { background: #ebf4ff; color: #2b6cb0; border: 1px solid #90cdf4; }

    .site-nav { max-width: 1000px; margin: 0 auto 1.5rem; }
    .site-nav a {
      display: inline-block; color: #2b6cb0; text-decoration: none;
      font-size: 0.9rem; font-weight: 600; padding: 0.3rem 0;
    }
    .site-nav a:hover { text-decoration: underline; }
    .site-nav-dark { margin-bottom: 0.4rem; }
    .site-nav-dark a {
      display: inline-block; color: rgba(255,255,255,0.72); text-decoration: none;
      font-size: 0.82rem; font-weight: 600;
    }
    .site-nav-dark a:hover { color: #fff; text-decoration: underline; }
