/*
 * First Digital theme layer over stock Bootstrap 5.3.
 * Palette from docs/FirstDigital-Brand-Guide-2025.pdf (p. 11):
 *   navy #003366, mid blue #307ab2, bright blue #38b2e3, red #cf333d (accents,
 *   use selectively), slate #2e404d (paragraph text), greys #8f9499 / #dedede / #f0f0f0.
 *
 * Everything here works by re-pointing Bootstrap's own CSS variables, so pages
 * keep using plain Bootstrap classes (btn-primary, text-danger, badge bg-success...)
 * and pick up the brand look automatically. Avoid hardcoded colors in templates.
 */

:root {
  --fd-navy: #003366;
  --fd-blue: #307ab2;
  --fd-blue-rgb: 48, 122, 178;
  --fd-blue-hover: #28689a;
  --fd-blue-active: #225a86;
  --fd-bright: #38b2e3;
  --fd-bright-rgb: 56, 178, 227;
  --fd-red: #cf333d;

  --bs-body-font-family: "Host Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- Light mode ----------
 * Same specificity as the dark block below, which therefore must stay AFTER this one:
 * <html> matches both :root and [data-bs-theme="dark"], so source order decides. */
:root,
[data-bs-theme="light"] {
  --fd-page-bg: #eef2f6;            /* canvas; cards and inputs stay white on top of it */
  --fd-btn-border: #b9c4ce;
  --fd-table-head-bg: #f4f7fa;
  --fd-chart-base: #307ab2;         /* chart series; pair validated for CVD/contrast on white */
  --fd-chart-upside: #c96a1b;
  --fd-chart-down: #cf333d;         /* "takes cash" in the math waterfall; validated vs. --fd-chart-base */
  --fd-shadow-sm: 0 1px 2px rgba(16, 32, 48, 0.06), 0 1px 3px rgba(16, 32, 48, 0.08);
  --fd-shadow-md: 0 2px 4px rgba(16, 32, 48, 0.06), 0 6px 16px rgba(16, 32, 48, 0.08);

  --bs-body-color: #2e404d;
  --bs-body-color-rgb: 46, 64, 77;
  --bs-heading-color: var(--fd-navy);
  --bs-secondary-color: rgba(46, 64, 77, 0.72);
  --bs-border-color: #dbe2e9;
  --bs-border-color-translucent: rgba(0, 51, 102, 0.1);
  --bs-tertiary-bg: #f5f7fa;

  --bs-primary: #307ab2;
  --bs-primary-rgb: 48, 122, 178;
  --bs-primary-bg-subtle: #e2eef8;
  --bs-primary-border-subtle: #b9d4ea;
  --bs-primary-text-emphasis: #1d4f78;

  --bs-danger: #cf333d;
  --bs-danger-rgb: 207, 51, 61;
  --bs-danger-bg-subtle: #fae3e4;
  --bs-danger-border-subtle: #f0b8bc;
  --bs-danger-text-emphasis: #8f1f27;

  --bs-success: #2e8b47;
  --bs-success-rgb: 46, 139, 71;
  --bs-success-bg-subtle: #e0f1e5;
  --bs-success-border-subtle: #b3dbbe;
  --bs-success-text-emphasis: #1d5c2e;

  --bs-secondary-bg-subtle: #e9edf1;
  --bs-secondary-border-subtle: #d0d8df;
  --bs-secondary-text-emphasis: #3d4a55;

  --bs-warning-bg-subtle: #fff2cc;
  --bs-warning-border-subtle: #ffe08a;
  --bs-warning-text-emphasis: #6b4e00;

  --bs-link-color: #2a6ea3;
  --bs-link-color-rgb: 42, 110, 163;
  --bs-link-hover-color: #1d4f78;
  --bs-link-hover-color-rgb: 29, 79, 120;
  --bs-focus-ring-color: rgba(var(--fd-bright-rgb), 0.35);
}

/* ---------- Dark mode: navy-black instead of Bootstrap's neutral grey ---------- */
[data-bs-theme="dark"] {
  --fd-page-bg: #0a1621;
  --fd-btn-border: rgba(255, 255, 255, 0.26);
  --fd-table-head-bg: #15283b;
  --fd-chart-base: #3d88c4;         /* re-stepped (not flipped) for the #112234 card surface */
  --fd-chart-upside: #d0731f;
  --fd-chart-down: #e0545c;
  --fd-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);
  --fd-shadow-md: 0 2px 4px rgba(0, 0, 0, 0.35), 0 8px 20px rgba(0, 0, 0, 0.35);

  --bs-body-bg: #112234;            /* surfaces: cards, inputs, dropdowns, modals */
  --bs-body-bg-rgb: 17, 34, 52;
  --bs-body-color: #dbe3ea;
  --bs-body-color-rgb: 219, 227, 234;
  --bs-heading-color: #eef3f8;
  --bs-secondary-color: rgba(219, 227, 234, 0.68);
  --bs-secondary-bg: #1a2e43;
  --bs-tertiary-bg: #15283b;
  --bs-border-color: #24384c;
  --bs-border-color-translucent: rgba(255, 255, 255, 0.1);

  --bs-primary: #3f8fcc;
  --bs-primary-rgb: 63, 143, 204;
  --bs-primary-bg-subtle: rgba(56, 178, 227, 0.14);
  --bs-primary-border-subtle: rgba(56, 178, 227, 0.35);
  --bs-primary-text-emphasis: #8fd3f0;

  --bs-danger: #e5545d;              /* brand red lifted for contrast on dark surfaces */
  --bs-danger-rgb: 229, 84, 93;
  --bs-danger-bg-subtle: rgba(229, 84, 93, 0.16);
  --bs-danger-border-subtle: rgba(229, 84, 93, 0.4);
  --bs-danger-text-emphasis: #f39aa0;

  --bs-success: #3fae5f;
  --bs-success-rgb: 63, 174, 95;
  --bs-success-bg-subtle: rgba(63, 174, 95, 0.16);
  --bs-success-border-subtle: rgba(63, 174, 95, 0.4);
  --bs-success-text-emphasis: #8fdca5;

  --bs-secondary-bg-subtle: rgba(255, 255, 255, 0.07);
  --bs-secondary-border-subtle: rgba(255, 255, 255, 0.16);
  --bs-secondary-text-emphasis: #c3cdd6;

  --bs-warning-bg-subtle: rgba(255, 193, 7, 0.14);
  --bs-warning-border-subtle: rgba(255, 193, 7, 0.35);
  --bs-warning-text-emphasis: #ffd76a;

  --bs-link-color: #6cc4ec;
  --bs-link-color-rgb: 108, 196, 236;
  --bs-link-hover-color: #9ad6f2;
  --bs-link-hover-color-rgb: 154, 214, 242;
}

