/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
ELECTORATE PROFILE PANELS
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.section-label {
  font-family: var(--font-sans);
  font-size: 24px;
  font-weight: 700;
  color: var(--colour-parliamentary-dark);
  padding-bottom: 8px;
  margin: 0 0 16px;
}

/* Shared panel background and spacing for each chart panel */
.ethnicity-panel,
.age-panel,
.gender-panel,
.qualification-panel,
.household-composition-panel,
.individual-home-ownership-panel,
.workforce-status-panel,
.occupation-panel,
.industry-panel {
  background: var(--colour-parliamentary-light);
  margin-bottom: 28px;
}

/* Wrap long panel body text */
.ethnicity-panel p,
.qualification-panel p {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Two-column layout for the age and gender donuts */
.demographic-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
}

/* Lets the SVG charts size themselves instead of using a fixed height */
.chart-wrapper {
  height: auto;
}

/* Legacy stacked age bar (currently unused, the donut replaced it) */
.distribution-graph {
  margin-bottom: 36px;
}

.distribution-bar {
  display: flex;
  height: 26px;
  border: var(--border-style);
  box-sizing: border-box;
}

.age-segment--under15 { background: var(--cyan); }
.age-segment--15to29 { background: var(--blue); }
.age-segment--30to64 { background: var(--yellow); }
.age-segment--65plus { background: var(--coral); }

.distribution-labels {
  display: flex;
  margin-top: 4px;
  font-size: 16px;
  font-weight: 600;
  color: var(--colour-parliamentary-dark);
}

.distribution-labels span:first-child { text-align: left; }
.distribution-labels span:last-child { text-align: right; }
.distribution-labels span:not(:first-child):not(:last-child) { text-align: center; }


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
LEGENDS AND COLOUR KEYS
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.legend {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  font-size: var(--font-sans-body-small);
}

.legend li {
  display: inline-flex;
  align-items: center;
  max-width: none;
}

/* Colour swatch, the colour comes from the --c variable set in JS */
.key {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  margin-right: 0.45rem;
  border-radius: 2px;
  background: var(--c, var(--g-other));
  flex: none;
}

/* Diagonal stripes for hatched items such as transfers and forecasts */
.is-hatched,
.key.is-hatched {
  background-image: repeating-linear-gradient(-45deg, transparent 0 5px, rgba(255, 255, 255, 0.55) 5px 9px);
}


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
CHART CONTAINERS
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.chart {
  margin: 0;
}

.chart-caption {
  color: var(--grey-dark);
  margin-bottom: 0.75rem;
  max-width: var(--measure);
}

/* Holds the "Show as table" and download buttons under a chart */
.chart-foot {
  margin-top: 0.75rem;
}

.chart-foot .chart-table {
  margin-top: 0.75rem;
}


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
DONUT CHARTS
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.donut-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
}

.donut {
  width: 200px;
  max-width: 100%;
  flex: none;
}

.donut-segment {
  cursor: pointer;
}


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
COLUMN CHARTS
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.columns {
  display: block;
  width: 100%;
  height: auto;
  font-family: var(--font-sans);
}

/* Gridlines, axis and tick labels */
.col-grid {
  stroke: var(--grey-light);
  stroke-width: 1;
}

.col-axis {
  stroke: var(--dark);
  stroke-width: 1;
}

.col-tick {
  font-size: 12px;
  fill: var(--grey-dark);
}

.col-sub {
  font-size: 11px;
  fill: var(--grey-dark);
}

/* Shaded forecast area and its label */
.col-note {
  font-size: 12px;
  font-weight: 700;
  fill: var(--grey-dark);
}

.col-forecast-bg {
  fill: #f7f7f7;
}

.col-is-forecast {
  opacity: 0.55;
}

/* Outline shown when a column is hovered or focused */
.col-hit {
  cursor: default;
}

.col-hit:focus {
  outline: none;
}

.col-hit:focus .col,
.col-hit:hover .col {
  stroke: var(--dark);
  stroke-width: 2;
}


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
BAR CHARTS
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.bar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Three columns per row: label, bar track, value */
.bar-list li {
  display: grid;
  grid-template-columns: minmax(8rem, 15rem) minmax(0, 1fr) 6.5rem;
  gap: 0.75rem;
  align-items: center;
  padding: 0.35rem 0;
  max-width: none;
  font-size: var(--font-sans-body-small);
}

