/* ==========================================================================
   Material Design 3 (Material You) Design Tokens & Responsive Styles
   ========================================================================== */

:root {
  /* M3 Motion & Shape Tokens */
  --md-sys-motion-emphasized: cubic-bezier(0.2, 0, 0, 1);
  --md-sys-shape-corner-small: 10px;
  --md-sys-shape-corner-medium: 16px;
  --md-sys-shape-corner-large: 24px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full: 9999px;

  /* Default Palette: Ocean Blue (Light) */
  --md-sys-color-primary: #1a56c4;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #d8e2ff;
  --md-sys-color-on-primary-container: #001a43;

  --md-sys-color-secondary: #535e78;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #d8e2ff;
  --md-sys-color-on-secondary-container: #101b32;

  --md-sys-color-tertiary: #0b6e4f;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #c4f1de;
  --md-sys-color-on-tertiary-container: #002116;

  --md-sys-color-error: #ba1a1a;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;

  --md-sys-color-background: #f5f7fc;
  --md-sys-color-on-background: #191c22;
  --md-sys-color-surface: #f5f7fc;
  --md-sys-color-on-surface: #191c22;
  --md-sys-color-on-surface-variant: #44474f;
  --md-sys-color-outline: #747780;
  --md-sys-color-outline-variant: #c4c6d0;

  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #ffffff;
  --md-sys-color-surface-container: #eef1f8;
  --md-sys-color-surface-container-high: #e6ebf5;
  --md-sys-color-surface-container-highest: #dce3f0;

  --md-sys-color-inverse-surface: #2d3038;
  --md-sys-color-inverse-on-surface: #f0f1f8;

  /* Chart Series Tokens */
  --chart-pi: var(--md-sys-color-primary);
  --chart-tax: #0d9488;
  --chart-ins: #d97706;
  --chart-hoa: #7c3aed;
  --chart-pmi: #e11d48;
  --chart-principal: var(--md-sys-color-tertiary);
  --chart-interest: #d97706;

  --elevation-1: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px 1px rgba(15, 23, 42, 0.04);
  --elevation-2: 0 2px 6px 2px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.08);
  --elevation-3: 0 6px 18px 2px rgba(15, 23, 42, 0.12);
}

/* Dynamic Seed Palettes (Light) */
html[data-palette="teal"] {
  --md-sys-color-primary: #006a60;
  --md-sys-color-primary-container: #a0f2e4;
  --md-sys-color-on-primary-container: #00201c;
  --md-sys-color-secondary: #4a635f;
  --md-sys-color-secondary-container: #cce8e2;
  --md-sys-color-on-secondary-container: #05201c;
  --md-sys-color-tertiary: #42617d;
  --md-sys-color-tertiary-container: #cbe6ff;
  --md-sys-color-on-tertiary-container: #001e30;
  --md-sys-color-background: #f4f9f8;
  --md-sys-color-surface: #f4f9f8;
  --md-sys-color-surface-container: #eaf2f0;
  --md-sys-color-surface-container-high: #e1ece9;
  --md-sys-color-surface-container-highest: #d6e4e1;
}

html[data-palette="plum"] {
  --md-sys-color-primary: #6750a4;
  --md-sys-color-primary-container: #eaddff;
  --md-sys-color-on-primary-container: #21005d;
  --md-sys-color-secondary: #625b71;
  --md-sys-color-secondary-container: #e8def8;
  --md-sys-color-on-secondary-container: #1d192b;
  --md-sys-color-tertiary: #0b6e4f;
  --md-sys-color-tertiary-container: #c4f1de;
  --md-sys-color-on-tertiary-container: #002116;
  --md-sys-color-background: #f8f5fc;
  --md-sys-color-surface: #f8f5fc;
  --md-sys-color-surface-container: #f1ebf8;
  --md-sys-color-surface-container-high: #eae2f4;
  --md-sys-color-surface-container-highest: #e2d8ef;
}

html[data-palette="terracotta"] {
  --md-sys-color-primary: #9c4327;
  --md-sys-color-primary-container: #ffdbd0;
  --md-sys-color-on-primary-container: #390c00;
  --md-sys-color-secondary: #77574d;
  --md-sys-color-secondary-container: #ffdbd0;
  --md-sys-color-on-secondary-container: #2c150e;
  --md-sys-color-tertiary: #2e6b4e;
  --md-sys-color-tertiary-container: #b5f1cf;
  --md-sys-color-on-tertiary-container: #002113;
  --md-sys-color-background: #fcf6f4;
  --md-sys-color-surface: #fcf6f4;
  --md-sys-color-surface-container: #f6edea;
  --md-sys-color-surface-container-high: #efe4e0;
  --md-sys-color-surface-container-highest: #e7dad5;
}

