/* Same frame as Financeiro › Visão Geral, Despesas administrativas and
   Categorias de despesa: masthead, one joined KPI panel, and the list inside
   a titled card. In place of their trail bar, the panel draws the rates as a
   staircase — each vigência is a tread as wide as the days it held and as
   tall as its rate — with a marker for today. Ended treads stay neutral, the
   current one takes the primary color, and scheduled ones are hatched. */
@scope (.tax-rates-page) {
  :scope {
    --_surface: var(--color-surface);
    --_muted: var(--color-surface-muted);
    --_border: var(--color-border-muted);
    --_ink: var(--color-text-heading);
    display: flex;
    gap: var(--space-xl);
    container: tax-rates / inline-size;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  :scope > * {
    min-inline-size: 0;
  }

  .list-page__content {
    flex: none;
    min-height: auto;
    overflow: visible;
    padding-bottom: var(--space-xl);
  }

  /* Masthead */
  .tax-rates-page__masthead {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: var(--space-lg);
    flex-shrink: 0;
    padding-block: var(--space-lg) 0;
    border-bottom: 1px solid var(--_border);
  }

  .tax-rates-page__eyebrow {
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-widest);
    text-transform: uppercase;
  }

  .tax-rates-page__title {
    margin-top: var(--space-xs);
    color: var(--_ink);
    font-size: clamp(var(--text-heading-2), 3vw, var(--text-heading-1));
    font-weight: var(--font-semibold);
  }

  .tax-rates-page__thesis {
    max-inline-size: 46rem;
    margin-top: var(--space-sm);
    color: var(--color-text-secondary);
    font-size: var(--text-body);
  }

  /* KPI panel — the 1px grid gap over the border color draws the dividers,
     so any column count keeps clean lines. */
  .tax-rates-page__summary,
  .tax-rates-page__roster {
    flex-shrink: 0;
    border: 1px solid var(--_border);
    border-radius: var(--radius-xl);
    background: var(--_surface);
    box-shadow: var(--shadow-xs);
  }

  .tax-rates-page__summary {
    container: tax-rate-kpis / inline-size;
  }

  .tax-rates-page__metrics {
    display: grid;
    overflow: hidden;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    border-bottom: 1px solid var(--_border);
    border-start-start-radius: var(--radius-xl);
    border-start-end-radius: var(--radius-xl);
    background: var(--_border);
  }

  .tax-rates-page__metric {
    display: grid;
    align-content: start;
    gap: var(--space-xs);
    min-inline-size: 0;
    padding: var(--space-lg);
    background: var(--_surface);
  }

  .tax-rates-page__metric--lead {
    background: linear-gradient(var(--color-primary-muted), var(--color-primary-muted)), var(--_surface);
  }

  .tax-rates-page__metric-label {
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
  }

  .tax-rates-page__metric-value {
    overflow: hidden;
    color: var(--_ink);
    font-family: var(--font-mono);
    font-size: clamp(var(--text-heading-5), 2.6cqi, var(--text-heading-3));
    font-variant-numeric: tabular-nums;
    letter-spacing: var(--tracking-tighter);
    line-height: var(--leading-tight);
    text-overflow: ellipsis;
  }

  .tax-rates-page__metric-detail {
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: var(--text-caption);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  @container tax-rate-kpis (width < 44rem) {
    .tax-rates-page__metrics {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @container tax-rate-kpis (width < 24rem) {
    .tax-rates-page__metrics {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  /* Staircase */
  .tax-rates-page__timeline {
    display: grid;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg) var(--space-lg);
  }

  .tax-rates-page__timeline-title {
    color: var(--color-text-secondary);
    font-size: var(--text-caption);
    font-weight: var(--font-semibold);
  }

  .tax-rates-page__stairs {
    --_rise: 4.5rem;
    position: relative;
    display: flex;
    align-items: end;
    block-size: calc(var(--_rise) + 1.5rem);
    border-bottom: 1px solid var(--_border);
  }

  .tax-rates-page__step {
    --_tone: var(--color-text-muted);
    --_fill: color-mix(in oklab, var(--_tone) 14%, transparent);
    display: flex;
    flex: var(--share, 0) 1 0;
    flex-direction: column;
    justify-content: end;
    min-inline-size: 3px;
  }

  .tax-rates-page__step--current {
    --_tone: var(--color-primary);
    --_fill: color-mix(in oklab, var(--_tone) 22%, transparent);
  }

  .tax-rates-page__step--scheduled {
    --_tone: var(--color-primary);
    --_fill: repeating-linear-gradient(
      -45deg,
      color-mix(in oklab, var(--_tone) 22%, transparent) 0 4px,
      transparent 4px 8px
    );
  }

  .tax-rates-page__step-rate {
    padding-inline: var(--space-xs);
    padding-block-end: var(--space-2xs);
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
    font-size: var(--text-caption);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  /* The last tread is often the narrowest; its label hangs leftward over
     the previous one's empty space instead of spilling out of the chart. */
  .tax-rates-page__step--last .tax-rates-page__step-rate {
    display: flex;
    justify-content: flex-end;
  }

  .tax-rates-page__step--current .tax-rates-page__step-rate {
    color: var(--_ink);
    font-weight: var(--font-semibold);
  }

  .tax-rates-page__step--narrow .tax-rates-page__step-rate {
    visibility: hidden;
  }

  /* The tread's top edge is the rate; neighbours meet edge to edge, so a
     change of rate reads as a riser. */
  .tax-rates-page__step-tread {
    block-size: max(3px, calc(var(--_rise) * var(--height, 0) / 100));
    border-top: 2px solid var(--_tone);
    background: var(--_fill);
  }

  .tax-rates-page__step + .tax-rates-page__step .tax-rates-page__step-tread {
    box-shadow: inset 1px 0 0 var(--_surface);
  }

  .tax-rates-page__today {
    position: absolute;
    inset-block: 0;
    inset-inline-start: var(--at, 0%);
    border-inline-start: 1px dashed var(--_ink);
    pointer-events: none;
  }

  .tax-rates-page__axis {
    position: relative;
    display: flex;
    color: var(--color-text-muted);
    font-size: var(--text-caption);
    font-variant-numeric: tabular-nums;
  }

  .tax-rates-page__axis-today {
    position: absolute;
    inset-inline-start: var(--at, 0%);
    color: var(--_ink);
    font-weight: var(--font-semibold);
    translate: -50% 0;
  }

  .tax-rates-page__axis-today--end {
    translate: -100% 0;
    padding-inline-end: var(--space-2xs);
  }

  .tax-rates-page__legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-lg);
    color: var(--color-text-secondary);
    font-size: var(--text-caption);
    list-style: none;
  }

  .tax-rates-page__legend-key {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
  }

  .tax-rates-page__legend-key::before {
    content: "";
    width: 0.75rem;
    height: 0.6rem;
    border-top: 2px solid var(--_tone);
    background: var(--_fill);
  }

  .tax-rates-page__legend-key--ended {
    --_tone: var(--color-text-muted);
    --_fill: color-mix(in oklab, var(--_tone) 14%, transparent);
  }

  .tax-rates-page__legend-key--current {
    --_tone: var(--color-primary);
    --_fill: color-mix(in oklab, var(--_tone) 22%, transparent);
  }

  .tax-rates-page__legend-key--scheduled {
    --_tone: var(--color-primary);
    --_fill: repeating-linear-gradient(-45deg, color-mix(in oklab, var(--_tone) 30%, transparent) 0 2px, transparent 2px 4px);
  }

  .tax-rates-page__timeline-empty {
    color: var(--color-text-muted);
    font-size: var(--text-caption);
  }

  /* Roster card */
  .tax-rates-page__roster {
    overflow: hidden;
    container: tax-rate-roster / inline-size;
  }

  .tax-rates-page__roster-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: var(--space-lg);
    padding: var(--space-lg);
    border-bottom: 1px solid var(--_border);
  }

  .tax-rates-page__roster-header h2 {
    margin-top: var(--space-2xs);
    color: var(--_ink);
    font-size: var(--text-heading-5);
  }

  .tax-rates-page__roster-count {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-caption);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .tax-rates-table thead {
    border-bottom-width: 1px;
    background: var(--_muted);
  }

  .tax-rates-table th:first-child,
  .tax-rates-table td:first-child {
    padding-inline-start: var(--space-lg);
  }

  .tax-rates-table th:last-child,
  .tax-rates-table td:last-child {
    padding-inline-end: var(--space-lg);
  }

  .tax-rates-table tbody tr:last-child td {
    border-bottom: 0;
  }

  /* Rows */
  .tax-rate-row--current {
    background: linear-gradient(var(--color-primary-muted), var(--color-primary-muted));
  }

  .tax-rate-row__range {
    display: block;
    color: var(--_ink);
    font-weight: var(--font-semibold);
    font-variant-numeric: tabular-nums;
  }

  .tax-rate-row__detail {
    display: block;
    margin-top: var(--space-2xs);
    color: var(--color-text-muted);
    font-size: var(--text-caption);
  }

  .tax-rate-row__change {
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
    font-size: var(--text-body-sm);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .tax-rate-row__change--up {
    color: var(--color-error-text);
  }

  .tax-rate-row__change--down {
    color: var(--color-success-text);
  }

  .tax-rate-row__rate {
    color: var(--_ink);
    font-family: var(--font-mono);
    font-size: var(--text-heading-6, var(--text-body));
    font-weight: var(--font-semibold);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .tax-rate-row--ended .tax-rate-row__range,
  .tax-rate-row--ended .tax-rate-row__rate {
    color: var(--color-text-secondary);
    font-weight: var(--font-medium);
  }

  /* An ended vigência gets a neutral fill so its badge lines up with the
     tinted ones. */
  .tax-rate-row--ended .badge {
    --_bg: var(--_muted);
  }

  .tax-rate-row__actions {
    white-space: nowrap;
  }

  .tax-rate-row__actions .button {
    --_height: 2.25rem;
  }

  .tax-rate-row__actions .button:not(.button--icon) {
    --_padding-x: var(--space-md);
  }

  .tax-rate-row__actions form {
    display: inline-flex;
  }

  /* Narrow widths: each row becomes a card — vigência and rate on top,
     then situação and variação, then the actions. */
  @container tax-rate-roster (width < 40rem) {
    .tax-rates-table,
    .tax-rates-table tbody {
      display: block;
    }

    .tax-rates-table thead {
      display: none;
    }

    .tax-rate-row {
      display: grid;
      grid-template-areas:
        "period rate"
        "state change"
        "actions actions";
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: center;
      gap: var(--space-sm) var(--space-lg);
      padding: var(--space-md) var(--space-lg);
      border-bottom: 1px solid var(--_border);
    }

    .tax-rate-row:last-child {
      border-bottom: 0;
    }

    .tax-rates-table .tax-rate-row > td {
      display: block;
      min-inline-size: 0;
      padding: 0;
      border: 0;
      text-align: start;
    }

    .tax-rate-row__period { grid-area: period; }
    .tax-rate-row__state { grid-area: state; }
    .tax-rates-table .tax-rate-row > .tax-rate-row__rate { grid-area: rate; align-self: start; text-align: end; }
    .tax-rates-table .tax-rate-row > .tax-rate-row__change { grid-area: change; text-align: end; }

    .tax-rates-table .tax-rate-row > .tax-rate-row__actions {
      grid-area: actions;
      justify-self: end;
    }
  }

  .tax-rates-page__empty {
    display: grid;
    justify-items: center;
    gap: var(--space-md);
    min-block-size: 18rem;
    padding: var(--space-4xl) var(--space-lg);
    color: var(--color-text-muted);
    text-align: center;
    place-content: center;
  }

  .tax-rates-page__empty p {
    max-inline-size: 28rem;
  }

  .tax-rates-page__empty-icon {
    width: 2rem;
    height: 2rem;
    color: var(--color-text-secondary);
  }

  @container tax-rates (width < 40rem) {
    .tax-rates-page__masthead > .button {
      inline-size: 100%;
      justify-content: center;
    }
  }

  @container tax-rates (width < 28rem) {
    .tax-rates-page__roster-header {
      align-items: start;
      flex-direction: column;
    }
  }
}
