/* Financials */

.financials-page .inspections-proto {
  margin-inline: calc(var(--ipi-page-gutter) * -1);
  display: flex;
  flex-direction: column;
  gap: 22px;
  --financials-chart-bar: #1a1815;
  --financials-chart-bar-dim: rgba(61, 58, 52, 0.46);
  --financials-chart-line: #8a7a57;
  --financials-chart-muted: #d9d1c2;
}

.financials-page-header .ipi-ph-sub {
  max-width: 72ch;
}

.financials-page-header .ipi-ph-right {
  gap: 10px;
}

.financials-page-header .ipi-ph-right .btn svg {
  width: 13px;
  height: 13px;
}

.financials-stats-strip {
  flex-wrap: wrap;
}

.financials-stats-strip .ipi-stat {
  min-width: min(220px, 100%);
}

.financials-stats-strip .ipi-stat-num {
  font-size: clamp(22px, 2vw, 26px);
}

.financials-trend {
  font-size: 10px;
  font-weight: 600;
  margin-left: 4px;
  vertical-align: middle;
  white-space: nowrap;
}

.financials-trend--up {
  color: var(--success, #1e7a45);
}

.financials-trend--down {
  color: var(--danger, #b03030);
}

html[data-theme="dark"] .financials-trend--up {
  color: #34d399;
}

html[data-theme="dark"] .financials-trend--down {
  color: #f87171;
}

.financials-list-area {
  gap: 18px;
}

.financials-range-shell {
  display: grid;
  gap: 14px;
}

.financials-range-shell .ipi-filter-rail {
  align-items: center;
}

.financials-range-shell__stamps {
  display: flex;
  align-items: center;
  gap: 8px 10px;
  flex-wrap: wrap;
}

.financials-range-shell__stamp {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(26, 24, 21, 0.08);
  background: rgba(250, 247, 241, 0.82);
  color: #5f594e;
  font-size: 12px;
}

.financials-range-shell__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.financials-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) 360px;
  grid-template-areas:
    "main rail"
    "drivers rail";
  gap: 18px;
  align-items: start;
}

.financials-workspace__main,
.financials-workspace__rail,
.financials-driver-region,
.financials-driver-stack {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.financials-workspace__main {
  grid-area: main;
}

.financials-workspace__rail {
  grid-area: rail;
  align-content: start;
}

.financials-driver-region {
  grid-area: drivers;
}

.financials-panel-stack {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.financials-surface-header {
  margin: 0;
}

.financials-surface-header__title {
  margin: 0;
  font: inherit;
}

.financials-table-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.financials-table-grid--drivers {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.financials-spotlight {
  display: grid;
  gap: 16px;
  min-width: 0;
  padding: 18px;
  border: 1px solid rgba(26, 24, 21, 0.08);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.financials-spotlight__chart {
  min-width: 0;
}

.financials-pipeline-shell {
  display: grid;
  gap: 14px;
}

.financials-table-block .ipi-table-wrap,
.financials-empty {
  background: #fff;
}

.financials-table-block {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.financials-table-block .ipi-table-wrap {
  margin: 0;
}

.financials-table-block--featured .ipi-table-wrap {
  min-height: 0;
}

.financials-table .ipi-chip,
.financials-table .ipi-pill {
  white-space: nowrap;
}

.financials-data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.financials-data-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid rgba(26, 24, 21, 0.06);
}

.financials-data-card__label,
.financials-data-row__label {
  color: #5f594e;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.financials-data-card__value,
.financials-data-row__value {
  color: #1a1815;
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1.15;
}

.financials-data-card__note,
.financials-data-row__note {
  color: #6d6558;
  font-size: 12px;
  line-height: 1.45;
}

.financials-data-rows {
  display: grid;
  gap: 10px;
}

.financials-data-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(26, 24, 21, 0.06);
  background: #fff;
  color: inherit;
  text-decoration: none;
}

.financials-data-row__copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.financials-emphasis {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(250, 247, 241, 0.88), rgba(245, 240, 232, 0.88));
  border: 1px solid rgba(26, 24, 21, 0.06);
}

.financials-emphasis__value {
  font-family: var(--font-display);
  font-size: 28px;
  line-height: 1.02;
  letter-spacing: -0.03em;
  color: #1a1815;
}

.financials-emphasis__pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(26, 24, 21, 0.08);
}

.financials-band {
  display: grid;
  gap: 8px;
}

.financials-band__track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: rgba(26, 24, 21, 0.08);
  overflow: hidden;
}

.financials-band__range {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--band-left-pct, 0) * 1%);
  width: calc(var(--band-width-pct, 0) * 1%);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(184, 148, 82, 0.28), rgba(184, 148, 82, 0.62));
}

