/**
 * Investment Calculator.
 *
 * Scoped to .investment-calculator so it cannot leak into the rest of the page.
 * Colors, spacing and type come from the design tokens declared in
 * themes/saturna/scss/saturna.scss.
 */

/* The paragraph's container (paragraph--investment-calculator.html.twig):
   space above the title. */
.paragraph--type--investment-calculator > .container-lg {
  padding-top: var(--spacing-5);
}

.investment-calculator {
  /* Chart series, from the site's palette. Dark -> mid -> light, so the
     three stay distinct for colorblind visitors too. */
  --ic-series-1: var(--color-midnight); /* starting amount */
  --ic-series-2: var(--color-teal);     /* contributions */
  --ic-series-3: var(--color-aqua);     /* investment growth */
  --ic-chart-surface: var(--color-stone);

  display: grid;
  gap: var(--spacing-8);
  max-width: 900px;
  margin: 0; /* left-aligned with the paragraph title */
  padding: var(--spacing-6) 0;
  color: var(--color-text-default);
  font-size: var(--text-md);
}

@media (min-width: 768px) {
  .investment-calculator {
    grid-template-columns: 3fr 2fr;
    align-items: start;
  }
}

/* Let the columns shrink below their content's width; the charts size
   themselves to the column. */
.investment-calculator > * {
  min-width: 0;
}

/* minmax(0, 1fr) and the inputs' min-width let fields shrink below the
   width their size attribute asks for, so the form fits a 320px screen. */
.investment-calculator__form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--spacing-6);
}

.investment-calculator__frequency,
.investment-calculator__plan,
.investment-calculator__estate {
  margin: 0;
  padding: 0;
  border: 0;
}

/* The retirement calculator's opening question: its heading, then the two
   plans with an "or" between them. */
.investment-calculator__plan legend {
  padding: 0;
}

.investment-calculator__plan h4 {
  margin: 0 0 var(--spacing-2);
}

.investment-calculator__or {
  margin: var(--spacing-2) 0 0;
  font-size: 20px; /* the size of the radio labels around it */
  font-weight: var(--text-bold);
}

/* Keep the $ / % / years affixes on the same line as their input. */
.investment-calculator .form-element:not(.form-element--radios) .form-element__input-wrapper {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
}

.investment-calculator .form-element__label {
  margin-bottom: var(--spacing-2);
  font-weight: var(--text-bold);
}

.investment-calculator input.form-element__input:not([type="radio"], [type="range"]) {
  flex: 1;
  min-width: 0;
  min-width: 0;
  padding: var(--spacing-3) var(--spacing-4);
  border: 1px solid var(--color-slate);
  border-radius: var(--spacing-2);
  background: var(--color-background);
  color: var(--color-text-default);
  font-family: inherit;
  font-size: var(--text-lg);
}

.investment-calculator .prefix,
.investment-calculator .suffix {
  font-size: var(--text-lg);
}

/* Sliders: the track fills the row and the current value sits to its right
   at a fixed width, so the track doesn't shift as the number changes. */
.investment-calculator input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--color-teal);
  cursor: pointer;
}

.investment-calculator .form-element--range .suffix {
  min-width: 5.5em;
  font-weight: var(--text-bold);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* A contribution amount, field or result, with the Monthly / Bi-Monthly
   toggle beside it, wrapping below it when there is no room. */
.investment-calculator__with-frequency {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-2) var(--spacing-4);
}

.investment-calculator__with-frequency > .form-element {
  flex: 1 1 11rem;
  min-width: 0;
}

/* Beside a field, line the toggle up with the input, below the field's title,
   rather than the middle of the title, input and description together. */
.investment-calculator__with-frequency > .form-element + .investment-calculator__frequency {
  align-self: flex-start;
  margin-top: var(--spacing-8); /* centers the two options on the input box */
}

.investment-calculator__result .investment-calculator__with-frequency {
  margin-bottom: var(--spacing-4);
}

/* Beside the toggle, "per month" goes under the amount to leave it room. */
.investment-calculator__with-frequency .investment-calculator__balance {
  flex: 1 1 auto;
  margin: 0;
}

.investment-calculator__with-frequency .investment-calculator__per {
  display: block;
}

.investment-calculator__frequency .form-element__input-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2);
}

.investment-calculator .investment-calculator__frequency .form-element--radios .form-element__label {
  margin: 0;
  font-size: var(--text-md);
}

.investment-calculator__frequency-option {
  display: grid;
  line-height: 1.2;
}

.investment-calculator__frequency-option small {
  font-size: var(--text-sm);
  color: var(--color-text-accent);
}

/* The estate checkbox, with its field below while ticked. */
.investment-calculator__estate {
  display: grid;
  gap: var(--spacing-4);
}

.investment-calculator .form-element--checkbox .form-element__label {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  margin: 0;
  cursor: pointer;
}

.investment-calculator input[type="checkbox"] {
  width: 1.3em;
  height: 1.3em;
  margin: 0;
  accent-color: var(--color-teal);
}