/* Dark Mode Tokens */
html[data-theme="dark"] {
  --md-sys-color-primary: #adc6ff;
  --md-sys-color-on-primary: #002e69;
  --md-sys-color-primary-container: #004494;
  --md-sys-color-on-primary-container: #d8e2ff;

  --md-sys-color-secondary: #bcc6e0;
  --md-sys-color-on-secondary: #263047;
  --md-sys-color-secondary-container: #3c475f;
  --md-sys-color-on-secondary-container: #d8e2ff;

  --md-sys-color-tertiary: #7bdcb8;
  --md-sys-color-on-tertiary: #003827;
  --md-sys-color-tertiary-container: #005139;
  --md-sys-color-on-tertiary-container: #c4f1de;

  --md-sys-color-error: #ffb4ab;
  --md-sys-color-error-container: #93000a;
  --md-sys-color-on-error-container: #ffdad6;

  --md-sys-color-background: #101319;
  --md-sys-color-on-background: #e3e6ee;
  --md-sys-color-surface: #101319;
  --md-sys-color-on-surface: #e3e6ee;
  --md-sys-color-on-surface-variant: #c2c6d2;
  --md-sys-color-outline: #8d919c;
  --md-sys-color-outline-variant: #3b3f4a;

  --md-sys-color-surface-container-lowest: #0b0e14;
  --md-sys-color-surface-container-low: #171b23;
  --md-sys-color-surface-container: #1d222c;
  --md-sys-color-surface-container-high: #242a36;
  --md-sys-color-surface-container-highest: #2e3544;

  --md-sys-color-inverse-surface: #e3e6ee;
  --md-sys-color-inverse-on-surface: #1d2026;

  --chart-tax: #2dd4bf;
  --chart-ins: #fbbf24;
  --chart-hoa: #c084fc;
  --chart-pmi: #fb7185;
  --chart-interest: #fbbf24;

  --elevation-1: 0 1px 3px rgba(0, 0, 0, 0.35);
  --elevation-2: 0 3px 10px rgba(0, 0, 0, 0.4);
  --elevation-3: 0 8px 24px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"][data-palette="teal"] {
  --md-sys-color-primary: #82d6c8;
  --md-sys-color-on-primary: #003731;
  --md-sys-color-primary-container: #005048;
  --md-sys-color-on-primary-container: #a0f2e4;
  --md-sys-color-secondary-container: #334b47;
  --md-sys-color-on-secondary-container: #cce8e2;
  --md-sys-color-tertiary: #a2cced;
  --md-sys-color-tertiary-container: #284964;
  --md-sys-color-on-tertiary-container: #cbe6ff;
}

html[data-theme="dark"][data-palette="plum"] {
  --md-sys-color-primary: #d0bcff;
  --md-sys-color-on-primary: #381e72;
  --md-sys-color-primary-container: #4f378b;
  --md-sys-color-on-primary-container: #eaddff;
  --md-sys-color-secondary-container: #4a4458;
  --md-sys-color-on-secondary-container: #e8def8;
}

html[data-theme="dark"][data-palette="terracotta"] {
  --md-sys-color-primary: #ffb59e;
  --md-sys-color-on-primary: #5d1902;
  --md-sys-color-primary-container: #7d2c12;
  --md-sys-color-on-primary-container: #ffdbd0;
  --md-sys-color-secondary-container: #5d3f36;
  --md-sys-color-on-secondary-container: #ffdbd0;
}

/* ==========================================================================
   Base Reset & Typography
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  font-family: "Google Sans Text", "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
  transition: background-color 220ms var(--md-sys-motion-emphasized), color 220ms var(--md-sys-motion-emphasized);
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   Top App Bar
   ========================================================================== */

.top-app-bar {
  position: static;
  z-index: 40;
  background: color-mix(in srgb, var(--md-sys-color-surface) 90%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 60%, transparent);
}

@media (min-width: 1024px) {
  .top-app-bar {
    position: sticky;
    top: 0;
  }
}

.top-app-bar__inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand__icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  flex-shrink: 0;
}