body {
  background-color: var(--fd-page-bg);
}

/* ---------- Top bar ---------- */
.navbar-fd {
  background: linear-gradient(100deg, #003366 0%, #00335f 45%, #1b5a92 100%);
  border-bottom: 3px solid var(--fd-bright);
  box-shadow: var(--fd-shadow-sm);
}
.navbar-fd .navbar-brand img { height: 24px; width: auto; }

/* ---------- Buttons ---------- */
.btn { --bs-btn-font-weight: 500; }

.btn-primary {
  --bs-btn-bg: var(--fd-blue);
  --bs-btn-border-color: var(--fd-blue);
  --bs-btn-hover-bg: var(--fd-blue-hover);
  --bs-btn-hover-border-color: var(--fd-blue-hover);
  --bs-btn-active-bg: var(--fd-blue-active);
  --bs-btn-active-border-color: var(--fd-blue-active);
  --bs-btn-disabled-bg: var(--fd-blue);
  --bs-btn-disabled-border-color: var(--fd-blue);
  --bs-btn-focus-shadow-rgb: var(--fd-bright-rgb);
}

.btn-outline-primary {
  --bs-btn-color: var(--fd-blue);
  --bs-btn-border-color: var(--fd-blue);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--fd-blue);
  --bs-btn-hover-border-color: var(--fd-blue);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--fd-blue-hover);
  --bs-btn-active-border-color: var(--fd-blue-hover);
  --bs-btn-focus-shadow-rgb: var(--fd-bright-rgb);
}
[data-bs-theme="dark"] .btn-outline-primary {
  --bs-btn-color: #6cc4ec;
  --bs-btn-border-color: #3f8fcc;
}

