body.legacy-tool-page {
  --accent-primary: var(--color-orange-500);
  --accent-soft: var(--color-orange-100);
  --emi-note-text: #5b2b0b;
  --border-strong: var(--color-border-strong);
  --border-subtle: var(--color-border);
  --focus-ring: var(--color-focus);
  --radius-md: var(--radius-medium);
  --radius-lg: var(--radius-large);
  --shadow-lg: var(--shadow-raised);
  --surface-elevated: var(--color-surface);
  --surface-soft: var(--color-surface-subtle);
  --text-body: var(--color-text-soft);
  --text-muted: var(--color-text-muted);
  --text-strong: var(--color-text);
}

.emi-original {
  color: var(--text-body);
  min-width: 0;
}

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

.emi-original__card {
  min-width: 0;
}

.loanproduct-nav {
  display: grid;
  gap: .55rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}

.loanproduct-nav button {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-body);
  cursor: pointer;
  display: flex;
  font: inherit;
  font-weight: 750;
  justify-content: center;
  min-height: 2.75rem;
  padding: .65rem .8rem;
  text-align: center;
  width: 100%;
}

.loanproduct-nav .active button,
.loanproduct-nav button:hover {
  background: var(--accent-soft);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.loanproduct-nav button:focus-visible,
.emi-original input:focus-visible,
.emi-original select:focus-visible,
.emi-original .btn:focus-visible,
.emi-original .ui-slider-handle:focus-visible,
#emipaymenttable .toggle:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

#emicalculatorform {
  display: grid;
  gap: 1.25rem;
}

.emi-field {
  display: grid;
  gap: .55rem;
}

.emi-field > label,
.emi-field > legend {
  color: var(--text-strong);
  font-size: .9rem;
  font-weight: 750;
}

.emi-fieldset {
  border: 0;
  margin: 0;
  min-width: 0;
  padding: 0;
}

.input-group {
  align-items: stretch;
  display: flex;
  min-width: 0;
}

.emi-original input[type="text"],
.emi-original input[type="number"],
.emi-original select {
  appearance: none;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong, var(--border-subtle));
  border-radius: var(--radius-md);
  color: var(--text-strong);
  font: inherit;
  min-height: 2.9rem;
  min-width: 0;
  padding: .7rem .85rem;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
  width: 100%;
}

.emi-original input:hover,
.emi-original select:hover {
  border-color: var(--accent-primary);
}

.input-group .form-control {
  border-bottom-right-radius: 0;
  border-top-right-radius: 0;
}

.input-group-text {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border-strong, var(--border-subtle));
  border-left: 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-muted);
  display: flex;
  font-weight: 800;
  min-width: 3rem;
  padding: .7rem .85rem;
}

.emi-choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
}

.emi-choice-group .btn {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-body);
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  gap: .45rem;
  min-height: 2.65rem;
  padding: .55rem .9rem;
}

.emi-choice-group .btn.active,
.emi-choice-group .btn:has(input:checked) {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}

.emi-choice-group input {
  accent-color: currentColor;
  height: 1rem;
  margin: 0;
  width: 1rem;
}

.toggle-hidden,
[hidden] {
  display: none !important;
}

.toggle-visible {
  display: grid;
}

.emi-slider {
  padding: .1rem .35rem 0;
}

.ui-slider {
  background: var(--surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  height: .6rem;
  margin: .5rem 0 .2rem;
  position: relative;
}

.ui-slider-range {
  background: var(--accent-primary);
  border-radius: inherit;
  height: 100%;
  position: absolute;
}

.ui-slider-handle {
  background: var(--surface-elevated);
  border: 3px solid var(--accent-primary);
  border-radius: 50%;
  cursor: grab;
  height: 1.25rem;
  margin-left: -.625rem;
  position: absolute;
  top: -.4rem;
  touch-action: none;
  width: 1.25rem;
}

.ui-slider-handle:active {
  cursor: grabbing;
}

.steps {
  color: var(--text-muted);
  font-size: .68rem;
  height: 2.25rem;
  margin: 0 .35rem;
  position: relative;
}

.steps .tick {
  position: absolute;
  text-align: center;
  transform: translateX(-50%);
  white-space: nowrap;
}

.steps .marker {
  display: inline-block;
  margin-top: .15rem;
}

.emi-form-actions,
.emi-export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.emi-status {
  color: var(--text-muted);
  margin: .15rem 0 0;
  min-height: 1.5rem;
}

.emi-status[data-state="success"] { color: var(--color-success, #34d399); }
.emi-status[data-state="error"] { color: var(--color-danger, #f87171); }

.emi-results {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, .85fr) minmax(18rem, 1.15fr);
  margin-top: 1.75rem;
}

#emipaymentsummary {
  display: grid;
  gap: .75rem;
}

#emipaymentsummary > div {
  background: var(--surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1rem;
}

#emipaymentsummary h3 {
  color: var(--text-muted);
  font-size: .78rem;
  letter-spacing: .035em;
  margin: 0 0 .35rem;
  text-transform: uppercase;
}

#emipaymentsummary p {
  color: var(--accent-primary);
  font-size: clamp(1.3rem, 2.5vw, 2rem);
  font-weight: 850;
  margin: 0;
}

#emipiechart,
#emibarchart {
  min-height: 21rem;
  min-width: 0;
  width: 100%;
}