.brand__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.brand__subtitle {
  margin: 0.1rem 0 0;
  font-size: 0.78rem;
  color: var(--md-sys-color-on-surface-variant);
}

.top-app-bar__actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 34px;
  padding: 0 0.8rem;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 180ms var(--md-sys-motion-emphasized);
}

.status-chip:hover {
  background: var(--md-sys-color-surface-container-high);
}

.status-chip.is-ok {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.status-chip.is-err {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.status-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.palette-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.45rem;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container);
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 160ms var(--md-sys-motion-emphasized), border-color 160ms;
}

.swatch[data-set-palette="blue"] { background: #2563eb; }
.swatch[data-set-palette="teal"] { background: #00897b; }
.swatch[data-set-palette="plum"] { background: #7c3aed; }
.swatch[data-set-palette="terracotta"] { background: #c2512f; }

.swatch:hover { transform: scale(1.12); }

.swatch.is-active {
  border-color: var(--md-sys-color-on-surface);
  transform: scale(1.08);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 160ms var(--md-sys-motion-emphasized), transform 120ms;
}

.icon-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ==========================================================================
   Mobile Sticky Summary Bar
   ========================================================================== */

.mobile-summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 35;
  padding: 0.65rem 1rem;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-bottom: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 50%, transparent);
  box-shadow: var(--elevation-1);
}

#results-pane {
  scroll-margin-top: 72px;
}

.mobile-summary-bar__metric {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.mobile-summary-bar__label {
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.85;
}

.mobile-summary-bar__metric strong {
  font-size: 1.05rem;
}

@media (min-width: 1024px) {
  .mobile-summary-bar {
    display: none;
  }
}

/* ==========================================================================
   Page Layout & Scenario Strip
   ========================================================================== */

.page-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.15rem 1.25rem 3.5rem;
}

.preset-strip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: none;
}

.preset-strip::-webkit-scrollbar {
  display: none;
}

.preset-strip__label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--md-sys-color-on-surface-variant);
  flex-shrink: 0;
}

.chip-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.m3-chip {
  height: 36px;
  padding: 0 0.95rem;
  border-radius: var(--md-sys-shape-corner-small);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms var(--md-sys-motion-emphasized),
    color 160ms,
    border-color 160ms;
}

.m3-chip:hover {
  background: var(--md-sys-color-surface-container);
}

.m3-chip.is-selected {
  border-color: transparent;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-weight: 600;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (min-width: 1024px) {
  .workspace-grid {
    grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
    gap: 1.5rem;
  }
}

.pane {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
}

/* ==========================================================================
   M3 Cards
   ========================================================================== */

.m3-card {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 55%, transparent);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 1.35rem 1.4rem;
  box-shadow: var(--elevation-1);
}

.m3-card--hero {
  background: linear-gradient(
    145deg,
    var(--md-sys-color-surface-container-low) 0%,
    color-mix(in srgb, var(--md-sys-color-primary-container) 34%, var(--md-sys-color-surface-container-low)) 100%
  );
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: 1.6rem;
}

.m3-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.m3-card__header--wrap {
  flex-wrap: wrap;
}

.m3-card__title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.m3-card__sub {
  margin: 0.15rem 0 0;
  font-size: 0.83rem;
  color: var(--md-sys-color-on-surface-variant);
}

.info-pill {
  padding: 0.25rem 0.7rem;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-size: 0.78rem;
  font-weight: 600;
}

/* ==========================================================================
   M3 Inputs, Sliders, Segmented Buttons & Switch
   ========================================================================== */

.field-group {
  margin-bottom: 1.15rem;
}

.field-group--last {
  margin-bottom: 0;
}

.field-group__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.field-label {
  display: block;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 0.35rem;
}

.field-group__top .field-label {
  margin-bottom: 0;
}

.field-hint {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--md-sys-color-primary);
}

.field-helper {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.76rem;
  color: var(--md-sys-color-on-surface-variant);
}

.m3-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  height: 48px;
  padding: 0 0.9rem;
  border-radius: 12px;
  border: 1.5px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
  transition: border-color 160ms var(--md-sys-motion-emphasized), box-shadow 160ms;
}

.m3-field:focus-within {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--md-sys-color-primary) 18%, transparent);
}

.m3-field--mt {
  margin-top: 0.6rem;
}

.m3-field__affix {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  user-select: none;
}

.m3-field input {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  font-variant-numeric: tabular-nums;
}

.m3-field input:focus {
  outline: none;
}