.btn-danger,
.btn-outline-danger {
  --bs-btn-focus-shadow-rgb: var(--bs-danger-rgb);
}
.btn-danger {
  --bs-btn-bg: var(--bs-danger);
  --bs-btn-border-color: var(--bs-danger);
  --bs-btn-hover-bg: #b52a33;
  --bs-btn-hover-border-color: #b52a33;
}
.btn-outline-danger {
  --bs-btn-color: var(--bs-danger);
  --bs-btn-border-color: var(--bs-danger-border-subtle);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--bs-danger);
  --bs-btn-hover-border-color: var(--bs-danger);
  --bs-btn-active-bg: var(--bs-danger);
  --bs-btn-active-border-color: var(--bs-danger);
}

/* Stock outline-secondary is a mid grey that reads as disabled on the navy-black dark
   surface. Body-colored text on a visible border keeps secondary actions clearly live. */
.btn-outline-secondary {
  --bs-btn-color: var(--bs-body-color);
  --bs-btn-border-color: var(--fd-btn-border);
  --bs-btn-hover-color: var(--bs-body-color);
  --bs-btn-hover-bg: var(--bs-secondary-bg-subtle);
  --bs-btn-hover-border-color: var(--bs-secondary-color);
  --bs-btn-active-color: var(--bs-body-color);
  --bs-btn-active-bg: var(--bs-secondary-bg-subtle);
  --bs-btn-active-border-color: var(--bs-secondary-color);
  --bs-btn-disabled-color: var(--bs-secondary-color);
  --bs-btn-disabled-border-color: var(--fd-btn-border);
  --bs-btn-focus-shadow-rgb: var(--fd-bright-rgb);
}

/* "Add a row" buttons: a dashed, full-width drop zone under the table it adds to. */
.btn-add {
  --bs-btn-color: var(--bs-link-color);
  --bs-btn-border-color: var(--bs-primary-border-subtle);
  --bs-btn-hover-color: var(--bs-link-hover-color);
  --bs-btn-hover-bg: var(--bs-primary-bg-subtle);
  --bs-btn-hover-border-color: var(--bs-primary);
  --bs-btn-active-color: var(--bs-link-hover-color);
  --bs-btn-active-bg: var(--bs-primary-bg-subtle);
  --bs-btn-active-border-color: var(--bs-primary);
  --bs-btn-focus-shadow-rgb: var(--fd-bright-rgb);
  border-style: dashed;
}
/* The form JS matches clicks on event.target's class, so the icon must not be the target. */
.btn-add > * { pointer-events: none; }

/* Navbar links: quiet ghost buttons, so the one filled "+ New CAT" is the call to action. */
.btn-nav {
  --bs-btn-color: rgba(255, 255, 255, 0.82);
  --bs-btn-border-color: transparent;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: rgba(255, 255, 255, 0.12);
  --bs-btn-hover-border-color: transparent;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: rgba(255, 255, 255, 0.18);
  --bs-btn-active-border-color: transparent;
  --bs-btn-focus-shadow-rgb: 255, 255, 255;
}
.btn-nav.active {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 -2px 0 var(--fd-bright);
}
.navbar-fd .dropdown-header { font-size: 0.75rem; }