.financials-band__labels {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.financials-empty {
  display: grid;
  gap: 4px;
  padding: 16px;
  border-radius: 14px;
  border: 1px dashed rgba(26, 24, 21, 0.15);
  background: #fff;
}

.financials-empty__title {
  font-weight: 700;
  color: #1a1815;
}

.financials-legend {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.financials-legend__swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: middle;
}

.financials-legend__swatch--primary {
  background: #1a1815;
}

.financials-legend__swatch--muted {
  background: var(--financials-chart-muted, #d9d1c2);
}

.financials-chart {
  display: block;
  width: 100%;
  height: auto;
  color: #7b7265;
}

.financials-chart__link {
  cursor: pointer;
}

.financials-chart__link:focus-visible rect {
  stroke: currentColor;
  stroke-opacity: 0.55;
  stroke-width: 2;
}

.financials-chart__link.is-hover rect {
  opacity: 0.96;
}

.financials-chart__label {
  font-size: 12px;
  fill: currentColor;
}

.financials-chart__tick {
  font-size: 11px;
  fill: currentColor;
  opacity: 0.78;
}

.financials-chart__empty {
  font-size: 12px;
  fill: currentColor;
}

.financials-chart__grid {
  stroke: currentColor;
  stroke-opacity: 0.14;
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.financials-chart__bar {
  transition: opacity 0.12s ease-out;
}

.financials-chart__bar:hover {
  opacity: 0.92;
}

.financials-chart__area {
  opacity: 0.9;
}

.financials-chart--combo .financials-chart__area {
  opacity: 1;
}

.financials-chart__point {
  stroke: var(--card, #fff);
  stroke-width: 2;
}

.financials-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: min(340px, calc(100vw - 24px));
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(26, 24, 21, 0.96);
  color: rgba(255, 253, 248, 0.98);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

.financials-tooltip__title {
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 700;
}

.financials-tooltip__line {
  font-size: 0.85rem;
  line-height: 1.35;
  color: rgba(244, 238, 228, 0.92);
}

.financials-tooltip__hint {
  margin-top: 6px;
  font-size: 0.78rem;
  color: rgba(217, 209, 194, 0.92);
}

html[data-theme="dark"] .financials-range-shell__stamp,
html[data-theme="dark"] .financials-spotlight,
html[data-theme="dark"] .financials-table-block .ipi-table-wrap,
html[data-theme="dark"] .financials-data-card,
html[data-theme="dark"] .financials-data-row,
html[data-theme="dark"] .financials-empty,
html[data-theme="dark"] .financials-emphasis {
  background: var(--card);
  border-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .financials-data-card__label,
html[data-theme="dark"] .financials-data-row__label,
html[data-theme="dark"] .financials-data-card__note,
html[data-theme="dark"] .financials-data-row__note,
html[data-theme="dark"] .financials-range-shell__stamp {
  color: var(--text-muted);
}

html[data-theme="dark"] .financials-data-card__value,
html[data-theme="dark"] .financials-data-row__value,
html[data-theme="dark"] .financials-empty__title,
html[data-theme="dark"] .financials-emphasis__value {
  color: var(--text);
}

html[data-theme="dark"] .financials-band__track {
  background: rgba(255, 255, 255, 0.08);
}

/* --- Collapsible sections: open on desktop, summary hidden --- */
.financials-collapse__summary {
  display: none;
}

.financials-collapse__body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (hover: hover) and (pointer: fine) {
  .financials-data-row:hover {
    color: #1a1815;
    transform: translateY(-1px);
  }
}

/* --- Desktop/laptop: workspace single column --- */
@media (max-width: 1080px) {
  .financials-workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "main"
      "rail"
      "drivers";
  }

  .financials-table-grid {
    grid-template-columns: 1fr;
  }

  .financials-table-grid--drivers {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* --- Standard mobile breakpoint (900px) --- */
@media (max-width: 900px) {

  /* Container chain overflow fix */
  .financials-page,
  .financials-page .ipi-list-area,
  .financials-page .ipi-filter-shell {
    min-width: 0;
    max-width: 100%;
  }

  .financials-page .ipi-list-area {
    overflow-x: hidden;
  }

  /* --- Stats strip: horizontal scroll carousel ---
     Desktop has flex-wrap: wrap — MUST override to nowrap for scroll. */
  .financials-page .ipi-stats-strip {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x proximity;
    scroll-padding-left: var(--ipi-page-gutter);
    scroll-padding-right: var(--ipi-page-gutter);
    padding-bottom: 20px;
  }

  .financials-page .ipi-stats-strip::-webkit-scrollbar {
    display: none;
  }

  /* Reset desktop min-width: min(220px, 100%) which prevents flex-basis from working */
  .financials-page .ipi-stat,
  .financials-stats-strip .ipi-stat {
    flex: 0 0 min(240px, 76vw);
    scroll-snap-align: start;
    min-width: 0;
  }

  .financials-page .ipi-stats-strip > .ipi-stat:first-child {
    margin-left: var(--ipi-page-gutter);
  }

  .financials-page .ipi-stats-strip > .ipi-stat:last-child {
    margin-right: var(--ipi-page-gutter);
  }

  /* --- Page header: 4 buttons → 2×2 grid --- */
  .financials-page-header .ipi-ph-right {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .financials-page-header .ipi-ph-right .btn {
    width: 100%;
    justify-content: center;
  }

  /* --- Filter rail: column layout for range controls --- */
  .financials-page .ipi-filter-rail {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px 16px;
    background: var(--ipi-bg-card);
    border-radius: 12px;
    box-shadow: var(--ipi-shadow-card);
  }

  .financials-range-shell__stamps {
    flex-direction: column;
    gap: 6px;
  }

  .financials-range-shell__actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .financials-range-shell__actions .btn {
    flex: 1 1 auto;
    min-height: 40px;
    justify-content: center;
  }

  /* --- Driver table grid: single column --- */
  .financials-table-grid--drivers {
    grid-template-columns: 1fr;
  }

  /* --- Emphasis & data rows: stack vertically --- */
  .financials-emphasis,
  .financials-data-row {
    align-items: stretch;
    flex-direction: column;
  }

  /* --- Spotlight: reduced padding --- */
  .financials-spotlight {
    padding: 16px;
  }

  /* --- Data grid: 2 columns on mobile --- */
  .financials-data-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* --- Table card-ification --- */
  .financials-page .financials-table,
  .financials-page .financials-table thead,
  .financials-page .financials-table tbody,
  .financials-page .financials-table tr,
  .financials-page .financials-table th,
  .financials-page .financials-table td {
    display: block;
    width: 100%;
  }

  .financials-page .financials-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .financials-page .financials-table tbody {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .financials-page .financials-table tr {
    border: 1px solid rgba(26, 24, 21, 0.1);
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    padding: 6px 0;
  }

  .financials-page .financials-table td {
    position: relative;
    padding: 7px 14px 7px 110px;
    border-bottom: 1px solid rgba(26, 24, 21, 0.06);
    text-align: left !important;
    white-space: normal;
  }

  .financials-page .financials-table td:last-child {
    border-bottom: none;
  }

  .financials-page .financials-table td::before {
    content: attr(data-label);
    position: absolute;
    left: 14px;
    top: 7px;
    width: 82px;
    color: #9a9188;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  /* Override ipi-table min-width for card layout */
  .financials-page .ipi-table-wrap {
    overflow-x: visible;
  }

  .financials-page .ipi-table.financials-table {
    min-width: 0;
  }

  /* --- Collapsible sections: show summary, collapse by default --- */
  .financials-collapse__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    background: var(--ipi-bg-card, #ffffff);
    border-radius: 12px;
    box-shadow: var(--ipi-shadow-card, 0 1px 4px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.05));
    font-size: 13px;
    font-weight: 600;
    color: var(--ipi-ink, #1a1815);
    cursor: pointer;
    list-style: none;
    -webkit-tap-highlight-color: transparent;
  }

  .financials-collapse__summary::-webkit-details-marker {
    display: none;
  }

  .financials-collapse__chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
  }

  .financials-collapse[open] .financials-collapse__chevron {
    transform: rotate(180deg);
  }

  .financials-collapse__body {
    margin-top: 12px;
  }

  /* --- Surface headers: stack vertically --- */
  .financials-surface-header.ipi-result-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .financials-surface-header__actions {
    width: 100%;
  }

  /* --- Range stamp pills: flex-wrap for narrow screens --- */
  .financials-range-shell__stamp {
    display: flex;
    white-space: normal;
    text-align: left;
  }

  /* --- Data cards: ensure min-width doesn't force overflow --- */
  .financials-data-card {
    min-width: 0;
  }

  /* --- Emphasis value: scale down on mobile --- */
  .financials-emphasis__value {
    font-size: 22px;
  }

  /* --- Reduce workspace gaps --- */
  .financials-list-area {
    gap: 14px;
  }

  .financials-workspace {
    gap: 14px;
  }

  /* --- Panel stacks: tighter gaps --- */
  .financials-panel-stack {
    gap: 10px;
  }
}

/* --- Dark mode: mobile table cards --- */
@media (max-width: 900px) {
  html[data-theme="dark"] .financials-page .financials-table tr {
    background: var(--card);
    border-color: var(--border);
    box-shadow: none;
  }

  html[data-theme="dark"] .financials-page .financials-table td {
    border-bottom-color: rgba(71, 85, 105, 0.4);
  }

  html[data-theme="dark"] .financials-page .financials-table td::before {
    color: var(--text-muted);
  }
}