/* Remove default number spinners for cleaner M3 look */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

/* M3 Slider */
.m3-slider {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  margin: 0.85rem 0 0.3rem;
  border-radius: var(--md-sys-shape-corner-full);
  background: linear-gradient(
    to right,
    var(--md-sys-color-primary) 0%,
    var(--md-sys-color-primary) var(--fill),
    var(--md-sys-color-surface-container-highest) var(--fill),
    var(--md-sys-color-surface-container-highest) 100%
  );
  cursor: pointer;
}

.m3-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
  border: 3px solid var(--md-sys-color-surface-container-low);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 150ms var(--md-sys-motion-emphasized), box-shadow 150ms;
}

.m3-slider::-webkit-slider-thumb:hover {
  transform: scale(1.12);
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--md-sys-color-primary) 16%, transparent);
}

.m3-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
  border: 3px solid var(--md-sys-color-surface-container-low);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 150ms var(--md-sys-motion-emphasized), box-shadow 150ms;
}

.slider-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--md-sys-color-on-surface-variant);
}

.field-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
}

.caption-tag {
  font-weight: 600;
  color: var(--md-sys-color-tertiary);
}

.caption-tag.is-warn {
  color: var(--md-sys-color-error);
}

/* M3 Segmented Button */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
  overflow: hidden;
  background: var(--md-sys-color-surface-container-lowest);
}

.segmented--compact {
  display: inline-grid;
}

.segmented__btn {
  height: 40px;
  padding: 0 0.95rem;
  border: none;
  border-right: 1px solid var(--md-sys-color-outline-variant);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 160ms var(--md-sys-motion-emphasized), color 160ms;
}

.segmented--compact .segmented__btn {
  height: 34px;
  padding: 0 0.85rem;
  font-size: 0.82rem;
}

.segmented__btn:last-child {
  border-right: none;
}

.segmented__btn:hover:not(.is-active) {
  background: var(--md-sys-color-surface-container);
}

.segmented__btn.is-active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-weight: 600;
}

/* M3 Accordion */
.m3-accordion__summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
}

.m3-accordion__summary::-webkit-details-marker {
  display: none;
}

.m3-accordion__chevron {
  color: var(--md-sys-color-on-surface-variant);
  transition: transform 200ms var(--md-sys-motion-emphasized);
  flex-shrink: 0;
}

.m3-accordion[open] .m3-accordion__chevron {
  transform: rotate(180deg);
}

.m3-accordion__body {
  margin-top: 1.15rem;
}

.two-col-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

@media (min-width: 480px) {
  .two-col-fields {
    grid-template-columns: 1fr 1fr;
  }
}

/* M3 Switch */
.m3-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface-container);
  cursor: pointer;
}

.m3-switch-row__title {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
}

.m3-switch-row__sub {
  display: block;
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.m3-switch {
  position: relative;
  width: 52px;
  height: 32px;
  flex-shrink: 0;
}

.m3-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.m3-switch__track {
  position: absolute;
  inset: 0;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  border: 2px solid var(--md-sys-color-outline);
  transition: background-color 180ms var(--md-sys-motion-emphasized), border-color 180ms;
}

.m3-switch__track::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--md-sys-color-outline);
  transform: translateY(-50%);
  transition: transform 180ms var(--md-sys-motion-emphasized), width 180ms, height 180ms, background-color 180ms;
}

.m3-switch input:checked + .m3-switch__track {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.m3-switch input:checked + .m3-switch__track::after {
  width: 22px;
  height: 22px;
  background: var(--md-sys-color-on-primary);
  transform: translate(20px, -50%);
}

/* M3 Pill Buttons */
.action-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filled-btn,
.tonal-btn,
.outlined-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  height: 40px;
  padding: 0 1.2rem;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: filter 160ms var(--md-sys-motion-emphasized), background-color 160ms, transform 120ms;
}

.filled-btn {
  border: none;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.tonal-btn {
  border: none;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.tonal-btn--compact {
  height: 34px;
  padding: 0 0.9rem;
  font-size: 0.8rem;
}

.outlined-btn {
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-primary);
}

.filled-btn:hover,
.tonal-btn:hover {
  filter: brightness(0.96);
}

.outlined-btn:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
}

.filled-btn:active,
.tonal-btn:active,
.outlined-btn:active {
  transform: scale(0.97);
}

/* ==========================================================================
   Hero Breakdown Card & Donut Chart
   ========================================================================== */

