/* ============================================================
   CalcWise — Calculator Components
   calculator-styles.css  (single source of truth, part 2 of 2)
   Relies on tokens defined in styles.css.
   ============================================================ */

/* ── 1. Calculator wrapper & layout ─────────────────────── */
.calculator-wrapper { padding-block: var(--s-10); }

.calc-layout {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: var(--s-6);
  align-items: start;
}

.calc-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: var(--s-8);
  overflow: hidden;
}
.calc-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), #6366f1 55%, var(--accent));
}

.calc-inputs {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

.calc-section-title {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-2);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--border-2);
  margin-top: var(--s-2);
}

/* Results panel — sticky on desktop */
.results-panel {
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-6);
  background: linear-gradient(160deg, #f4f8ff 0%, #eaf1fe 100%);
  border: 1px solid #d4e0fb;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

/* ── 2. Input groups ────────────────────────────────────── */
.input-group { display: flex; flex-direction: column; gap: var(--s-2); }

.input-label {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
}
.input-label small { font-weight: 400; font-size: .8rem; color: var(--text-2); }

.input-field {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input-field::placeholder { color: var(--text-2); font-weight: 400; }
.input-field:hover { border-color: #b6c2d4; }
.input-field:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(26 86 219 / .25);
}

textarea.input-field { min-height: 110px; resize: vertical; line-height: 1.6; }

select.input-field {
  padding-right: 40px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.input-hint { font-size: .8rem; color: var(--text-2); line-height: 1.5; }
.input-hint strong { color: var(--text); }

/* Prefix / suffix addons */
.input-addon {
  display: flex;
  align-items: stretch;
}
.input-addon .input-field { border-radius: 0; }
.input-prefix, .input-suffix {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  white-space: nowrap;
}
.input-prefix {
  border-right: none;
  border-radius: var(--r) 0 0 var(--r);
}
.input-suffix {
  border-left: none;
  border-radius: 0 var(--r) var(--r) 0;
}
.input-addon .input-prefix + .input-field { border-radius: 0 var(--r) var(--r) 0; }
.input-addon .input-field:has(+ .input-suffix) { border-radius: var(--r) 0 0 var(--r); }
.input-addon:focus-within .input-prefix,
.input-addon:focus-within .input-suffix {
  border-color: var(--primary);
}
.input-addon:focus-within .input-field {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(26 86 219 / .25);
  position: relative;
  z-index: 1;
}

/* Input paired with a slider */
.input-with-slider { display: flex; flex-direction: column; gap: var(--s-3); }
.slider-value {
  align-self: flex-end;
  font-size: .85rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

/* ── 3. Range slider ────────────────────────────────────── */
.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--border);
  outline: none;
  cursor: pointer;
  accent-color: var(--primary);
}
/* gradient-fill feel via background; JS may set --fill for progress */
.range-slider {
  background: linear-gradient(90deg, var(--primary) 0 var(--fill, 50%), var(--border) var(--fill, 50%) 100%);
}
.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary);
  box-shadow: 0 2px 6px rgb(26 86 219 / .35);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.range-slider::-webkit-slider-thumb:hover { transform: scale(1.12); box-shadow: 0 2px 10px rgb(26 86 219 / .45); }
.range-slider::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary);
  box-shadow: 0 2px 6px rgb(26 86 219 / .35);
  cursor: pointer;
}
.range-slider::-moz-range-progress { background: var(--primary); height: 8px; border-radius: var(--r-full); }
.range-slider::-moz-range-track { background: var(--border); height: 8px; border-radius: var(--r-full); }
.range-slider:focus-visible { outline: 3px solid rgb(26 86 219 / .4); outline-offset: 4px; }

