@layer components {
  /* Fee Allocation Form Styles */
  
  /* One cohesive table: labeled header, rows, and totals footer share a
     single container and column grid. */
  .allocation-table {
    --allocation-grid: minmax(0, 1fr) 72px 108px minmax(88px, auto) 28px;
    background: var(--rd-bg-raised);
    border: 1px solid var(--color-border);
  }

  .allocation-table-head {
    display: grid;
    grid-template-columns: var(--allocation-grid);
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--rd-text-2xs, 0.75rem);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--rd-fg-subtle);
  }

  .allocation-row {
    padding: var(--space-2) var(--space-3);
  }

  .allocation-row + .allocation-row {
    border-top: 1px solid var(--color-border);
  }

  /* Error state for allocation rows with validation errors */
  .allocation-row.allocation-row-error {
    box-shadow: inset 2px 0 0 var(--color-negative);
    background: oklch(var(--rd-danger) / 0.05);
  }

  .allocation-row-fields {
    display: grid;
    grid-template-columns: var(--allocation-grid);
    align-items: center;
    gap: var(--space-3);
  }

  .allocation-row-cost-center {
    min-width: 0;
  }

  .allocation-row-cost-center .form-select,
  .allocation-row-cost-center .rd-select {
    width: 100%;
    margin: 0;
  }

  .allocation-row-hours {
    font-size: var(--rd-text-sm);
    color: var(--rd-fg-muted);
    font-family: var(--rd-font-mono);
    white-space: nowrap;
    min-width: 0;
    text-align: right;
  }

  .allocation-table-head .allocation-row-hours,
  .allocation-table-head .allocation-row-percentage,
  .allocation-table-head .allocation-row-amount {
    font: inherit;
    color: inherit;
    text-align: right;
  }

  .allocation-row-percentage input {
    text-align: right;
  }

  .allocation-row-amount {
    text-align: right;
    font-weight: var(--font-semibold);
    color: var(--rd-fg);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .allocation-row-actions {
    display: flex;
    justify-content: flex-end;
  }

  .allocation-row-actions .btn-ghost:hover {
    color: var(--color-negative);
  }

  /* Empty state (lives inside the table container) */
  .allocation-empty-state {
    padding: var(--space-4);
    text-align: center;
  }

  /* Summary section */
  .allocation-summary {
    padding: var(--space-3);
    border-top: 1px solid var(--color-border);
    background: var(--rd-bg-sunken, transparent);
  }

  .allocation-totals {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4);
  }

  .allocation-total {
    display: flex;
    gap: var(--space-2);
  }

  .allocation-total-label {
    color: var(--rd-fg-muted);
    font-size: var(--rd-text-sm);
  }

  .allocation-total-value {
    font-weight: var(--font-semibold);
    font-size: var(--rd-text-sm);
  }

  /* Responsive adjustments — only collapse to a stacked layout for very
     narrow viewports (true mobile). The inline expanded-card panel on the
     work-items page is narrower than a full page but still wide enough to
     hold one row; the 640px collapse used to fire there and pushed the
     delete button onto its own line. */
  @media (max-width: 460px) {
    .allocation-row-fields {
      flex-wrap: wrap;
    }

    .allocation-row-cost-center {
      flex: 1 1 100%;
    }

    .allocation-totals {
      flex-direction: column;
      gap: var(--space-2);
    }
  }

  /* Inline calculator feedback — softer than the full rd-callout chrome
     so it slots into the financials panel without dominating it. */
  .allocation-calculator-messages.hidden { display: none; }

  .allocation-calculator-messages .rd-callout {
    padding: var(--space-2) var(--space-3);
    border-width: 1px;
    box-shadow: none;
    font-size: var(--rd-text-sm);
  }

  .allocation-calculator-messages-lead {
    margin: 0 0 var(--space-2);
    font-size: var(--rd-text-sm);
  }

  .allocation-calculator-messages-label {
    margin-bottom: var(--space-1, 0.25rem);
    font-size: var(--rd-text-2xs, 0.75rem);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.8;
  }

  .allocation-calculator-messages-list {
    /* reset.css strips list-style globally; restore the bullets */
    list-style: disc outside;
    margin: 0;
    padding-left: var(--space-4);
    line-height: var(--leading-normal, 1.45);
  }

  .allocation-calculator-messages-list li + li { margin-top: 4px; }
}

@layer components {
  /* Percentage fields: hide the native number-input spinners */
  .allocation-row-percentage input[data-percentage-input]::-webkit-outer-spin-button,
  .allocation-row-percentage input[data-percentage-input]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }

  .allocation-row-percentage input[data-percentage-input] {
    -moz-appearance: textfield;
    appearance: textfield;
  }
}
