/* Shared spacing between text and controls (#440). Sizes use rem so they grow with the text-size setting. */

/* Checkboxes and radios keep their own size; the base input rule is meant for text fields. */
input:is([type=checkbox],[type=radio]) { width: 1.25rem; height: 1.25rem; min-width: 1.25rem; min-height: 0; padding: 0; margin: 0; flex: 0 0 auto; vertical-align: middle; accent-color: var(--brand-strong); }
label:has(> input:is([type=checkbox],[type=radio]):first-child) { gap: .5rem; }
label:not(.attribution-choice, .check-field) > input:is([type=checkbox],[type=radio]):first-child:not(:only-child) { margin-inline-end: .5rem; }
:is(.partner-category-row, .attachment-row, .settings-table) label:has(> input[type=checkbox]) { display: inline-flex; align-items: center; }
:is(.partner-category-row, .attachment-row, .settings-table) label > input[type=checkbox] { margin-inline-end: 0; }

/* A label's text sits above its field with a visible gap. */
label:not(:is(.master-form, .master-search, .quote-form, .attachment-picker, .monthly-controls, .personal-signature-dialog) label) > :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]), select, textarea) { margin-top: .375rem; }
.field > span:not(.required) + :is(input, select, textarea) { margin-top: 0; }
.field > span:not(.required) { margin-bottom: .375rem; }
.field > :is(small, .hint, .field-hint) { display: block; margin-top: .375rem; }

/* Headings get room from what comes before them and from the controls under them. */
#app :is(section, form, .card, article, fieldset, nav.account-index, [data-request-settings], [data-personal], [data-catalog], [data-result]) > :not(.eyebrow, .sr-only) + :is(h2, h3, h4) { margin-top: 1.5rem; }
#app :is(h1, h2, h3, h4) + :is(form, fieldset, table, .request-table-wrap, .button-row, .partner-category-row, .request-selector-search) { margin-top: .75rem; }
#app .button-row + :is(h2, h3), #app .button-row + * > :is(h2, h3):first-child { margin-top: 1.25rem; }
#app :is(h1, h2, h3) + p { margin-top: .375rem; }
#app p + :is(form, .button-row, .field, label, fieldset, table) { margin-top: .75rem; }

/* Rows of buttons and the next block never touch. */
#app .button-row + :is(.card, section, form, .field, label, p) { margin-top: 1rem; }
#app :is(form, .card) > :is(.button, .btn, button):not(:first-child) { margin-top: .75rem; }
#app details > summary + * { margin-top: .75rem; }

/* File pickers read as a field: label text above, picker below, then the action. */
#app label:has(> input[type=file]) { display: grid; gap: .5rem; }
#app label > input[type=file] { margin-top: 0; padding: .5rem; min-height: 0; }

/* Tab panels start below the tab bar, not against it. */
#app [role=tablist] + [role=tabpanel], #app .master-tabs + * { padding-top: 1.25rem; }
#app [data-tag-rows] + .field { margin-top: 1.25rem; }
#app .button-row { gap: .5rem; }
#app :is(h2, h3, h4) + :is(.field, label) { margin-top: .75rem; }
#app [data-catalog] + [data-expense-import], #app [data-personal] + .button-row { margin-top: 1.25rem; }
#app :is(.back-button, [data-page-back], .button.secondary) + h1 { margin-top: .75rem; }
#app :is(.page-head, section) > h1 + :is(.button, button) { margin-top: .75rem; }

/* Search rows: on phones a filter dropdown and the status line take their own row, so the search box and button keep their width at any text size. */
.request-selector-search > select, .request-selector-search > [role=status] { grid-column: 1 / -1; }
.request-selector-search > button { white-space: nowrap; }

/* Lists and the controls above them. */
#app .request-toolbar + .request-list-caption { margin-top: .75rem; }
#app .request-list-caption { margin-bottom: .5rem; }
#app details.mfa-reset + * { margin-top: 1rem; }
#app .profile-row + form { margin-top: .75rem; }
#app .field + :is(.button, button) { margin-top: .5rem; }

@media (max-width: 759px) {
  /* A search box keeps the room; its button only takes what its label needs. */
  .button-row:has(> input[type=search]) { grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; }
  /* Paired choices (list switch, previous/next) are equal halves. */
  .button-row:has(> [data-settings-kind], > [data-previous]) { grid-template-columns: 1fr 1fr; }
  /* Tag rows: the name gets a full line, its controls sit underneath. */
  .partner-category-row > b { flex-basis: 100%; }
}