/* Bright-blue call to action on the navy bar ("+ New CAT"). Navy text keeps it AA. */
.btn-accent {
  --bs-btn-color: var(--fd-navy);
  --bs-btn-bg: var(--fd-bright);
  --bs-btn-border-color: var(--fd-bright);
  --bs-btn-hover-color: var(--fd-navy);
  --bs-btn-hover-bg: #5cc2ea;
  --bs-btn-hover-border-color: #5cc2ea;
  --bs-btn-active-color: var(--fd-navy);
  --bs-btn-active-bg: #2a9fcf;
  --bs-btn-active-border-color: #2a9fcf;
  --bs-btn-focus-shadow-rgb: 255, 255, 255;
  --bs-btn-font-weight: 600;
}

/* ---------- Forms ---------- */
.form-control:focus,
.form-select:focus {
  border-color: var(--fd-bright);
  box-shadow: 0 0 0 0.25rem rgba(var(--fd-bright-rgb), 0.25);
}
.form-check-input:checked {
  background-color: var(--fd-blue);
  border-color: var(--fd-blue);
}
.form-check-input:focus {
  border-color: var(--fd-bright);
  box-shadow: 0 0 0 0.25rem rgba(var(--fd-bright-rgb), 0.25);
}
.dropdown-menu {
  --bs-dropdown-link-active-bg: var(--fd-blue);
  --bs-dropdown-border-color: var(--bs-border-color);
  box-shadow: var(--fd-shadow-md);
}

/* ---------- Cards: white surfaces lifted off the tinted page ---------- */
.card {
  --bs-card-border-color: var(--bs-border-color-translucent);
  --bs-card-border-radius: 0.75rem;
  --bs-card-inner-border-radius: calc(0.75rem - 1px);
  box-shadow: var(--fd-shadow-sm);
}
.modal-content { box-shadow: var(--fd-shadow-md); }
/*
 * Layout rule: page titles, section labels and card borders sit on the page's outer
 * edge; ALL content sits on the card's inner edge (--bs-card-spacer-x). Section
 * titles go in a .card-header, never as bare text on the page background.
 */
.card-header {
  --bs-card-cap-bg: transparent;
  --bs-card-cap-padding-y: 0.75rem;
}
.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

/* A table placed straight in a card (no .card-body): clip its tinted header to the
   card's rounded corners, and pad its outer columns to the card's inner edge so the
   text lines up with .card-header / .card-body content above and below it.
   (Not overflow:hidden on .card itself -- that would clip the City combobox.) */
.card > .table-responsive {
  border-radius: var(--bs-card-inner-border-radius);
}
.card > .table-responsive > .table {
  margin-bottom: 0;
}
.card > .table-responsive > .table > :not(caption) > * > :first-child {
  padding-left: var(--bs-card-spacer-x);
}
.card > .table-responsive > .table > :not(caption) > * > :last-child {
  padding-right: var(--bs-card-spacer-x);
}
.card > .table-responsive > .table > tbody > tr:last-child > * {
  border-bottom-width: 0;
}