.hero-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: center;
}

@media (min-width: 680px) {
  .hero-grid {
    grid-template-columns: minmax(0, 1.25fr) 210px;
  }
}

.hero-eyebrow {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--md-sys-color-primary);
}

.hero-amount-row {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  margin: 0.2rem 0 0.35rem;
}

.hero-amount {
  font-size: clamp(2.25rem, 5vw, 3.1rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.08;
}

.hero-unit {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.hero-subline {
  margin: 0 0 1.15rem;
  font-size: 0.88rem;
  color: var(--md-sys-color-on-surface-variant);
}

.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.48rem 0.75rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--md-sys-color-surface-container-lowest) 75%, transparent);
  transition: background-color 150ms, transform 150ms;
  cursor: default;
}

.legend-item:hover,
.legend-item.is-highlighted {
  background: var(--md-sys-color-surface-container-lowest);
  transform: translateX(2px);
}

.legend-item__left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.86rem;
  font-weight: 500;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 4px;
  flex-shrink: 0;
}

.legend-item__right {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.legend-pct {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  min-width: 36px;
  text-align: right;
}

/* Donut SVG */
.donut-wrap {
  position: relative;
  width: 210px;
  height: 210px;
  margin: 0 auto;
}

.donut-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.donut-track {
  fill: none;
  stroke: var(--md-sys-color-surface-container-highest);
  stroke-width: 24;
}

.donut-seg {
  fill: none;
  stroke-width: 24;
  transition: stroke-dasharray 320ms var(--md-sys-motion-emphasized),
    stroke-dashoffset 320ms var(--md-sys-motion-emphasized),
    stroke-width 180ms;
  cursor: pointer;
}

.donut-seg:hover,
.donut-seg.is-highlighted {
  stroke-width: 28;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  padding: 1rem;
}

.donut-center__label {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.donut-center__value {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Extra Payment Savings Banner */
.savings-banner {
  margin-top: 1.25rem;
  padding: 0.9rem 1.05rem;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.savings-banner__icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--md-sys-color-on-tertiary-container) 12%, transparent);
  flex-shrink: 0;
}

.savings-banner__content {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.86rem;
}

.savings-banner__content strong {
  font-size: 0.96rem;
}

/* ==========================================================================
   KPI Summary Tiles
   ========================================================================== */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

@media (min-width: 760px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.kpi-card {
  background: var(--md-sys-color-surface-container);
  border-radius: 20px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.kpi-card__label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
}

.kpi-card__value {
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.kpi-card__sub {
  font-size: 0.74rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ==========================================================================
   Balance & Equity SVG Chart
   ========================================================================== */

.chart-legend {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--md-sys-color-on-surface-variant);
}

.chart-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.swatch-dot--balance { background: var(--chart-pi); }
.swatch-dot--principal { background: var(--chart-principal); }
.swatch-dot--interest { background: var(--chart-interest); }
.swatch-dot--baseline {
  background: transparent;
  border: 2px dashed var(--md-sys-color-outline);
}

.line-chart-wrap {
  position: relative;
  width: 100%;
  height: 255px;
}

.line-chart-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.chart-grid-line {
  stroke: var(--md-sys-color-outline-variant);
  stroke-opacity: 0.45;
  stroke-dasharray: 3 4;
}

.chart-axis-text {
  fill: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip {
  position: absolute;
  top: 10px;
  left: 10px;
  pointer-events: none;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  font-size: 0.78rem;
  line-height: 1.45;
  box-shadow: var(--elevation-3);
  min-width: 175px;
  z-index: 10;
}

.chart-tooltip__title {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.chart-tooltip__row {
  display: flex;
  justify-content: space-between;
  gap: 0.9rem;
}

/* ==========================================================================
   Amortization Schedule Table
   ========================================================================== */

.schedule-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.table-scroll {
  overflow-x: auto;
  max-height: 440px;
  border-radius: var(--md-sys-shape-corner-medium);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 55%, transparent);
}

.m3-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  min-width: 620px;
}

.m3-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 600;
  font-size: 0.78rem;
  text-align: left;
  padding: 0.72rem 0.85rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  white-space: nowrap;
}

.m3-table th.num,
.m3-table td.num {
  text-align: right;
  white-space: nowrap;
}

.m3-table tbody td {
  padding: 0.66rem 0.85rem;
  border-bottom: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 35%, transparent);
}

.m3-table tbody tr:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 6%, transparent);
}