/* ── 4. Term buttons ────────────────────────────────────── */
.term-buttons { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.term-btn {
  flex: 1 1 auto;
  min-width: 56px;
  padding: 10px 14px;
  font-size: .9rem;
  font-weight: 700;
  color: var(--text-2);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.term-btn:hover { color: var(--primary); border-color: #c7d7fd; background: var(--primary-light); }
.term-btn.active {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-color: transparent;
  box-shadow: var(--shadow-primary);
}

/* ── 5. Toggle switch (% vs $, etc.) ────────────────────── */
.toggle-switch {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-full);
  gap: 2px;
}
.toggle-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 18px;
  font-size: .875rem;
  font-weight: 700;
  color: var(--text-2);
  border-radius: var(--r-full);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}
.toggle-option:hover { color: var(--primary); }
.toggle-option.active {
  color: #fff;
  background: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ── 6. Radio pills ─────────────────────────────────────── */
.radio-pills { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 9px 16px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}
.radio-pill:hover { color: var(--primary); border-color: #c7d7fd; }
.radio-pill.active,
.radio-pill:has(input:checked) {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}
.radio-pill input { position: absolute; opacity: 0; pointer-events: none; }

/* ── 7. Result highlight ────────────────────────────────── */
.result-highlight {
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: var(--s-6) var(--s-5);
  border-radius: var(--r);
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  box-shadow: var(--shadow-primary);
}
.result-highlight::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% -20%, rgb(255 255 255 / .22), transparent 55%);
  pointer-events: none;
}
.result-highlight-label {
  position: relative;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #cfe0ff;
  margin-bottom: var(--s-2);
}
.result-highlight-value {
  position: relative;
  font-size: clamp(2.2rem, 6vw, 3rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

/* ── 8. Result metrics ──────────────────────────────────── */
.result-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}
.result-metric {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--s-4);
  background: var(--surface);
  border: 1px solid #d4e0fb;
  border-radius: var(--r);
}
.metric-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-2);
}
.metric-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.metric-value.positive { color: var(--accent); }
.metric-value.negative { color: var(--danger); }