/* ---------- Badges: soft tinted pills instead of solid blocks ---------- */
.badge {
  --bs-badge-font-weight: 600;
  --bs-badge-padding-x: 0.65em;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.badge.bg-success   { background-color: var(--bs-success-bg-subtle) !important;   color: var(--bs-success-text-emphasis) !important;   box-shadow: inset 0 0 0 1px var(--bs-success-border-subtle); }
.badge.bg-danger    { background-color: var(--bs-danger-bg-subtle) !important;    color: var(--bs-danger-text-emphasis) !important;    box-shadow: inset 0 0 0 1px var(--bs-danger-border-subtle); }
.badge.bg-secondary { background-color: var(--bs-secondary-bg-subtle) !important; color: var(--bs-secondary-text-emphasis) !important; box-shadow: inset 0 0 0 1px var(--bs-secondary-border-subtle); }
.badge.bg-warning   { background-color: var(--bs-warning-bg-subtle) !important;   color: var(--bs-warning-text-emphasis) !important;   box-shadow: inset 0 0 0 1px var(--bs-warning-border-subtle); }
.badge.bg-primary   { background-color: var(--bs-primary-bg-subtle) !important;   color: var(--bs-primary-text-emphasis) !important;   box-shadow: inset 0 0 0 1px var(--bs-primary-border-subtle); }

/* ---------- Tables ---------- */
.table {
  --bs-table-bg: transparent;       /* sit on whatever surface holds them: page or card */
  --bs-table-border-color: var(--bs-border-color);
}
.table > thead > tr > th {
  --bs-table-bg: var(--fd-table-head-bg);
  --bs-table-color: var(--bs-secondary-color);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: bottom;
}
.table > tbody > tr:hover > * {
  --bs-table-bg-state: rgba(var(--fd-blue-rgb), 0.06);
}
.table td,
.fs-4 {
  font-variant-numeric: tabular-nums;
}

/* ---------- KPI cards (CAT detail page) ---------- */
.kpi-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.4rem;                 /* two-line labels ("Cash Flow Margin") keep gauges aligned */
  margin-bottom: 0.35rem;
}
.kpi-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 0.5rem;
  background-color: var(--bs-primary-bg-subtle);
  color: var(--fd-navy);              /* brand guide: dark-blue icons... */
  font-size: 1rem;
  flex-shrink: 0;
}
[data-bs-theme="dark"] .kpi-icon { color: var(--fd-bright); }  /* ...bright blue for emphasis */
.kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
}
.kpi-value {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--bs-heading-color);
}
.kpi-foot {
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
}

