/* Home Loan Optimiser — editorial-fintech styling.
   Cream paper background, deep ink, forest-green for positive deltas,
   burnt sienna for cost. Serif display, sans body, mono numerals. */

:root {
  --paper:        #F6F1E5;
  --paper-deep:   #EFE8D5;
  --ink:          #1A1714;
  --ink-soft:     #3D362D;
  --ink-muted:    #6E665B;
  --rule:         #C9BFA6;
  --rule-soft:    #D9D0B8;
  --surface:      #FBF7EC;
  --surface-sunk: #EFE7D2;
  --green:        #2F5D43;
  --green-soft:   #D7E2D5;
  --sienna:       #A44A2A;
  --sienna-soft:  #EBD3C2;
  --gold:         #B8893A;
  --shadow-sm:    0 1px 2px rgba(26, 23, 20, 0.06);
  --shadow-md:    0 4px 16px -6px rgba(26, 23, 20, 0.12), 0 2px 4px -2px rgba(26, 23, 20, 0.08);
  --shadow-lg:    0 18px 40px -18px rgba(26, 23, 20, 0.25);
  --radius-sm:    4px;
  --radius-md:    8px;
  --radius-lg:    14px;
  --serif:        'Fraunces', 'Iowan Old Style', 'Charter', 'Georgia', serif;
  --sans:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono:         'JetBrains Mono', 'SF Mono', 'Menlo', 'Consolas', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle paper grain — drawn with stacked radial gradients, no image asset. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(26, 23, 20, 0.025) 0 1px, transparent 1px),
    radial-gradient(circle at 70% 60%, rgba(26, 23, 20, 0.02) 0 1px, transparent 1px),
    radial-gradient(circle at 40% 80%, rgba(26, 23, 20, 0.018) 0 1px, transparent 1px);
  background-size: 7px 7px, 11px 11px, 13px 13px;
  opacity: 0.6;
  mix-blend-mode: multiply;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 32px 28px 80px;
}

/* ---------- Masthead ---------- */
.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 8px;
}

.masthead__brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.masthead__mark {
  width: 56px;
  height: 56px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
}
.masthead__mark::after {
  content: '$';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 30px;
  color: var(--ink);
  font-style: italic;
}

.masthead h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 44px;
  line-height: 1;
  margin: 0 0 4px 0;
  letter-spacing: -0.01em;
  font-feature-settings: 'ss01';
}
.masthead h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--green);
}

.masthead__sub {
  margin: 0;
  max-width: 540px;
  color: var(--ink-soft);
  font-size: 14.5px;
  line-height: 1.5;
}

.masthead__meta {
  text-align: right;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  line-height: 1.6;
  white-space: nowrap;
}
.masthead__meta strong { color: var(--ink); font-weight: 500; }

.masthead__rule {
  height: 6px;
  margin-bottom: 36px;
  background:
    linear-gradient(to bottom, var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 5px, transparent 5px 6px);
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .masthead h1 { font-size: 36px; }
  .masthead__meta { display: none; }
}

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
  position: relative;
}

.panel--inputs { position: sticky; top: 24px; }

.panel h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  margin: 0 0 4px 0;
  letter-spacing: -0.01em;
}
.panel h2 + .panel__hint {
  margin: 0 0 22px 0;
  font-size: 13px;
  color: var(--ink-muted);
}
.panel h2:not(:first-of-type) {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--rule-soft);
}
.panel h2:not(:first-of-type) + .panel__hint {
  margin-bottom: 18px;
}

/* ---------- Form fields ---------- */
.field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 4px 12px;
  margin-bottom: 14px;
}
.field__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}
.field__hint {
  grid-column: 1 / -1;
  font-size: 11.5px;
  color: var(--ink-muted);
  margin: 0 0 2px 0;
  line-height: 1.4;
}
.field__input {
  grid-column: 1 / -1;
  position: relative;
  display: flex;
  align-items: stretch;
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: var(--radius-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
  overflow: hidden;
}
.field__input:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(26, 23, 20, 0.08);
  background: var(--surface);
}
.field__input input,
.field__input select {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  outline: none;
}
.field__input select { font-family: var(--sans); }
.field__input input::-webkit-outer-spin-button,
.field__input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field__input input[type=number] { -moz-appearance: textfield; }
.field__suffix {
  display: grid;
  place-items: center;
  padding: 0 12px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-muted);
  background: var(--paper-deep);
  border-left: 1px solid var(--rule-soft);
  user-select: none;
}
.field__reset {
  background: transparent;
  border: 0;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px 0 0 0;
  align-self: end;
  grid-column: 2;
  transition: color 120ms;
}
.field__reset:hover { color: var(--sienna); }