/* Compact version used for the largest appropriations list */
.bar-list-compact li {
  grid-template-columns: minmax(10rem, 17rem) minmax(0, 1fr) 6.5rem;
  align-items: start;
}

.bar-label {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
}

.bar-sub {
  flex-basis: 100%;
  font-size: var(--font-sans-caption);
  color: var(--grey-dark);
}

.bar-track {
  height: 1.1rem;
}

.bar-list-compact .bar-track {
  margin-top: 0.15rem;
}

.bar {
  display: block;
  height: 100%;
  background-color: var(--c);
  border-radius: 0 3px 3px 0;
}

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
CHANGE BARS AND LIFECYCLE BAR
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.change-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.change-list li {
  display: grid;
  grid-template-columns: minmax(9rem, 16rem) minmax(0, 1fr) 7.5rem;
  gap: 0.75rem;
  align-items: center;
  padding: 0.3rem 0;
  max-width: none;
  font-size: var(--font-sans-body-small);
  border-bottom: 1px solid var(--grey-light);
}

/* Divider between the increases and the decreases */
.change-list li.is-down:first-of-type,
.change-list li.is-up + li.is-down {
  border-top: 2px solid var(--grey-light-mid);
  margin-top: 0.4rem;
  padding-top: 0.6rem;
}

/* Centre line that bars grow out of, left for decreases and right for increases */
.change-track {
  position: relative;
  height: 1.1rem;
}

.change-track::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -0.3rem;
  bottom: -0.3rem;
  border-left: 1px solid var(--dark);
}

.change-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--c);
}

.is-up .change-bar {
  border-radius: 0 3px 3px 0;
}

.is-down .change-bar {
  border-radius: 3px 0 0 3px;
}

.change-list .bar-value {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.change-list .bar-value span {
  font-weight: 400;
  color: var(--grey-dark);
  font-size: var(--font-sans-caption);
}

/* Single bar showing how much of a multi-year appropriation has been used */
.life-bar {
  display: flex;
  height: 2.2rem;
  gap: 2px;
  margin-bottom: 0.75rem;
  border: 1px solid var(--grey-light-mid);
}

.life-part {
  display: block;
  background-color: var(--c);
}

.life-part.is-hatched {
  background: repeating-linear-gradient(-45deg, var(--white) 0 3px, var(--grey-dark) 3px 5px);
}


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
TREEMAPS
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.treemap {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--light);
  border: 2px solid var(--dark);
}

/* Dashboard overview treemap is wider and has no border */
#ov-treemap {
  aspect-ratio: 2 / 1;
  border: 0;
  overflow: hidden;
}

.treemap-build {
  aspect-ratio: 4 / 3;
}

#tax-tree {
  aspect-ratio: 4 / 3;
}

/* Each box in the treemap, positioned by JS */
.tm-box {
  position: absolute;
  margin: 0;
  padding: 0.4rem 0.5rem;
  border: 0;
  border-radius: 0;
  box-shadow: inset 0 0 0 1.5px var(--light);
  background-color: var(--c);
  color: var(--dark);
  text-align: left;
  text-decoration: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  font-size: var(--font-sans-body-small);
  line-height: 1.3;
  cursor: pointer;
}

.tm-box:hover {
  filter: brightness(1.08) saturate(1.05);
}

/* Links (dashboard) underline on hover, buttons (youth budget) do not */
a.tm-box:hover {
  text-decoration: underline;
}

.tm-box.on-dark {
  color: var(--light);
}

.tm-name {
  font-weight: 700;
}

/* Small boxes hide their text visually but keep it for screen readers */
.tm-small {
  padding: 0;
}