/* Value-vs-target bar: fill grows in on load; the tick marks the target. */
.kpi-gauge {
  position: relative;
  height: 0.5rem;
  margin: 0.55rem 0 0.4rem;
  border-radius: 999px;
  background-color: var(--bs-secondary-bg-subtle);
}
.kpi-gauge-fill {
  height: 100%;
  width: var(--fill);
  border-radius: inherit;
  animation: kpi-gauge-grow 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.kpi-gauge-fill.is-ok      { background: linear-gradient(90deg, #2e8b47, #3fae5f); }
.kpi-gauge-fill.is-low     { background: linear-gradient(90deg, #a82830, var(--bs-danger)); }
.kpi-gauge-fill.is-neutral { background: linear-gradient(90deg, var(--fd-blue), var(--fd-bright)); }
.kpi-gauge-target {
  position: absolute;
  top: -0.25rem;
  bottom: -0.25rem;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background-color: var(--bs-heading-color);
}
@keyframes kpi-gauge-grow {
  from { width: 0; }
}

/* Before there's anything to compute (QuickCalc's empty state): the same cards, greyed. */
.kpi-card.is-placeholder .kpi-value { color: var(--bs-tertiary-color); }
.kpi-card.is-placeholder .kpi-icon { background-color: var(--bs-secondary-bg-subtle); color: var(--bs-secondary-color); }

/* ---------- "What it takes" lever cards (detail page) ---------- */
.lever-card {
  height: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.6rem;
  background-color: var(--bs-tertiary-bg);
}
.lever-value {
  margin-top: 0.15rem;
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--bs-heading-color);
}
.lever-value small { font-size: 0.8rem; font-weight: 500; color: var(--bs-secondary-color); }
.lever-change { font-size: 0.875rem; font-weight: 600; color: var(--bs-primary-text-emphasis); }
.lever-card.is-unreachable .lever-value { color: var(--bs-secondary-color); }
.lever-card.is-unreachable .lever-change { color: var(--bs-secondary-color); font-weight: 400; }
.lever-now { margin-top: 0.35rem; font-size: 0.8rem; color: var(--bs-secondary-color); font-variant-numeric: tabular-nums; }

/* ---------- Deal facts (detail page): label-over-value tiles in a grid ---------- */
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr));
  gap: 1rem 1.5rem;
  margin: 0;
}
.facts dt {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
  margin-bottom: 0.15rem;
}
.facts dd { margin: 0; }
.subhead {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
  margin-bottom: 0.4rem;
}

/* ---------- Money in tables and inputs ---------- */
.table > thead > tr > th.money-col { text-align: right; }
.money-input { text-align: right; font-variant-numeric: tabular-nums; }
/* "$" drawn inside the cell, over the input's left padding: no extra width per column. */
.money-cell { position: relative; }
.money-cell::before {
  content: "$";
  position: absolute;
  z-index: 1;
  left: 0.8rem;
  top: calc(0.25rem + 1.2rem);
  transform: translateY(-50%);
  color: var(--bs-secondary-color);
  pointer-events: none;
}
.money-cell > .money-input { padding-left: 1.5rem; }
.money-cell:has(> .form-control-sm)::before { left: 0.6rem; top: calc(0.25rem + 0.97rem); font-size: 0.875rem; }
.money-cell > .form-control-sm.money-input { padding-left: 1.3rem; }

/* ---------- CAT form product-line table ---------- */
/* Category and Product stay pinned while the money columns scroll under them, so a wide
   deal (several rate changes) never loses track of which line a number belongs to. */
.lines-table > :not(caption) > tr > :nth-child(1),
.lines-table > :not(caption) > tr > :nth-child(2) {
  position: sticky;
  z-index: 2;
  background-color: var(--bs-body-bg);
}
.lines-table > :not(caption) > tr > :nth-child(1) { left: 0; width: 7.5rem; min-width: 7.5rem; max-width: 7.5rem; }
.lines-table > :not(caption) > tr > :nth-child(2) {
  left: 7.5rem;
  width: 10rem;
  min-width: 10rem;
  max-width: 10rem;
  box-shadow: inset -1px 0 0 var(--bs-border-color);
}
.lines-table > thead > tr > :nth-child(1),
.lines-table > thead > tr > :nth-child(2) { background-color: var(--fd-table-head-bg); }
.lines-table > tbody > tr > td { vertical-align: top; }
.lines-table .money-col,
.lines-table .money-cell { min-width: 6.5rem; }
.lines-table > :not(caption) > * > * { padding-left: 0.15rem; padding-right: 0.15rem; }
.lines-table > :not(caption) > * > :first-child { padding-left: 0; }
.lines-table .product-toggle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lines-table > tbody > tr:last-child > * { border-bottom-width: 0; }

/* ---------- CAT form live preview bar ---------- */
.irr-preview {
  border-top: 3px solid var(--bs-border-color);
  box-shadow: 0 -4px 16px rgba(16, 32, 48, 0.1);
  transition: border-color 0.2s ease;
}
.irr-preview.is-ok  { border-top-color: var(--bs-success); background-image: linear-gradient(rgba(var(--bs-success-rgb), 0.07), rgba(var(--bs-success-rgb), 0.07)); }
.irr-preview.is-low { border-top-color: var(--bs-danger);  background-image: linear-gradient(rgba(var(--bs-danger-rgb), 0.07), rgba(var(--bs-danger-rgb), 0.07)); }
.irr-preview-badge { font-size: 0.85rem; padding: 0.45em 0.9em; }

/* ---------- QuickCalc ---------- */
.qc-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
  margin-bottom: 0.35rem;
}
.qc-inputs .form-label { font-size: 0.85rem; margin-bottom: 0.2rem; }
@media (min-width: 992px) {
  .qc-inputs { position: sticky; top: 1rem; }  /* inputs stay in reach while reading results */
}
/* After the first live update, gauges slide from the old value instead of regrowing from 0. */
.qc-results.is-live .kpi-gauge-fill {
  animation: none;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
/* Delayed so a fast response never flickers; only a slow one visibly dims. */
.qc-results { transition: opacity 0.15s ease; }
.qc-results[aria-busy="true"] { opacity: 0.6; transition-delay: 0.2s; }
.qc-current-term > * { --bs-table-bg-state: rgba(var(--fd-blue-rgb), 0.08); }

/* ---------- Motion ---------- */
.btn,
.badge,
.form-control,
.form-select {
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Live preview bar: a brief bright-blue glow when a number changes. */
.value-flash {
  border-radius: 0.25rem;
  animation: value-flash 0.9s ease-out;
}
@keyframes value-flash {
  from { background-color: rgba(var(--fd-bright-rgb), 0.35); }
  to   { background-color: transparent; }
}

/* "With upside" chart (detail page). Text stays in ink tokens; only marks carry series color. */
.upside-chart { position: relative; }
.upside-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.upside-chart .grid line { stroke: var(--bs-border-color); stroke-width: 1; }
.upside-chart .zero-line { stroke: var(--bs-secondary-color); stroke-width: 1; }
.upside-chart .axis-label { fill: var(--bs-secondary-color); font-size: 11px; }
.upside-chart .end-label { fill: var(--bs-body-color); font-size: 11px; font-weight: 600; }
.upside-chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.upside-chart .series-base { stroke: var(--fd-chart-base); }
.upside-chart .series-upside { stroke: var(--fd-chart-upside); }
.upside-chart .install-mark { fill: var(--fd-chart-upside); stroke: var(--bs-body-bg); stroke-width: 2; }
.upside-chart .crosshair { stroke: var(--bs-secondary-color); stroke-width: 1; stroke-dasharray: 3 3; }
.upside-chart .hover-dot { stroke: var(--bs-body-bg); stroke-width: 2; }
.upside-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 0.375rem;
  box-shadow: var(--fd-shadow-md);
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
  white-space: nowrap;
}
.legend-swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 0.35rem; }