/* ── 9. Breakdown bar ───────────────────────────────────── */
.breakdown-bar {
  display: flex;
  width: 100%;
  height: 22px;
  border-radius: var(--r-full);
  overflow: hidden;
  background: var(--surface-2);
}
.breakdown-segment {
  height: 100%;
  transition: width .5s cubic-bezier(.4, 0, .2, 1);
}
.breakdown-segment:nth-child(1) { background: var(--primary); }
.breakdown-segment:nth-child(2) { background: #f97316; }
.breakdown-segment:nth-child(3) { background: #8b5cf6; }
.breakdown-segment:nth-child(4) { background: var(--accent); }
.breakdown-segment:nth-child(5) { background: #ec4899; }
.breakdown-segment:nth-child(6) { background: #06b6d4; }

.breakdown-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3) var(--s-4);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: .82rem;
  color: var(--text-2);
  font-weight: 500;
}
.legend-item::before {
  content: '';
  width: 11px; height: 11px;
  border-radius: 3px;
  background: var(--text-2);
  flex-shrink: 0;
}
.legend-item:nth-child(1)::before { background: var(--primary); }
.legend-item:nth-child(2)::before { background: #f97316; }
.legend-item:nth-child(3)::before { background: #8b5cf6; }
.legend-item:nth-child(4)::before { background: var(--accent); }
.legend-item:nth-child(5)::before { background: #ec4899; }
.legend-item:nth-child(6)::before { background: #06b6d4; }

/* ── 10. Pie chart (conic-gradient) ─────────────────────── */
.pie-chart {
  width: 180px; height: 180px;
  border-radius: 50%;
  flex-shrink: 0;
  background: conic-gradient(
    var(--primary) 0 var(--p1, 60%),
    #f97316 var(--p1, 60%) var(--p2, 78%),
    #8b5cf6 var(--p2, 78%) var(--p3, 90%),
    var(--accent) var(--p3, 90%) 100%
  );
  box-shadow: var(--shadow);
  position: relative;
}
.pie-chart::after {
  content: '';
  position: absolute;
  inset: 28%;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: inset 0 1px 3px rgb(16 24 40 / .08);
}
.pie-legend {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

/* Legend color swatches — used by .legend-item children on the homepage
   pie legend and several calculator pages (cd, net-worth, paycheck,
   student-loan, 401k, apr, future-value, home-affordability, etc.).
   Sized/shaped to match the .legend-item::before dot below. */
.legend-color,
.legend-dot,
.legend-swatch {
  display: inline-block;
  flex-shrink: 0;
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--text-2);
}
/* When a legend row already renders its own swatch element, suppress the
   generic ::before dot so rows don't show two color indicators. */
.legend-item:has(.legend-color, .legend-dot, .legend-swatch)::before {
  content: none;
}
/* Named modifiers (color-mapped to match .breakdown-segment / .legend-item::before order) */
.legend-principal { background: var(--primary); }
.legend-tax { background: #f97316; }
.legend-insurance { background: #8b5cf6; }
.legend-pmi { background: var(--accent); }
.legend-hoa { background: #ec4899; }
.legend-interest { background: #f97316; }
/* .legend-swatch rows with no modifier class (e.g. 401k contribution
   breakdown) follow the same 1st/2nd/3rd row order as .breakdown-segment. */
.legend-item:nth-child(1) > .legend-swatch { background: var(--primary); }
.legend-item:nth-child(2) > .legend-swatch { background: #f97316; }
.legend-item:nth-child(3) > .legend-swatch { background: #8b5cf6; }

/* ── 11. Bar chart ──────────────────────────────────────── */
.chart { width: 100%; }
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  height: 200px;
  padding-top: var(--s-4);
  border-bottom: 2px solid var(--border);
}
.chart-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 10px;
}
.chart-bar-fill {
  width: 100%;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: linear-gradient(to top, var(--primary), #6366f1);
  transition: height .5s cubic-bezier(.4, 0, .2, 1);
}

/* ── 12. Amortization & comparison tables ───────────────── */
.amortization-table,
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  min-width: 540px;
}
.amortization-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 12px 16px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}
.amortization-table thead th:first-child { text-align: left; }
.amortization-table tbody td {
  padding: 11px 16px;
  text-align: right;
  border-bottom: 1px solid var(--border-2);
  font-variant-numeric: tabular-nums;
}
.amortization-table tbody td:first-child { text-align: left; font-weight: 700; color: var(--text-2); }
.amortization-table tbody tr:nth-child(even) { background: #fafbfd; }
.amortization-table tbody tr:hover { background: var(--primary-light); }

.comparison-table { min-width: 480px; }
.comparison-table thead th {
  padding: 14px 18px;
  font-weight: 700;
  text-align: center;
  font-size: .9rem;
  background: var(--surface-2);
  border-bottom: 2px solid var(--border);
}
.comparison-table thead th:first-child {
  text-align: left;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: .76rem;
}
.comparison-table tbody td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-2);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.comparison-table tbody td:first-child { text-align: left; font-weight: 700; color: var(--text); background: var(--surface-2); }
.comparison-table tbody tr:hover td { background: var(--primary-light); }
.comparison-table tfoot td {
  padding: 14px 18px;
  font-weight: 800;
  background: var(--primary-light);
  border-top: 2px solid var(--primary);
  text-align: center;
  color: var(--primary-dark);
}
.comparison-table tfoot td:first-child { text-align: left; }

/* ── 13. Calculate button spacing ───────────────────────── */
.calc-inputs .btn-calculate { margin-top: var(--s-3); }

/* ── 14. Responsive ─────────────────────────────────────── */
@media (max-width: 1024px) {
  .calc-layout { grid-template-columns: 1fr; }
  .results-panel { position: static; top: auto; }
}

@media (max-width: 768px) {
  .calc-card { padding: var(--s-6) var(--s-5); }
  .result-metrics { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .calc-card { padding: var(--s-5) var(--s-4); }
  .result-metrics { grid-template-columns: 1fr; }
  .pie-chart { width: 150px; height: 150px; }
  .term-btn { padding: 9px 10px; font-size: .82rem; }
  .toggle-option { padding: 7px 14px; }
}

/* ── 15. Reduced motion ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .breakdown-segment, .chart-bar-fill, .progress-bar { transition: none !important; }
}

/* ── 16. Print ──────────────────────────────────────────── */
@media print {
  .calc-layout { grid-template-columns: 1fr; gap: 16pt; }
  .results-panel { position: static; background: none; border: 1px solid #ccc; }
  .calc-card { box-shadow: none; border: 1px solid #ccc; }
  .calc-card::before { display: none; }
  .result-highlight { background: #eee !important; color: #000; box-shadow: none; }
  .result-highlight-label { color: #444; }
  .range-slider, .term-buttons, .toggle-switch, .radio-pills, .btn-calculate, .btn-reset { display: none !important; }
  .amortization-table, .comparison-table { min-width: 0; font-size: 9pt; }
  tr.hidden-row { display: table-row !important; }
  table { page-break-inside: avoid; }
  thead { display: table-header-group; }
}