.tm-small .tm-name,
.tm-small .tm-amt {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.tm-tiny {
  pointer-events: none;
}

.tm-selected {
  box-shadow:
    inset 0 0 0 4px var(--dark),
    inset 0 0 0 6px var(--light);
  z-index: 1;
}

/* Striped box for money not yet allocated in the budget builder */
.tm-unalloc {
  --c: var(--grey-mid);
  background: repeating-linear-gradient(45deg, var(--light) 0 7px, var(--grey-light) 7px 14px);
  border-top: 0;
  box-shadow: inset 0 0 0 2px var(--grey-mid);
}

.tm-box:focus-visible {
  z-index: 3;
  outline-offset: -4px;
  box-shadow: inset 0 0 0 6px var(--light);
}

/* Drag handles for resizing boxes in the budget builder */
.tm-handle {
  position: absolute;
  z-index: 4;
  padding: 0;
  background: var(--dark);
  border: 2px solid var(--light);
  touch-action: none;
}

/* Larger invisible hit area around each handle */
.tm-handle::before {
  content: '';
  position: absolute;
  inset: -12px;
}

.tm-handle.h-right {
  width: 14px;
  height: 48px;
  margin: -24px 0 0 -7px;
  cursor: ew-resize;
  background-image: linear-gradient(
    90deg,
    transparent 4px,
    var(--light) 4px 5px,
    transparent 5px 7px,
    var(--light) 7px 8px,
    transparent 8px
  );
}

.tm-handle.h-bottom {
  width: 48px;
  height: 14px;
  margin: -7px 0 0 -24px;
  cursor: ns-resize;
  background-image: linear-gradient(
    0deg,
    transparent 4px,
    var(--light) 4px 5px,
    transparent 5px 7px,
    var(--light) 7px 8px,
    transparent 8px
  );
}

.tm-handle.h-corner {
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  cursor: nwse-resize;
  background-image: linear-gradient(
    135deg,
    transparent 45%,
    var(--light) 45% 52%,
    transparent 52% 62%,
    var(--light) 62% 69%,
    transparent 69%
  );
}

.tm-handle:focus-visible {
  outline: 3px solid var(--dark);
  outline-offset: 3px;
  box-shadow: 0 0 0 7px var(--light);
}

.treemap.dragging,
.treemap.dragging * {
  cursor: grabbing !important;
}

.tm-callout {
  position: absolute;
  z-index: 3;
  max-width: 15rem;
  background: var(--dark);
  color: var(--light);
  font-size: var(--font-sans-body-small);
  line-height: 1.4;
  padding: 0.55rem 0.7rem;
  pointer-events: none;
  transition: opacity 0.3s;
}
.tm-callout strong {
  display: block;
}
.tm-callout::before {
  content: '';
  position: absolute;
  left: 14px;
  top: -7px;
  border: 7px solid transparent;
  border-top: 0;
  border-bottom-color: var(--dark);
}
.tm-callout.out {
  opacity: 0;
}

.tm-box {
  transition:
    left 0.35s ease,
    top 0.35s ease,
    width 0.35s ease,
    height 0.35s ease,
    background-color 0.2s ease;
}
.treemap.dragging .tm-box {
  transition: none;
}
.treemap.tm-enter .tm-box {
  animation: tmIn 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes tmIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
}

.tm-callout {
  animation: calloutIn 0.35s ease-out both;
}
@keyframes calloutIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* small tree map text styling */
[data-small-key] {
  column-width: 290px;
  column-gap: 14px;
}

.small-key {
  margin-top: 10px;
  column-width: 200px;
  column-gap: 10px;
}

.key-card {
  break-inside: avoid;
  margin: 0 0 10px;
  padding: 8px 12px 6px;
 
  /* background: color-mix(in srgb, var(--c) 20%, white); */
  color: #2b2b2b;
}

.key-card-head {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 3px;
  line-height: 1.2em;
   border-bottom: 4px solid var(--c);
}

.key-card .small-key-item {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 2px 0;
  font-size: 14px;
  line-height: 1.3;
  break-inside: avoid;
}

.key-card-name {
  flex: 1;
  min-width: 0;
}

.key-card-amount {
  margin-left: auto;
  flex: none;
  font-weight: bold;
  white-space: nowrap;
  color: #555;
}

.small-key-item a {
  color: var(--text);
  margin-right: 0.25rem;
} */


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
DATA TABLES
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
/* Wrapper that scrolls sideways on narrow screens */
.table-scroll {
  overflow-x: auto;
  max-width: 100%;
}

.table-scroll:focus-visible {
  outline-offset: 4px;
}

.table-scroll-tall {
  max-height: 75vh;
  overflow: auto;
  border-bottom: 1px solid var(--grey-light-mid);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sans-body-small);
}

.data-table caption {
  text-align: left;
  font-weight: 700;
  padding-bottom: 0.5rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--grey-light-mid);
  vertical-align: top;
}

