:root {
  /* Bright modern SaaS palette (per user-supplied reference): white
     throughout, vivid indigo for brand/headings/selection, green reserved
     specifically for primary actions and positive figures. */
  --navy: #4F46E5;
  --navy-light: #6366F1;
  /* Two green shades: --cta for button backgrounds (needs 4.5:1 under its
     own white label text — #16A34A only reaches 3.3:1), --cta-bright for
     large positive stat values (32px/700, only needs 3:1, and reads more
     vivid at that size). */
  --cta: #15803D;
  --cta-bright: #16A34A;
  --paper: #ffffff;
  --paper-alt: #f3f4fa;
  --line: #e5e7f0;
  --ink: #0f1115;
  --ink-muted: #5b6577;
  --teal: #0d6e63;
  --teal-light: #e4f0ee;
  --green: #1f7a3d;
  --green-light: #e6f4ea;
  --danger: #9a2b2b;
  --danger-light: #f6e5e5;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 3px rgba(10, 20, 36, 0.06);
  --shadow-md: 0 8px 24px rgba(10, 20, 36, 0.10);
  --shadow-lg: 0 20px 48px rgba(10, 20, 36, 0.16);
  --max-width: 960px;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  /* Shared motion tokens rather than one-off durations per rule — 220ms for
     hover/focus fades (the 200-250ms range this product type calls for),
     120ms for snappy feedback (presses, chevron rotation, popover open). */
  --duration: 220ms;
  --duration-fast: 120ms;

  /* Type scale — consolidated from ~18 ad hoc rem values down to 7 steps. */
  --fs-2xs: 0.75rem;   /* 12px — micro labels/badges */
  --fs-xs: 0.8125rem;  /* 13px — hints, secondary/meta text */
  --fs-sm: 0.875rem;   /* 14px — form labels, buttons, table text, UI copy */
  --fs-base: 1rem;     /* 16px — icon glyphs, base UI */
  --fs-md: 1.125rem;   /* 18px — card headings (h3) */
  --fs-lg: 1.5rem;     /* 24px — section headings (h2) */
  --fs-xl: 2rem;       /* 32px — page title / hero stat */

  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.5;
}

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
}

h1, h2, h3 {
  font-weight: 800;
  margin: 0 0 4px;
  color: var(--navy);
  letter-spacing: -0.015em;
}

/* ---------- Header ---------- */

.site-header {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 24px 0 22px;
}
.site-header .wrap { padding: 0 20px; }
.site-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 6px;
}
.site-title-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.site-title {
  color: var(--ink);
  font-size: var(--fs-lg);
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
}
.site-tagline {
  margin: 0;
  color: var(--ink-muted);
  font-size: var(--fs-sm);
  max-width: 46em;
}

/* ---------- Ad slots ---------- */

