:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #637083;
  --line: #dde5f0;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --principal: #3b82f6;
  --interest: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --shadow: 0 20px 45px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 14px;
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1.05;
}

h2 {
  margin-bottom: 8px;
  font-size: 20px;
}

.hero-text {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.75;
}

.hero-card {
  min-width: 250px;
  padding: 22px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.hero-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
}

.hero-card strong {
  display: block;
  color: var(--primary-dark);
  font-size: 20px;
}

.layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  min-width: 0;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.controls,
.chart-panel,
.table-panel {
  padding: 22px;
}

.controls {
  position: sticky;
  top: 18px;
}

.panel-header {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.field-grid {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.amount-input {
  position: relative;
}

.amount-input input {
  padding-right: 96px;
}

.amount-input em {
  position: absolute;
  right: 30px;
  top: 50%;
  max-width: 70px;
  overflow: hidden;
  color: var(--primary-dark);
  font-size: 13px;
  font-style: normal;
  font-weight: 900;
  text-align: right;
  text-overflow: ellipsis;
  transform: translateY(-50%);
  white-space: nowrap;
  pointer-events: none;
}

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--primary-dark);
  cursor: pointer;
  font-weight: 800;
  padding: 9px 14px;
}

.danger-button {
  border-color: rgba(239, 68, 68, 0.24);
  color: var(--danger);
}

.toggle-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  margin: 20px 0;
  padding: 16px;
  border-radius: 18px;
  background: #f8fbff;
}

.toggle-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  display: block;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: #cbd5e1;
  cursor: pointer;
  position: relative;
  transition: background 160ms ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.24);
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.prepay-fields[hidden] {
  display: none;
}

.subsection-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
}

.subsection-header strong {
  display: block;
  margin-bottom: 4px;
}

.subsection-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.prepay-list {
  display: grid;
  gap: 10px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
}

.prepay-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.06), rgba(37, 99, 235, 0.025));
}

.prepay-row-header {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.prepay-row-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
}

.prepay-row-fields {
  display: grid;
  grid-template-columns: minmax(76px, 0.8fr) minmax(150px, 1.35fr);
  gap: 8px;
}

.prepay-row-fields .wide {
  grid-column: 1 / -1;
}

.prepay-row .field {
  gap: 5px;
}

.prepay-row .field span {
  font-size: 12px;
}

.prepay-row .field input,
.prepay-row .field select {
  min-height: 38px;
  border-radius: 12px;
  padding: 8px 10px;
}

.prepay-row .amount-input input {
  padding-right: 82px;
}

.prepay-row .amount-input em {
  right: 30px;
  max-width: 46px;
  font-size: 12px;
}

.prepay-row .ghost-button {
  padding: 6px 10px;
}

.results {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.summary-card {
  min-height: 126px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.summary-card span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.summary-card strong {
  display: block;
  font-size: clamp(20px, 2.2vw, 30px);
  line-height: 1.1;
}

.summary-card em {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  line-height: 1.5;
}

.summary-deltas {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.summary-delta {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  padding: 6px 8px;
}

.delta-good {
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
}

.delta-bad {
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

.chart-header {
  align-items: flex-start;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.legend span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 4px;
}

.principal-dot {
  background: var(--principal);
}

.interest-dot {
  background: var(--interest);
}

.payment-dot {
  background: #111827;
}

.chart-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 0 4px;
  overscroll-behavior-inline: contain;
}

#chart {
  display: block;
  min-width: 0;
  height: 420px;
}

.line-principal,
.line-interest,
.line-payment {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.line-principal {
  stroke: var(--principal);
}

.line-interest {
  stroke: var(--interest);
}

.line-payment {
  stroke: #111827;
}

.hover-area {
  cursor: crosshair;
  fill: transparent;
}

.hover-line {
  stroke: #475569;
  stroke-width: 1.5;
  stroke-dasharray: 4 5;
}

.hover-point {
  stroke: #ffffff;
  stroke-width: 2;
}

.principal-point {
  fill: var(--principal);
}

.interest-point {
  fill: var(--interest);
}

.payment-point {
  fill: #111827;
}

.axis,
.grid-line {
  stroke: #d8e0eb;
  stroke-width: 1;
}

.axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.prepay-marker {
  stroke: var(--danger);
  stroke-width: 2;
  stroke-dasharray: 5 6;
}

.month-detail {
  min-height: 72px;
  margin-top: 16px;
  border-radius: 18px;
  background: #f8fbff;
  color: var(--muted);
  padding: 14px 16px;
  line-height: 1.7;
}

.month-detail strong {
  color: var(--text);
}

.table-panel {
  margin-top: 24px;
}

.table-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
}

.compact-field {
  width: min(180px, 100%);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 14px 10px;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 13px;
}

td {
  font-variant-numeric: tabular-nums;
}

.row-gap td {
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.18em;
}

.positive {
  color: var(--success);
  font-weight: 800;
}

.warning {
  color: var(--danger);
  font-weight: 800;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 20px, 1440px);
    padding: 24px 0;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .hero-card {
    min-width: 0;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .prepay-row-fields {
    grid-template-columns: 1fr;
  }

  .compact-field {
    width: 100%;
  }

  .panel-header,
  .chart-header {
    display: grid;
    justify-content: stretch;
  }
}