/* ---------- Cash flow schedule (CAT detail modal) ---------- */
#cashFlowModal .modal-dialog { max-width: min(96vw, 1600px); }
.schedule-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.schedule-chart .grid line { stroke: var(--bs-border-color); stroke-width: 1; }
.schedule-chart .zero-line { stroke: var(--bs-secondary-color); stroke-width: 1; }
.schedule-chart .axis-label { fill: var(--bs-secondary-color); font-size: 11px; }
.schedule-chart .area { fill: var(--fd-chart-base); opacity: 0.12; }
.schedule-chart .series { fill: none; stroke: var(--fd-chart-base); stroke-width: 2; stroke-linejoin: round; }
.schedule-chart .point { fill: var(--fd-chart-base); stroke: var(--bs-body-bg); stroke-width: 2; }
.schedule-chart .payback-line { stroke: var(--bs-success); stroke-width: 1; stroke-dasharray: 3 3; }
.schedule-chart .payback-dot { fill: var(--bs-success); stroke: var(--bs-body-bg); stroke-width: 2; }
.schedule-chart .payback-label { fill: var(--bs-success-text-emphasis); font-size: 12px; font-weight: 600; }

/* One scroller for both axes, so the header can stick to its top while the Period and
 * Cumulative columns stick to its sides (sticky only works against the nearest scroller). */
.schedule-scroll {
  overflow: auto;
  max-height: 60vh;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
}
.schedule-table { margin-bottom: 0; font-size: 0.85rem; border-collapse: separate; border-spacing: 0; }
.schedule-table th,
.schedule-table td { white-space: nowrap; padding: 0.45rem 0.65rem; }
.schedule-table thead th { position: sticky; top: 0; z-index: 2; }
.schedule-table thead .schedule-groups th { height: 2rem; vertical-align: middle; }
.schedule-table thead tr + tr th { top: 2rem; }
.schedule-table .sticky-start,
.schedule-table .sticky-end { position: sticky; z-index: 1; --bs-table-bg: var(--bs-body-bg); }
.schedule-table .sticky-start { left: 0; border-right: 1px solid var(--bs-border-color); text-align: left; }
.schedule-table .sticky-end { right: 0; border-left: 1px solid var(--bs-border-color); }
.schedule-table thead .sticky-start,
.schedule-table thead .sticky-end { z-index: 3; --bs-table-bg: var(--fd-table-head-bg); }
.schedule-table .group-end { border-right: 1px solid var(--bs-border-color); }

