:root {
  --ink: #1b2838;
  --ink-soft: #3e4c59;
  --paper: #f3efe6;
  --card: #fffdf8;
  --line: #e4dccf;
  --navy: #1b3a4b;
  --copper: #c4622d;
  --serif: Georgia, "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  --sans: "Segoe UI", Candara, sans-serif;
}

html {
  font-size: 16px;
}

body {
  display: grid;
  grid-template-columns: 2fr 8fr 2fr;
  align-items: stretch;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}

.gridLeft,
.gridRight {
  grid-row: 1;
  min-width: 0;
}

.gridLeft {
  grid-column: 1;
}

.gridRight {
  grid-column: 3;
}

.gridCenter {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

main {
  padding-inline: 0.75rem;
}

h1, h2, .stat-value, .donut-hole strong {
  font-family: var(--serif);
  font-weight: 600;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  transform: translateY(-150%);
  background: white;
  color: var(--navy);
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  z-index: 10;
}

.skip-link:focus {
  transform: none;
}

.page-wrap {
  width: 100%;
  max-width: none;
  margin-inline: 0;
  padding-inline: 0.75rem;
  box-sizing: border-box;
}

.site-header {
  position: relative;
  background: var(--navy);
  color: #f7f4ee;
  padding: 0.55rem 0 0.5rem;
}

.site-header::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: 0;
  bottom: 0;
  left: -25%;
  right: -25%;
  background: var(--navy);
}

.site-header .page-wrap {
  position: relative;
  z-index: 1;
}

.site-header h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
  color: #fffdf8;
}