.m3-table tbody tr:last-child td {
  border-bottom: none;
}

.split-bar {
  width: 84px;
  height: 8px;
  border-radius: var(--md-sys-shape-corner-full);
  background: color-mix(in srgb, var(--chart-interest) 45%, var(--md-sys-color-surface-container-highest));
  overflow: hidden;
}

.split-bar__fill {
  height: 100%;
  background: var(--chart-principal);
  border-radius: var(--md-sys-shape-corner-full);
}

.split-col {
  width: 104px;
}

/* ==========================================================================
   M3 Snackbar
   ========================================================================== */

.m3-snackbar {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 60;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--elevation-3);
  max-width: calc(100vw - 2rem);
}

@media (max-width: 599px) {
  .top-app-bar__inner {
    padding: 0.65rem 0.9rem;
  }

  .brand__subtitle {
    display: none;
  }

  .page-shell {
    padding: 0.9rem 0.85rem 3rem;
  }

  .m3-card,
  .m3-card--hero {
    padding: 1.15rem 1rem;
    border-radius: 20px;
  }

  .kpi-card__value {
    font-size: 1.08rem;
  }
}


/* ==========================================================================
   Unified OpenAppsAI Suite Chrome (Header & Footer)
   ========================================================================== */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-shell {
  width: 100%;
  flex: 1;
}

.oa-header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 12px 16px 0;
}

.oa-nav {
  max-width: 1260px;
  margin: 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(24px) saturate(190%);
  -webkit-backdrop-filter: blur(24px) saturate(190%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), 0 6px 22px rgba(32, 42, 88, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

html[data-theme="dark"] .oa-nav {
  background: rgba(20, 25, 40, 0.86);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 8px 26px rgba(0, 0, 0, 0.42);
}

.oa-brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.oa-prism-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border-radius: 12px;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.oa-prism-btn:hover { transform: scale(1.06); }

.oa-logo {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, #4F46E5 0%, #06B6D4 52%, #F43F5E 100%);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 7px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.34);
  flex-shrink: 0;
}

.oa-dot { background: #FFFFFF; display: block; }
.oa-dot.d1, .oa-dot.d4 { border-radius: 2.5px; }
.oa-dot.d2, .oa-dot.d3 { border-radius: 50%; opacity: 0.84; }

.oa-divider {
  width: 1px;
  height: 22px;
  background: rgba(98, 108, 152, 0.25);
  flex-shrink: 0;
}

html[data-theme="dark"] .oa-divider { background: rgba(255, 255, 255, 0.18); }

.oa-brand-text { display: flex; flex-direction: column; line-height: 1.08; }
.oa-brand-title { margin: 0; font-size: 1rem; font-weight: 800; letter-spacing: -0.025em; color: var(--md-sys-color-on-surface); }
.oa-brand-sub { font-size: 0.68rem; font-weight: 600; color: var(--md-sys-color-on-surface-variant); }

.oa-suite-pills {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.14);
}

html[data-theme="dark"] .oa-suite-pills {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}

.oa-pill {
  padding: 6px 13px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.81rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  transition: background-color 0.18s, color 0.18s;
}

.oa-pill:hover {
  background: rgba(79, 70, 229, 0.12);
  color: var(--md-sys-color-on-surface);
}

.oa-pill.is-active {
  background: linear-gradient(135deg, #434CE6, #00A699);
  color: #FFFFFF;
  box-shadow: 0 3px 10px rgba(67, 76, 230, 0.28);
}

.oa-footer {
  margin-top: auto;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-low);
}

.oa-footer-inner {
  max-width: 1260px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.84rem;
}

.oa-footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--md-sys-color-on-surface-variant);
}

.oa-footer-brand strong {
  color: var(--md-sys-color-on-surface);
  font-weight: 800;
}

.oa-footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.oa-footer-links a {
  text-decoration: none;
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 700;
  transition: color 0.18s;
}

.oa-footer-links a:hover { color: var(--md-sys-color-primary); }

@media (max-width: 1020px) {
  .oa-suite-pills { display: none; }
}

@media (max-width: 600px) {
  .oa-header { padding: 8px 10px 0; }
  .oa-nav { padding: 6px 10px; }
  .oa-brand-sub { display: none; }
  .oa-footer-inner { flex-direction: column; text-align: center; }
  .oa-footer-links { justify-content: center; gap: 12px; }
}