/* Inline frequency toggle */
.segmented {
  display: flex;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.segmented__btn {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 7px 10px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  border-radius: 3px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.segmented__btn:hover { color: var(--ink); }
.segmented__btn.is-active {
  background: var(--ink);
  color: var(--paper);
}

/* ---------- Results panel ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--paper);
  overflow: hidden;
  margin-bottom: 24px;
}
.kpi {
  padding: 18px 20px;
  border-right: 1px solid var(--rule-soft);
  position: relative;
}
.kpi:last-child { border-right: 0; }
.kpi__label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.kpi__value {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 26px;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.kpi__value--accent { color: var(--green); }
.kpi__value--warn   { color: var(--sienna); }
.kpi__sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-muted);
  font-family: var(--mono);
}
.kpi__sub--accent { color: var(--green); font-weight: 500; }

@media (max-width: 720px) {
  .kpi { border-right: 0; border-bottom: 1px solid var(--rule-soft); }
  .kpi:last-child { border-bottom: 0; }
  .kpi__value { font-size: 22px; }
}

/* Recommendation card */
.recommendation {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-md);
  padding: 22px 24px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}
.recommendation::before {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 200px;
  background:
    radial-gradient(circle at 100% 50%, rgba(184, 137, 58, 0.18) 0%, transparent 60%);
  pointer-events: none;
}
.recommendation__eyebrow {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 500;
  margin-bottom: 8px;
}
.recommendation__body {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.4;
  font-weight: 400;
  margin: 0;
  max-width: 580px;
  position: relative;
}
.recommendation__body strong {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--gold);
  font-size: 22px;
  letter-spacing: -0.01em;
}
.recommendation__detail {
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: rgba(246, 241, 229, 0.65);
  position: relative;
}
.recommendation.is-empty .recommendation__body {
  color: rgba(246, 241, 229, 0.55);
  font-style: italic;
}

/* Charts */
.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
@media (max-width: 880px) { .charts { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 22px 24px 18px;
  box-shadow: var(--shadow-sm);
}
.chart-card h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 18px;
  margin: 0 0 4px 0;
  letter-spacing: -0.01em;
}
.chart-card h3 small {
  display: block;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-muted);
  margin-top: 2px;
  letter-spacing: 0;
}
.chart-card__body {
  position: relative;
  height: 240px;
  margin-top: 12px;
}

.chart-card--wide { grid-column: 1 / -1; }
.chart-card--wide .chart-card__body { height: 260px; }

.legend {
  display: flex;
  gap: 18px;
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 6px;
}
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* Schedule */
.schedule-section {
  margin-top: 48px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  box-shadow: var(--shadow-sm);
}
.schedule-section h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  margin: 0 0 4px 0;
  letter-spacing: -0.01em;
}
.schedule-section > p {
  margin: 0 0 20px 0;
  color: var(--ink-muted);
  font-size: 13.5px;
}
.schedule-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}
.schedule-controls select,
.schedule-controls button {
  font-family: var(--sans);
  font-size: 13px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.schedule-controls button:hover,
.schedule-controls select:hover { background: var(--paper-deep); }
.schedule-controls button.is-active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.schedule-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--paper);
}
table.schedule {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
table.schedule thead th {
  position: sticky;
  top: 0;
  background: var(--paper-deep);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-align: right;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
table.schedule thead th:first-child { text-align: left; }
table.schedule tbody td {
  padding: 7px 14px;
  text-align: right;
  border-bottom: 1px solid var(--rule-soft);
  white-space: nowrap;
}
table.schedule tbody td:first-child { text-align: left; color: var(--ink-soft); }
table.schedule tbody tr:last-child td { border-bottom: 0; }
table.schedule tbody tr.is-summary td {
  background: var(--surface-sunk);
  font-weight: 600;
  color: var(--ink);
}
table.schedule tbody tr.is-milestone td {
  background: rgba(47, 93, 67, 0.06);
}
table.schedule tbody tr.is-milestone td:first-child {
  color: var(--green);
  font-weight: 600;
}

/* Footer */
.foot {
  margin-top: 48px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.foot kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 6px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
}

/* Visually-hidden helper for accessibility */
.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;
}

/* Subtle entry animation */
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kpi, .recommendation, .chart-card { animation: rise 320ms ease both; }
.kpi:nth-child(2) { animation-delay: 40ms; }
.kpi:nth-child(3) { animation-delay: 80ms; }
.kpi:nth-child(4) { animation-delay: 120ms; }
.kpi:nth-child(5) { animation-delay: 160ms; }
.kpi:nth-child(6) { animation-delay: 200ms; }
@media (prefers-reduced-motion: reduce) {
  .kpi, .recommendation, .chart-card { animation: none; }
}