.lede {
  margin: 0.05rem 0 0;
  color: #efe6d8;
  font-size: 0.92rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-footer {
  position: relative;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  padding: 1.1rem 0 1.8rem;
  margin-top: 0.5rem;
}

.site-footer::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -25%;
  right: -25%;
  border-top: 1px solid var(--line);
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: inherit;
  font-weight: 600;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.4rem 0 1.6rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.2rem 1.2rem 1.3rem;
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(21rem, 26rem) minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.workspace:not(:has(.summary-column)) {
  grid-template-columns: minmax(21rem, 26rem);
}

.form-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.form-column > .panel:last-child {
  margin-top: auto;
}

.summary-column {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
  height: 100%;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.75rem;
  align-items: stretch;
  flex: 1;
}

.summary-cards .chart-card {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.summary-cards .chart-layout {
  flex: 1;
  align-items: center;
}

.schedule-stage {
  grid-column: 1 / -1;
  min-width: 0;
}

.loan-fields {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.field-row {
  display: grid;
  grid-template-columns: 7.6rem minmax(0, 1fr);
  gap: 0.55rem;
  align-items: start;
}

.field-row > label {
  margin: 0;
  padding-top: 0.28rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.field-control {
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-head h2 {
  margin: 0;
}

.form-label {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.35rem;
}

.field-help {
  display: block;
  margin-top: 0.35rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.form-control,
.form-select {
  border-color: #d9d0c2;
  background: #fff;
  color: var(--ink);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 0.2rem rgba(27, 58, 75, 0.16);
}

.input-group-text {
  background: #f3eee4;
  border-color: #d9d0c2;
  color: var(--navy);
  font-weight: 600;
}

.date-pair {
  display: flex;
  gap: 0.5rem;
}

.date-pair .form-select {
  flex: 1 1 auto;
  min-width: 0;
}

.year-input {
  max-width: 7.5rem;
}

.form-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.btn-calculate {
  background: var(--navy);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 0.28rem 0.9rem;
  font-weight: 600;
}

.btn-calculate:hover,
.btn-calculate:focus {
  background: #142c3a;
  color: #fff;
}

.btn-reset {
  color: var(--navy);
  font-weight: 600;
  text-decoration: none;
  padding: 0.28rem 0.2rem;
}

.btn-reset:hover {
  color: var(--navy);
  text-decoration: underline;
}

.extra-empty {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.extra-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.extra-table th,
.extra-table td {
  text-align: left;
  padding: 0.4rem 0.35rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.extra-table th {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}

.extra-table th:last-child,
.extra-table td:last-child {
  text-align: right;
}

.extra-actions {
  white-space: nowrap;
}

.extra-actions .btn-row + .btn-row {
  margin-left: 0.3rem;
}

.btn-row {
  border: 1px solid var(--line);
  background: white;
  color: var(--navy);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.5;
}

.btn-row:hover,
.btn-row:focus {
  border-color: var(--navy);
  color: var(--navy);
}

.btn-row-danger {
  color: #8d2a2a;
}

.btn-row-danger:hover,
.btn-row-danger:focus {
  border-color: #8d2a2a;
  color: #8d2a2a;
}

.modal-content {
  background: var(--card);
  border-color: var(--line);
}

.validation-summary-valid {
  display: none;
}

.validation-summary-errors {
  background: #fdeeee;
  border: 1px solid #e7c1c1;
  color: #8d2a2a;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.validation-summary-errors ul {
  margin: 0;
  padding-left: 1.1rem;
}

.field-validation-error {
  display: block;
  margin-top: 0.3rem;
  color: #8d2a2a;
  font-size: 0.82rem;
}

.results-header h2 {
  margin: 0;
  font-size: 1.55rem;
}

.results-kicker {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  white-space: nowrap;
}

#results {
  scroll-margin-top: 1rem;
}

.stat,
.chart-card,
.schedule-board {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.schedule-board {
  margin-top: 0;
}

.stat {
  container-type: inline-size;
  padding: 0.95rem 1rem 1rem;
}

.stat-label,
.chart-card figcaption {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 600;
}

.stat-value {
  margin: 0.2rem 0 0;
  max-width: 100%;
  font-size: clamp(0.7rem, 13cqi, 1.5rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat-hint,
.method-note,
.table-note,
.stale-note {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.chart-card {
  margin: 0;
  padding: 1rem 1.1rem 1.1rem;
}

.chart-layout {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-top: 0.8rem;
  min-width: 0;
}

.trend {
  flex: 1 1 16rem;
  align-self: stretch;
  min-width: 0;
  min-height: 10.5rem;
}

.trend svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 10.5rem;
}

.trend-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.trend-principal,
.trend-interest {
  fill: none;
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.trend-principal {
  stroke: var(--navy);
}

.trend-interest {
  stroke: var(--copper);
}

.trend text {
  fill: var(--ink-soft);
  font-size: 11px;
  font-family: var(--sans);
}

.donut {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  background: conic-gradient(var(--navy) calc(var(--principal) * 1%), var(--copper) 0);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.donut-hole {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.donut-hole span {
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.donut-hole strong {
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.legend li {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
}

.legend-label,
.legend-value {
  display: block;
}

.legend-label {
  font-weight: 700;
}

.legend-value {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.swatch {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  margin-top: 0.25rem;
  flex: 0 0 auto;
}

.swatch-principal {
  background: var(--navy);
}

.swatch-interest {
  background: var(--copper);
}

.schedule-messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.schedule-messages .method-note,
.schedule-messages .table-note,
.schedule-messages .stale-note {
  margin: 0;
}

.savings {
  background: #e7f2ec;
  border: 1px solid #b7d7c6;
  color: #145c38;
  border-radius: 12px;
  padding: 0.8rem 1rem;
  margin: 0;
}

.savings p {
  margin: 0;
}

.savings .baseline {
  margin-top: 0.25rem;
  color: #1d6844;
}

.note-list {
  background: #f8f1e4;
  border: 1px solid #ead7b8;
  border-radius: 12px;
  padding: 0.7rem 1rem 0.7rem 2rem;
  margin: 0;
}

.method-note {
  margin-top: 0.75rem;
}

.schedule-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.schedule-switch {
  display: inline-flex;
  padding: 0.2rem;
  background: #efeae1;
  border-radius: 999px;
  gap: 0.15rem;
}

.schedule-switch label {
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-weight: 600;
  color: var(--navy);
  cursor: pointer;
  margin: 0;
}

.schedule-switch label:hover {
  background: rgba(27, 58, 75, 0.08);
}

.schedule-board:has(#view-annual:checked) label[for="view-annual"],
.schedule-board:has(#view-monthly:checked) label[for="view-monthly"] {
  background: var(--navy);
  color: #fff;
}

.schedule-board:has(#view-annual:focus-visible) label[for="view-annual"],
.schedule-board:has(#view-monthly:focus-visible) label[for="view-monthly"] {
  outline: 2px solid var(--copper);
  outline-offset: 2px;
}

.schedule-choice {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.monthly-pane {
  display: none;
}

.schedule-board:has(#view-monthly:checked) .annual-pane {
  display: none;
}

.schedule-board:has(#view-monthly:checked) .monthly-pane {
  display: block;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.export-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.btn-export {
  background: transparent;
  border: 1px solid var(--navy);
  color: var(--navy);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-weight: 600;
}

.btn-export:hover,
.btn-export:focus {
  background: var(--navy);
  color: #fff;
}

.btn-export:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: transparent;
  color: var(--navy);
}

.stale-note {
  color: #8a3e16;
  margin: 0 0 0.7rem;
}

.table-scroll {
  overflow: auto;
  max-height: 32rem;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.schedule {
  width: 100%;
  min-width: 46rem;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.92rem;
}

.schedule th,
.schedule td {
  padding: 0.5rem 0.7rem;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.schedule thead th {
  position: sticky;
  top: 0;
  background: var(--navy);
  color: #fff;
  font-weight: 600;
  z-index: 1;
}

.schedule .text-start,
.schedule th:first-child,
.schedule td:first-child {
  text-align: left;
}

.schedule tbody tr:nth-child(even) td {
  background: #faf7f2;
}

.schedule tbody tr:hover td {
  background: #f3ece1;
}

.schedule td.extra {
  color: #8a3e16;
  font-weight: 700;
}

.schedule tfoot th,
.schedule tfoot td {
  background: #f3eee4;
  font-weight: 700;
  border-top: 2px solid #d9d0c2;
  border-bottom: 0;
}

.btn-calculate:focus-visible,
.btn-export:focus-visible,
.btn-reset:focus-visible,
.btn-row:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: 2px;
}

@media (max-width: 1200px) {
  .summary-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  .gridLeft,
  .gridRight {
    display: none;
  }

  .gridCenter {
    grid-column: 1;
    grid-row: auto;
  }

  .site-header::before,
  .site-footer::before {
    left: 0;
    right: 0;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .summary-cards {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: none;
    flex: none;
  }

  .form-column > .panel:last-child {
    margin-top: 0;
  }
}

@media (max-width: 560px) {
  .summary-cards {
    grid-template-columns: 1fr;
  }

  .field-row {
    grid-template-columns: 6.4rem minmax(0, 1fr);
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions .btn-calculate {
    width: 100%;
  }

  .chart-layout {
    flex-direction: column;
    align-items: flex-start;
  }
}