.schedule-year { cursor: pointer; }
.schedule-year > * { font-weight: 600; border-top: 1px solid var(--bs-border-color); }
.schedule-month > th { padding-left: 2.4rem; font-weight: 400; }
.schedule-month > td { color: var(--bs-secondary-color); }
.schedule-sub { margin-left: 0.4rem; font-size: 0.75rem; font-weight: 400; color: var(--bs-secondary-color); }
.schedule-toggle {
  display: inline-block;
  width: 1.25rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--bs-secondary-color);
}
.schedule-toggle i { display: inline-block; transition: transform 0.15s ease; }
.schedule-toggle[aria-expanded="true"] i { transform: rotate(90deg); }
.schedule-event { color: var(--fd-blue); font-size: 0.75rem; cursor: help; }
[data-bs-theme="dark"] .schedule-event { color: var(--fd-bright); }

/* Payback: a soft green tint plus a green edge on the Period cell -- readable in both
 * themes, unlike Bootstrap's solid table-warning yellow. */
.schedule-payback > * { --bs-table-bg-state: rgba(var(--bs-success-rgb), 0.12); }
.schedule-payback > .sticky-start { box-shadow: inset 3px 0 0 var(--bs-success), inset 0 0 0 9999px rgba(var(--bs-success-rgb), 0.12); }
.schedule-month.schedule-payback > td { color: var(--bs-body-color); }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* "Show the math" page (cats/math.html). */
.math-path { display: flex; flex-wrap: wrap; gap: 0.5rem; list-style: none; padding: 0; counter-reset: none; }
.math-path li { display: flex; align-items: center; gap: 0.5rem; }
.math-path li + li::before { content: "\F285"; font-family: "bootstrap-icons"; color: var(--bs-secondary-color); font-size: 0.8rem; }
.math-path a {
  display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.8rem 0.35rem 0.4rem;
  border: 1px solid var(--bs-border-color); border-radius: 999px; background: var(--bs-body-bg);
  color: var(--bs-body-color); text-decoration: none; font-size: 0.875rem; box-shadow: var(--fd-shadow-sm);
}
.math-path a:hover { border-color: var(--bs-primary); color: var(--bs-primary); }
.math-path-num {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--bs-primary); color: #fff; font-weight: 600; font-size: 0.75rem;
}
.math-steps td { vertical-align: top; }
.math-steps .math-label { font-weight: 500; min-width: 10rem; }
.math-steps .math-note { font-weight: 400; font-size: 0.75rem; color: var(--bs-secondary-color); max-width: 22rem; margin-top: 0.15rem; }
.math-steps .math-formula { font-size: 0.8125rem; color: var(--bs-secondary-color); min-width: 14rem; }
.math-steps .math-working { font-size: 0.8125rem; font-variant-numeric: tabular-nums; min-width: 14rem; }
.math-steps .math-value { font-variant-numeric: tabular-nums; }
.math-total > * { font-weight: 600; border-top: 2px solid var(--bs-border-color); }
.math-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.math-chart .grid line { stroke: var(--bs-border-color); stroke-width: 1; }
.math-chart .zero-line { stroke: var(--bs-secondary-color); stroke-width: 1; }
.math-chart .connector { stroke: var(--bs-secondary-color); stroke-width: 1; stroke-dasharray: 2 2; }
.math-chart .axis-label { fill: var(--bs-secondary-color); font-size: 12px; }
.math-chart .value-label { fill: var(--bs-body-color); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.math-chart .hit { fill: transparent; }
.math-chart .bar:hover .mark { opacity: 0.8; }
.math-chart .is-up, .math-key.is-up { fill: var(--fd-chart-base); background: var(--fd-chart-base); }
.math-chart .is-down, .math-key.is-down { fill: var(--fd-chart-down); background: var(--fd-chart-down); }
.math-chart .is-total, .math-key.is-total { fill: var(--bs-secondary-color); background: var(--bs-secondary-color); }
.math-key { display: inline-block; width: 0.75rem; height: 0.75rem; border-radius: 2px; margin-right: 0.35rem; vertical-align: -0.05rem; }
