/*!
 * refi-balance-curve.css  v1.0.0
 * Styles for the refinance balance-curve chart. Pair with refi-balance-curve.js.
 *
 * Every color is a custom property. Map them to the site's existing design tokens
 * instead of hard-coding new values (see HANDOFF.md, "Colors").
 */

/* -------------------------------------------------------------------------- */
/* Tokens                                                                     */
/* -------------------------------------------------------------------------- */

[data-refi-curve] {
  --refi-curve-ink: var(--color-green-800, #104547); /* Deep Forest (brand): area under the curves */
  --refi-curve-cost: #b5402c; /* Closing costs / cash out. Approved exception to brand palette */
  --refi-curve-savings: rgba(242, 207, 99, 0.5); /* Interest savings. Approved exception */
  --refi-curve-line: #8cc63e; /* MSFG Green (brand): new loan line */
  --refi-curve-original: #7d9e93; /* Current loan (dotted line) */
  --refi-curve-axis: #8f9a94;
  --refi-curve-axis-label: var(--color-muted, #5d6b63);
  --refi-curve-marker: #8cc63e; /* Dot beside the active card title */
  --refi-curve-surface: var(--color-paper-2, #eff1ec); /* Section background: strip fill + hollow end ring */
  --refi-curve-strip-rule: rgba(16, 69, 71, 0.14); /* Divider under the sticky strip */

  --refi-curve-axis-gutter: 32px; /* Space left of the stage that holds the y-axis label */
  --refi-curve-strip-height: 150px; /* Narrow layout chart height */
  --refi-curve-sticky-top: 0px; /* Set to the sticky site-header height, if there is one */
  --refi-curve-duration: 0.35s;
}

/* Text colors used by the white-text copies of the cards. The site's card CSS must read
   --refi-card-* variables (with its normal colors as fallbacks) for this to work. */
.refi-curve__ink {
  --refi-card-title: #ffffff;
  --refi-card-eyebrow: #cfe6b0;
  --refi-card-body: rgba(255, 255, 255, 0.88);
  --refi-card-link: #ffffff;
  --refi-card-rule: rgba(255, 255, 255, 0.16);
}

.refi-curve__ink--cost {
  --refi-card-eyebrow: #ffe0d4;
}

/* -------------------------------------------------------------------------- */
/* Layering (desktop: chart behind the cards)                                 */
/* -------------------------------------------------------------------------- */

[data-refi-curve-stage] {
  position: relative; /* clip paths are measured from this box: no padding or border here */
}

[data-refi-curve-stage] > [data-refi-curve-grid] {
  position: relative;
  z-index: 1;
}

.refi-curve__layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.refi-curve__back {
  z-index: 0;
}

.refi-curve__ink {
  z-index: 2;
}

.refi-curve__ink--base {
  background: var(--refi-curve-ink);
}

.refi-curve__ink--cost {
  background: var(--refi-curve-cost);
}

.refi-curve__ink > .refi-curve__ink-grid {
  position: absolute;
  inset: 0;
  margin: 0;
  z-index: auto;
}

.refi-curve__front {
  z-index: 3;
  overflow: visible;
}

/* -------------------------------------------------------------------------- */
/* Chart marks                                                                */
/* -------------------------------------------------------------------------- */

.refi-curve__under {
  fill: var(--refi-curve-ink);
}

.refi-curve__cost {
  fill: var(--refi-curve-cost);
}

.refi-curve__savings {
  fill: var(--refi-curve-savings);
}

.refi-curve__axes {
  fill: none;
  stroke: var(--refi-curve-axis);
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.refi-curve__original {
  fill: none;
  stroke: var(--refi-curve-original);
  stroke-width: 1.4;
  stroke-dasharray: 4 4;
}

.refi-curve__original-end {
  fill: var(--refi-curve-surface);
  stroke: var(--refi-curve-original);
  stroke-width: 1.4;
}

.refi-curve__line {
  fill: none;
  stroke: var(--refi-curve-line);
  stroke-width: 2.4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.refi-curve__end {
  fill: var(--refi-curve-line);
  stroke: var(--refi-curve-ink);
  stroke-width: 1.2;
}

/* -------------------------------------------------------------------------- */
/* Axes: hidden until the chart area is hovered or focused                    */
/* -------------------------------------------------------------------------- */

.refi-curve__hover-only {
  opacity: 0;
  transition: opacity var(--refi-curve-duration) ease;
}

[data-refi-curve-stage]:hover .refi-curve__hover-only,
[data-refi-curve-stage]:focus-within .refi-curve__hover-only {
  opacity: 1;
}

@media (hover: none) {
  .refi-curve__hover-only {
    opacity: 1;
  }
}

.refi-curve__axis-label {
  position: absolute;
  z-index: 3;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--refi-curve-axis-label);
  white-space: nowrap;
  pointer-events: none;
}

.refi-curve__axis-label--y {
  left: calc(var(--refi-curve-axis-gutter) * -1 + 8px);
  top: 10px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.refi-curve__axis-label--x {
  right: 0;
  top: calc(100% + 10px);
}

/* -------------------------------------------------------------------------- */
/* Active card marker                                                         */
/* -------------------------------------------------------------------------- */

[data-refi-curve] [data-refi-shape] {
  position: relative;
}

[data-refi-curve] [data-refi-shape]::before {
  content: '';
  position: absolute;
  left: var(--refi-card-marker-x, 6px);
  top: var(--refi-card-marker-y, 2.6rem);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--refi-curve-marker);
  transform: scale(0);
  transition: transform 0.3s ease;
}

[data-refi-curve] [data-refi-shape].is-refi-active::before {
  transform: scale(1);
}

/* -------------------------------------------------------------------------- */
/* Narrow layout: sticky chart strip above the stacked cards                  */
/* -------------------------------------------------------------------------- */

[data-refi-curve-body] {
  display: flex;
  flex-direction: column;
}

[data-refi-curve-strip] {
  display: none;
}

[data-refi-curve-layout='strip'] [data-refi-curve-strip] {
  display: block;
  order: 0;
  position: sticky;
  top: var(--refi-curve-sticky-top);
  z-index: 5;
  height: var(--refi-curve-strip-height);
  padding-bottom: 6px;
  background: var(--refi-curve-surface);
  border-bottom: 1px solid var(--refi-curve-strip-rule);
}

[data-refi-curve-layout='strip'] [data-refi-curve-key] {
  order: 1;
}

[data-refi-curve-layout='strip'] [data-refi-curve-stage] {
  order: 2;
}

.refi-curve__strip-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.refi-curve__strip-label {
  font-size: 11px;
  letter-spacing: 0.02em;
  fill: var(--refi-curve-axis-label);
}

/* -------------------------------------------------------------------------- */
/* Legend + disclaimer (only shown once the chart is running)                 */
/* -------------------------------------------------------------------------- */

[data-refi-curve]:not(.is-refi-ready) [data-refi-curve-key] {
  display: none;
}

.refi-curve__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.refi-curve__legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--refi-curve-axis-label);
}

.refi-curve__swatch {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 0;
}

.refi-curve__swatch--original {
  border-top: 1.5px dashed var(--refi-curve-original);
}

.refi-curve__swatch--line {
  border-top: 2.5px solid var(--refi-curve-line);
}

.refi-curve__swatch--cost,
.refi-curve__swatch--savings {
  width: 12px;
  height: 9px;
  border-radius: 2px;
}

.refi-curve__swatch--cost {
  background: var(--refi-curve-cost);
}

.refi-curve__swatch--savings {
  background: var(--refi-curve-savings);
}

.refi-curve__disclaimer {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--refi-curve-axis-label);
}

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

@media (prefers-reduced-motion: reduce) {
  .refi-curve__hover-only,
  [data-refi-curve] [data-refi-shape]::before {
    transition: none;
  }
}