.ad-slot { padding: 10px 20px; }
.ad-slot__inner {
  border: 1px dashed var(--line);
  background: var(--paper-alt);
  border-radius: var(--radius-sm);
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-slot--leaderboard .ad-slot__inner { min-height: 50px; }
.ad-slot__label {
  font-size: var(--fs-2xs);
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

/* ---------- Layout ---------- */

main.wrap { padding-top: 24px; padding-bottom: 40px; }

.calculator {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 24px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 16px;
}

.field { display: flex; flex-direction: column; }

label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

input, select {
  font-family: inherit;
  /* Literal 16px, not a rem step: iOS Safari auto-zooms on focus for any
     input under 16px computed size. Keeping this immune to the mobile
     root font-size override below guarantees that never happens. */
  font-size: 16px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--paper-alt);
  color: var(--ink);
  width: 100%;
  transition: background-color var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
input:hover, select:hover { background: #e8e5db; }
input:focus, select:focus {
  outline: none;
  background: #fff;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
input.is-invalid, input.is-invalid:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(154, 43, 43, 0.14);
}
button:focus-visible {
  outline: 2px solid var(--navy-light);
  outline-offset: 2px;
}
input[type="number"] { font-variant-numeric: tabular-nums; }

.field-error {
  font-size: var(--fs-xs);
  color: var(--danger);
  margin: 6px 0 0;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235b6577' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
}

.input-prefix, .input-suffix {
  display: flex;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--paper-alt);
  transition: background-color var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.input-prefix:focus-within, .input-suffix:focus-within {
  background: #fff;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
.input-prefix.is-invalid, .input-suffix.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(154, 43, 43, 0.14);
}
.input-prefix input, .input-suffix input {
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none !important;
}
.input-prefix__symbol, .input-suffix__symbol {
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--ink-muted);
  font-size: var(--fs-sm);
}
.input-suffix { flex-direction: row; }
.input-suffix__symbol { order: 2; }
.input-suffix input { order: 1; }

.field-hint {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  margin: 6px 0 0;
}

.field-tag {
  font-size: var(--fs-2xs);
  font-weight: 600;
  color: var(--navy);
  background: #e8ecfb;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.computed-value {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: var(--fs-lg);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
  background: #eef1fc;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  letter-spacing: -0.01em;
}

.field__label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.field__label-row label { margin-bottom: 0; }

/* ---------- Payment-mode toggle ---------- */

.payment-mode-field { margin-top: 18px; }

.segmented {
  display: inline-flex;
  background: var(--paper-alt);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 4px;
}
.segmented__btn {
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.segmented__btn:hover { color: var(--ink); }
.segmented__btn.is-active {
  background: var(--navy);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* ---------- Month picker ---------- */

.month-picker { position: relative; }
.month-picker__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.month-picker__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: inherit;
  font-size: 16px; /* see input/select rule above — avoids iOS zoom-on-focus */
  text-align: left;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--paper-alt);
  color: var(--ink);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.month-picker__trigger:hover { background: #e8e5db; }
.month-picker__trigger[aria-expanded="true"] {
  background: #fff;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
.month-picker__label { display: flex; align-items: center; gap: 8px; }
.month-picker__icon { color: var(--ink-muted); flex-shrink: 0; }
.month-picker__chevron { color: var(--ink-muted); font-size: var(--fs-xs); transition: transform var(--duration) var(--ease); }
.month-picker__trigger[aria-expanded="true"] .month-picker__chevron { transform: rotate(180deg); }

.month-picker__panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 40;
  width: 240px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 14px;
  animation: month-picker-in var(--duration-fast) var(--ease);
}
@keyframes month-picker-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.month-picker__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.month-picker__year {
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}
.month-picker__nav {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--paper-alt);
  border-radius: var(--radius-pill);
  color: var(--navy);
  font-size: var(--fs-base);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease);
}
.month-picker__nav:hover { background: #e8ecfb; }
.month-picker__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px; /* was 6px — below the 8px minimum spacing between adjacent tap targets */
}
.month-picker__cell {
  border: none;
  background: var(--paper-alt);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 9px 0;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.month-picker__cell:hover { background: #e8ecfb; }
.month-picker__cell.is-selected { background: var(--navy); color: #fff; }

/* ---------- Custom select ---------- */
/* Replaces native <select> — the dropdown *list* portion of a native select
   can't be styled via CSS at all (no control over its background/hover/
   selected colors), so it renders in flat browser-default white-on-black
   regardless of the page's theme. This gives full control, same pattern as
   the month picker above. */

.custom-select { position: relative; }
.custom-select__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.custom-select__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: inherit;
  font-size: 16px;
  text-align: left;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--paper-alt);
  color: var(--ink);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.custom-select__trigger:hover { background: #e8e5db; }
.custom-select__trigger[aria-expanded="true"] {
  background: #fff;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
.custom-select__chevron { color: var(--ink-muted); font-size: var(--fs-xs); transition: transform var(--duration) var(--ease); flex-shrink: 0; }
.custom-select__trigger[aria-expanded="true"] .custom-select__chevron { transform: rotate(180deg); }

.custom-select__panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  animation: month-picker-in var(--duration-fast) var(--ease);
}
.custom-select__option {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.custom-select__option:hover { background: #eef1fc; }
.custom-select__option.is-selected { background: var(--navy); color: #fff; font-weight: 600; }

/* ---------- Extras ---------- */

.extras { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.extras__header h2 { font-size: var(--fs-lg); }
.section-hint { font-size: var(--fs-sm); color: var(--ink-muted); margin: 0 0 14px; }

.extras-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }

.extras-empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  color: var(--ink-muted);
  font-size: var(--fs-sm);
}

.extra-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 16px;
  background: var(--paper-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.extra-row--recurring { grid-template-columns: auto 1fr 1fr 1fr auto; }
.extra-row .field { margin: 0; }
.extra-row label { font-size: var(--fs-2xs); }
.field-optional { font-weight: 400; color: var(--ink-muted); text-transform: none; }
.extra-row .remove-extra {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--danger);
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: var(--fs-md);
  line-height: 1;
  transition: background-color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.extra-row .remove-extra:hover { background: var(--danger-light); border-color: var(--danger); }

/* ---------- Buttons ---------- */

.btn {
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease), transform var(--duration-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--cta);
  border-color: var(--cta);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover { background: #166534; border-color: #166534; box-shadow: var(--shadow-md); }
.btn--secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--navy);
}
.btn--secondary:hover { background: var(--paper-alt); border-color: #c7c4b8; }
.btn--secondary:disabled { opacity: 0.45; cursor: default; }
.btn--secondary:disabled:hover { background: #fff; }
.btn--ghost {
  background: none;
  border-color: var(--navy);
  color: var(--navy);
}
.btn--ghost:hover { background: #eef1fc; }

.calculator__actions {
  margin-top: 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.share-status { font-size: var(--fs-sm); color: var(--teal); }

.form-error {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
}

/* ---------- Results ---------- */

.results[hidden] { display: none; }

.results-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
}
.results-card h3 { font-size: var(--fs-md); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat-tile {
  background: var(--paper-alt);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.stat-tile:last-child { grid-column: 1 / -1; }
.stat-tile__label {
  font-size: var(--fs-sm);
  color: var(--ink-muted);
  margin-bottom: 6px;
}
.stat-tile__value {
  font-size: var(--fs-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  letter-spacing: -0.015em;
}
/* #16A34A, not the darker button green — this is large bold text (32px/700)
   so it only needs 3:1, and reads more vivid at that size. */
.stat-tile--positive .stat-tile__value { color: var(--cta-bright); }
.stat-tile__sub {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  margin-top: 4px;
}

.chart-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
}
.chart-card h3 { font-size: var(--fs-md); }
.chart-caption { font-size: var(--fs-sm); color: var(--ink-muted); margin: 0 0 14px; }
.chart-wrap { position: relative; width: 100%; }

.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.legend-dot--plan { background: var(--teal); }
.legend-dot--original { background: #9a9691; }
.legend-dot--recurring { background: var(--green); }

/* ---------- Table ---------- */

.table-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}
.table-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.table-card__header h3 { margin: 0; font-size: var(--fs-md); }
.table-card__currency { font-size: var(--fs-sm); font-weight: 400; color: var(--ink-muted); }

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  min-width: 880px;
}
thead th {
  text-align: left;
  background: var(--paper-alt);
  color: var(--ink-muted);
  font-weight: 600;
  font-size: var(--fs-sm);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid #ece9e1;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.has-recurring { background: var(--green-light); }
tbody tr.has-lump { background: var(--teal-light); }
tbody tr.has-recurring.has-lump {
  background: linear-gradient(to right, var(--green-light) 0%, var(--green-light) 62%, var(--teal-light) 62%, var(--teal-light) 100%);
}
td.extra-amount--recurring { color: var(--green); font-weight: 700; }
td.extra-amount--lump { color: var(--teal); font-weight: 700; }
td.muted { color: var(--ink-muted); }

.table-legend { margin: -4px 0 12px; }

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
  font-size: var(--fs-sm);
  color: var(--ink-muted);
}

/* ---------- Footer ---------- */

.site-footer { border-top: 1px solid var(--line); padding: 20px 0 40px; }
.site-footer p { font-size: var(--fs-2xs); color: var(--ink-muted); max-width: 60em; }

/* ---------- Print ---------- */

@media print {
  .ad-slot, .calculator__actions, #csv-btn, .table-pagination, .site-header .site-tagline { display: none !important; }
  body { background: #fff; }
  .chart-card, .table-card, .results-card { border: 1px solid #999; break-inside: avoid; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  :root { font-size: 15px; }
  .field-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .extra-row { grid-template-columns: 1fr; }
  .extra-row .remove-extra { justify-self: end; width: auto; padding: 8px 16px; }
  .site-title { font-size: var(--fs-lg); }
  .calculator { padding: 18px; }
  .chart-card, .table-card { padding: 16px; }
  .month-picker__panel { width: 100%; left: 0; right: 0; }
  .segmented { display: flex; width: 100%; }
  .segmented__btn { flex: 1; text-align: center; }
}