.data-table tbody th {
  font-weight: 400;
}

.data-table thead th {
  border-bottom: 2px solid var(--dark);
  vertical-align: bottom;
  font-weight: 700;
  background: var(--grey-light);
}

/* Numbers line up in columns and stay on one line */
.data-table td {
  font-variant-numeric: tabular-nums;
}

.data-table .num {
  text-align: right;
  white-space: nowrap;
}

.data-table tfoot th,
.data-table tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--dark);
  border-bottom: 0;
}

.data-table td.empty {
  padding: 1.5rem 0;
  color: var(--grey-dark);
}

/* Row states */
.data-table tr.is-selected > * {
  background: var(--quiet-bg);
}

.data-table tr.is-mca > * {
  background: var(--tint-mca);
}

.data-table tr.is-mca > :first-child {
  box-shadow: inset 4px 0 0 var(--blue-dark);
}

.data-table tr.is-category > * {
  background: var(--tint-category);
  color: var(--grey-dark);
}

.data-table tr.is-category > :first-child {
  box-shadow: inset 4px 0 0 var(--blue-light);
  padding-left: 1.6rem;
}

.data-table tr.is-muted > * {
  color: var(--grey-dark);
}

/* Cell layouts */
.cell-flex {
  display: flex;
  align-items: center;
}

.cell-stack {
  display: flex;
  flex-direction: column;
}

.cell-sub {
  font-size: var(--font-sans-caption);
  color: var(--grey-dark);
}

/* Sortable column headers */
.sort-btn {
  border: 0;
  background: none;
  padding: 0;
  font-weight: 700;
  text-align: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: flex-end;
  gap: 0.25rem;
}

.num .sort-btn {
  flex-direction: row-reverse;
}

.sort-btn:hover {
  text-decoration: underline;
}

.sort-icon {
  font-size: 0.65rem;
  min-width: 0.7rem;
}

/* Buttons under a table and the page size and paging controls */
.table-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.table-actions-top {
  margin: 0 0 0.75rem;
}

.pager {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  font-size: var(--font-sans-body-small);
}

.pager-size {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.pager-size select {
  width: auto;
  min-height: 36px;
  margin: 0;
}


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
FINANCIAL SUMMARY (PIVOT TABLE)
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
.pivot {
  min-width: 64rem;
}

/* Sticky headers and first column so labels stay visible while scrolling */
.pivot thead th {
  position: sticky;
  top: 0;
  background: var(--light);
  z-index: 2;
}

.pivot thead tr + tr th {
  top: 2.1rem;
}

.pivot .pivot-first {
  position: sticky;
  left: 0;
  background: var(--light);
  z-index: 1;
  min-width: 16rem;
  max-width: 22rem;
}

.pivot thead .pivot-first {
  z-index: 3;
}

/* Year headings and column types */
.pivot .year-head {
  text-align: center;
  border-bottom: 1px solid var(--grey-light-mid);
}

.pivot .sub-head {
  font-weight: 400;
  color: var(--grey-dark);
  font-size: var(--font-sans-caption);
}

.pivot .year-start {
  padding-left: 0.75rem;
  border-left: 1px solid var(--grey-light-mid);
}

.pivot .is-budget {
  background: #f7f7f7;
  font-weight: 700;
}

.pivot .is-forecast {
  color: var(--grey-dark);
}

/* Vote rows and their expandable category rows */
.pivot-vote > * {
  font-weight: 700;
}

.pivot-vote .pivot-first {
  padding-left: 8px;
}
.pivot-cat .pivot-first {
  padding-left: 40px;
}

.pivot-toggle {
  float: left;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin: 0 8px 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

.pivot-toggle .chev {
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}

.pivot-toggle[aria-expanded="true"] .chev {
  transform: rotate(45deg);
}

.pivot tfoot th,
.pivot tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--light);
}

.key-explain {
  margin-top: 2rem;
}

.key-explain h2 {
  font-size: var(--font-sans-heading-6);
}

.pivot .sr-only,
.pivot-toggle .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/*★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
MOBILE OVERRIDES
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★*/
@media (max-width: 640px) {

  /* Stack the age and gender donuts */
  .demographic-columns {
    grid-template-columns: 1fr;
  }

  .section-label { font-size: 20px; }
  .stat-title { font-size: 16px; }
}