/*
 * The budget page's body (028, FR-050–FR-053): the planned / actual /
 * remaining summary, the planned cost lines grouped by kind, the actual costs
 * under their lines, and the funding totals. The same line rows and dialogs
 * render on the grant page's objective cards. The header and layout live in
 * budget_detail.css / detail.css, dialogs in dialog.css; the add-income card
 * is a .card.card--new inside a .reveal (card.css, reveal.css).
 */
@layer components {
  /* Planned, actual, remaining: three .stat figures in a row at the top. */
  .budget-summary {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-8);
    padding-block: var(--space-4);
    border-block-end: var(--rule);
  }

  .budget-summary__figure {
    display: grid;
    gap: var(--space-1);
    margin: 0;
  }

  /* Over plan (DESIGN.md §2.3): the tint carries it, the figure stays ink. */
  .budget-summary__figure--over .stat__value {
    padding-inline: var(--space-2);
    border-radius: var(--radius-xs);
    background: var(--color-negative-surface);
  }

  .budget-summary__flag {
    font: var(--text-small);
    color: var(--color-muted);
  }

  /* Planned cost lines and actual costs: one table per kind or line. */
  .cost-lines,
  .actual-costs {
    display: grid;
    gap: var(--space-4);
  }

  .cost-lines__heading {
    margin: 0 0 var(--space-2);
    font: var(--text-body-strong);
  }

  .cost-lines__table,
  .actual-costs__table {
    inline-size: 100%;

    & tfoot th,
    & tfoot td {
      font: var(--text-body-strong);
    }
  }

  .cost-lines__add {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .cost-line__name {
    display: block;
    font: var(--text-body-strong);
  }

  .cost-line__meta {
    display: block;
    font: var(--text-small);
    color: var(--color-muted);
  }

  /* Attention role: tinted, never orange text (DESIGN.md §2.3). */
  .cost-line__warning {
    display: inline-block;
    margin-block-start: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-xs);
    background: var(--color-attention-surface);
    font: var(--text-small);
  }

  /* A row's Edit and Delete (planned cost lines, funding, actual costs):
     quiet small buttons side by side, the delete's button_to form inline. */
  .row-actions {
    white-space: nowrap;
    text-align: end;

    & form {
      display: inline;
    }

    & > * + * {
      margin-inline-start: var(--space-1);
    }
  }

  .actual-costs__figures {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    margin: 0 0 var(--space-2);
    font: var(--text-small);
    color: var(--color-muted);
  }

  .actual-costs__remaining--over {
    padding-inline: var(--space-1);
    border-radius: var(--radius-xs);
    background: var(--color-negative-surface);
    color: var(--color-ink);
  }

  /* The line form's layout is the shared .dialog-form (dialog.css); these
     rules only show and hide its parts by kind. Two fields side by side
     (hours and rate, the spread window), each still label above input. */
  .cost-line-form__row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    align-items: start;
    gap: var(--space-3);

    & > button {
      align-self: end;
    }
  }

  /* *Monthly allocation?* shows the months; a category (first optgroup)
     has none, so the choice hides while one is chosen (FR-014). */
  .cost-line-form__months {
    display: none;
  }

  .cost-line-form:has(.cost-line-form__monthly input:checked) .cost-line-form__months {
    display: grid;
    gap: var(--space-3);
  }

  .cost-line-form:has(optgroup:first-of-type option:checked) :is(.cost-line-form__monthly, .cost-line-form__months) {
    display: none;
  }

  /* Hours are asked for only on a staff cost line (FR-043). */
  .actual-cost-form__hours {
    display: none;
  }

  .actual-cost-form:has(option[data-kind="staff_cost"]:checked) .actual-cost-form__hours {
    display: block;
  }

  /* Funded and balance, under the income lines. */
  .budget-funding__totals {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-8);
    margin-block-start: var(--space-4);

    & > * {
      margin: 0;
    }

    & > .budget-totals__meter {
      margin-inline-start: auto;
      align-self: center;
    }
  }

  .budget-totals__meter {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font: var(--text-small);
    color: var(--color-muted);
  }

  /* Attention role (DESIGN.md §2.3): the tint carries it, never orange text --
     same treatment as .budget-row__over-funded on the list. */
  .budget-totals__over-funded {
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-xs);
    background: var(--color-attention-surface);
    color: var(--color-ink);
    font-weight: 500;
  }

  /* A grant's restriction (028, FR-030): the amount requested only while
     Unrestricted is chosen. */
  .grant-restriction__amount {
    display: none;
  }

  .grant-restriction:has(input[value="unrestricted"]:checked) .grant-restriction__amount {
    display: block;
  }
}