.emi-schedule-section {
  border-top: 1px solid var(--border-subtle);
  margin-top: 2rem;
  padding-top: 1.5rem;
}

.emi-schedule-controls {
  align-items: end;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(13rem, 1fr) minmax(12rem, .7fr);
  margin-bottom: 1rem;
}

.emi-schedule-scroll {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  contain: paint;
  height: min(16rem, calc(100vh - 12rem));
  isolation: isolate;
  margin-top: 1rem;
  max-height: min(16rem, calc(100vh - 12rem));
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  position: relative;
  scrollbar-gutter: stable;
}

#emipaymenttable {
  min-width: 58rem;
}

#emipaymenttable table {
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
}

#emipaymenttable th,
#emipaymenttable td {
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-body);
  padding: .7rem .65rem;
  text-align: right;
  vertical-align: middle;
  width: 16.666%;
}

#emipaymenttable th {
  background: var(--surface-soft);
  color: var(--text-strong);
  font-size: .73rem;
  letter-spacing: .025em;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 4;
}

#emipaymenttable th:first-child,
#emipaymenttable td:first-child {
  text-align: left;
}

/* The original generator emits compact duplicate Principal/Interest headings
   for its former Bootstrap mobile view. V1 keeps the full six-column table in
   the horizontal scroller, so only the full headings are needed. */
#emipaymenttable th.d-sm-none {
  display: none;
}

#emipaymenttable .monthlypaymentdetails > td {
  padding: 0;
}

#emipaymenttable .monthlypaymentcontainer {
  background: var(--surface-soft);
  overflow: hidden;
}

#emipaymenttable .monthlypaymentcontainer td {
  background: var(--surface-soft);
  font-size: .83rem;
}

#emipaymenttable .toggle {
  color: var(--accent-primary);
  cursor: pointer;
  font-weight: 800;
}

#emipaymenttable .toggle::before {
  content: "+";
  display: inline-block;
  margin-right: .4rem;
}

#emipaymenttable .toggle-open::before {
  content: "−";
}

.loadmask {
  background: var(--surface-elevated);
  inset: 0;
  opacity: .72;
  position: absolute;
  z-index: 20;
}

.loadmask-msg {
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  color: var(--text-strong);
  left: 50% !important;
  padding: .75rem 1rem;
  position: absolute;
  top: 50% !important;
  transform: translate(-50%, -50%);
  z-index: 21;
}

.datepicker {
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  color: var(--text-body);
  padding: .65rem;
  position: absolute;
  z-index: 1000;
}

.datepicker table { border-collapse: collapse; }
.datepicker td,
.datepicker th { cursor: pointer; padding: .4rem .55rem; text-align: center; }
.datepicker .active { background: var(--accent-primary); color: #fff; }

html[data-theme="dark"] .emi-original .highcharts-container text {
  fill: var(--text-body) !important;
}

/* Highcharts renders these elements on pale surfaces, so they need a dark
   foreground even while the surrounding EMI page uses the dark theme. */
html[data-theme="dark"] .emi-original .highcharts-legend-item text,
html[data-theme="dark"] .emi-original .highcharts-tooltip text {
  fill: #17233a !important;
}

html[data-theme="dark"] .emi-original .highcharts-tooltip-box {
  fill: #fffaf5 !important;
  fill-opacity: .98 !important;
  stroke: var(--accent-primary) !important;
}

body.legacy-tool-page .legacy-tool-note {
  color: var(--emi-note-text);
}

@media (max-width: 760px) {
  .loanproduct-nav,
  .emi-results,
  .emi-schedule-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  .loanproduct-nav {
    display: flex;
    flex-wrap: wrap;
  }

  .loanproduct-nav li {
    flex: 1 1 8rem;
  }

  #emipiechart,
  #emibarchart {
    min-height: 18rem;
  }

  .emi-schedule-scroll {
    max-height: 16rem;
  }
}

@media (max-width: 480px) {
  .emi-form-actions .button,
  .emi-export-actions .button {
    flex: 1 1 100%;
    justify-content: center;
  }

  .steps {
    display: none;
  }
}