.investment-calculator .form-element--radios input[type="radio"] {
  width: 1.3em;
  height: 1.3em;
  flex-shrink: 0; /* keep its size beside a label that wraps */
  margin: 0;
  accent-color: var(--color-teal);
  cursor: pointer;
}

.investment-calculator .form-element--radios .form-element__label {
  font-size: 20px; /* between --text-md and --text-lg */
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-2);
  margin: var(--spacing-2) var(--spacing-4) 0 0;
  font-weight: var(--text-normal);
}

.investment-calculator .form-element__description {
  color: var(--color-text-accent);
  font-size: var(--text-sm);
}

.investment-calculator__result {
  padding: var(--spacing-6);
  border-radius: 10px;
  background: var(--color-stone);
}

.investment-calculator__result-label {
  margin: 0;
  font-size: var(--text-sm);
}

.investment-calculator__balance {
  margin: 0 0 var(--spacing-4);
  font-size: var(--text-xl);
  font-weight: var(--text-bold);
}

.investment-calculator__per {
  font-size: var(--text-md);
  font-weight: var(--text-normal);
}

/* A result sentence carrying figures of its own, read before the headline. */
.investment-calculator__result-label--lead {
  font-size: var(--text-md);
}

.investment-calculator__result-label strong {
  font-weight: var(--text-bold);
}

/* Headline values with a small label above each (before and after inflation). */
.investment-calculator__values {
  margin: var(--spacing-2) 0 0;
}

.investment-calculator__values dt {
  font-size: var(--text-sm);
  font-weight: var(--text-normal);
}

.investment-calculator__breakdown {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--spacing-2) var(--spacing-4);
  margin: 0 0 var(--spacing-4);
}

.investment-calculator__breakdown dd {
  margin: 0;
  text-align: right;
}

.investment-calculator__disclaimer {
  margin: var(--spacing-4) 0 0;
  color: var(--color-text-accent);
  font-size: var(--text-xs);
}

/* ------------------------------------------------------------- Charts ----- */

.ic-chart {
  margin: var(--spacing-6) 0 0;
}

.ic-chart__title {
  margin-bottom: var(--spacing-2);
  font-weight: var(--text-bold);
}

.ic-chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-1) var(--spacing-4);
  margin: 0 0 var(--spacing-2);
  padding: 0;
  list-style: none;
  font-size: var(--text-xs);
}

.ic-chart__swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: var(--spacing-1);
  border-radius: 2px;
  vertical-align: baseline;
}

.ic-chart__plot {
  position: relative;
}

.ic-chart__plot svg {
  display: block;
  overflow: visible;
}

.ic-chart__plot svg:focus-visible {
  outline: 2px solid var(--color-text-default);
  outline-offset: 2px;
}

.ic-chart__grid {
  stroke: var(--color-gray);
  stroke-width: 1;
}

.ic-chart__tick {
  fill: var(--color-text-accent);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.ic-chart__gap {
  fill: none;
  stroke: var(--ic-chart-surface);
  stroke-width: 2;
  stroke-linejoin: round;
}

/* The retirement chart's "Retire at" line. */
.ic-chart__marker line {
  stroke: var(--color-text-default);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.ic-chart__crosshair line {
  stroke: var(--color-text-default);
  stroke-width: 1;
}

.ic-chart__crosshair circle {
  fill: var(--color-text-default);
  stroke: var(--ic-chart-surface);
  stroke-width: 2;
}

.ic-chart__segment {
  cursor: pointer;
  outline: none;
}

.ic-chart__segment:hover,
.ic-chart__segment:focus-visible {
  opacity: 0.8;
}

.ic-chart__tooltip {
  position: absolute;
  top: 0;
  z-index: 1;
  min-width: 160px;
  padding: var(--spacing-2) var(--spacing-3);
  border: 1px solid var(--color-gray);
  border-radius: var(--spacing-2);
  background: var(--color-background);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);
  font-size: var(--text-xs);
  pointer-events: none;
}

.ic-chart__tooltip p {
  margin: 0;
  white-space: nowrap;
}

.ic-chart__tooltip-title {
  margin-bottom: var(--spacing-1) !important;
  font-weight: var(--text-bold);
}

.ic-chart__line-key {
  display: inline-block;
  width: 12px;
  height: 2px;
  margin-right: var(--spacing-1);
  vertical-align: middle;
}

.ic-chart__table {
  margin-top: var(--spacing-2);
  font-size: var(--text-xs);
}

.ic-chart__table summary {
  cursor: pointer;
}

.ic-chart__table-scroll {
  max-height: 240px;
  margin-top: var(--spacing-2);
  overflow: auto;
}

.ic-chart__table table,
.ic-chart__values {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.ic-chart__table th,
.ic-chart__table td {
  padding: 2px var(--spacing-1);
  text-align: right;
  white-space: nowrap;
}

.ic-chart__table th[scope="row"],
.ic-chart__values th {
  text-align: left;
  font-weight: var(--text-normal);
}

.ic-chart__values {
  margin-top: var(--spacing-3);
  font-size: var(--text-sm);
}

.ic-chart__values td {
  padding: 2px 0 2px var(--spacing-3);
  text-align: right;
}
