/* One field rhythm for every form in a dialog: label, field, optional memo,
   then a clearly larger space before the next label.

   A label belongs to the field beneath it, so it sits close to that field
   (--fld-label-gap) and far from the field above (--fld-group-gap). A memo
   (a short note about the field, smaller and fainter) hugs the field it
   describes (--fld-memo-gap). The two gaps must never look alike: the
   group gap is several times the label gap.

   Earlier files tuned label margins and container gaps form by form, and
   grid gaps added to label margins on both sides, so labels drifted to an
   equal distance between two fields. This file is last in the cascade and
   is the single source of field spacing: the flow containers below drop
   their row gap and every direct child is spaced by these rules alone.
   The !important flags only touch vertical margins and row gaps, which the
   older per-form rules (some with two ids) would otherwise keep winning. */
:root {
  --fld-label-gap: 0.4rem;
  --fld-memo-gap: 0.3rem;
  --fld-group-gap: 1.5rem;
}

/* Flow containers: forms in dialogs, their field rows and wrappers, the
   Lightning channel panel, the small dialog bodies and the Settings
   panels with their credential cards. */
dialog form,
dialog form [id$="-row"],
dialog form [id$="-wrap"],
dialog form details.adv,
dialog form details.adv > div,
.ln-panel,
.ln-panel [data-ln-for],
.ln-panel [data-ln-ids],
.ln-field,
:is(#account-dialog-body, #ledger-dialog-body, #group-dialog-body) > div,
#account-dialog-body [id$="-row"],
.set-panels section,
.set-panels section :is([id^="sy-g-"], [id^="pd-g-"], #set-date-format-custom, details.adv, .sync-field-group, .sync-feature-group, .sync-feature-settings) {
  row-gap: 0 !important;
}

:is(
  dialog form, dialog form [id$="-row"], dialog form [id$="-wrap"], dialog form details.adv, dialog form details.adv > div,
  .ln-panel, .ln-panel [data-ln-for], .ln-panel [data-ln-ids], .ln-field,
  :is(#account-dialog-body, #ledger-dialog-body, #group-dialog-body) > div, #account-dialog-body [id$="-row"],
  .set-panels section,
  .set-panels section :is([id^="sy-g-"], [id^="pd-g-"], #set-date-format-custom, details.adv, .sync-field-group, .sync-feature-group, .sync-feature-settings)
) > * {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Every block after the first starts a new field: the large gap. */
:is(
  dialog form, dialog form [id$="-row"], dialog form [id$="-wrap"], dialog form details.adv, dialog form details.adv > div,
  .ln-panel, .ln-panel [data-ln-for], .ln-panel [data-ln-ids], .ln-field,
  :is(#account-dialog-body, #ledger-dialog-body, #group-dialog-body) > div, #account-dialog-body [id$="-row"],
  .set-panels section,
  .set-panels section :is([id^="sy-g-"], [id^="pd-g-"], #set-date-format-custom, details.adv, .sync-field-group, .sync-feature-group, .sync-feature-settings)
) > * + * {
  margin-top: var(--fld-group-gap) !important;
}

/* A container whose first children are hidden starts flush with its first
   visible child, so nested rows never stack two group gaps. */
:is(
  dialog form, dialog form [id$="-row"], dialog form [id$="-wrap"], dialog form details.adv > div,
  .ln-panel, .ln-panel [data-ln-for], .ln-panel [data-ln-ids], .ln-field,
  :is(#account-dialog-body, #ledger-dialog-body, #group-dialog-body) > div, #account-dialog-body [id$="-row"],
  .set-panels section :is([id^="sy-g-"], [id^="pd-g-"], #set-date-format-custom, .sync-field-group, .sync-feature-settings)
) > :is([hidden]:first-child + *, [hidden]:first-child + [hidden] + *) {
  margin-top: 0 !important;
}

/* The field right after its label: the small gap. Labels that wrap their
   own control (checkbox rows) are fields themselves, not labels. */
:is(
  dialog form, dialog form [id$="-row"], dialog form [id$="-wrap"], dialog form details.adv, dialog form details.adv > div,
  .ln-panel, .ln-panel [data-ln-for], .ln-panel [data-ln-ids], .ln-field,
  :is(#account-dialog-body, #ledger-dialog-body, #group-dialog-body) > div, #account-dialog-body [id$="-row"],
  .set-panels section,
  .set-panels section :is([id^="sy-g-"], [id^="pd-g-"], #set-date-format-custom, details.adv, .sync-field-group, .sync-feature-group, .sync-feature-settings)
) > :is(label:not(.sync-check), .fld-label, #s-upload-label, #sy-enc-upload-label, #s-enc-label) + * {
  margin-top: var(--fld-label-gap) !important;
}

/* A remember toggle belongs to the secret above it. */
.set-panels :is(.sync-field-group, .sync-feature-settings) > :is(input, select) + label.sync-check {
  margin-top: var(--fld-memo-gap) !important;
}

/* Field memos: under their field, smaller and fainter than the label. */
.fld-hint,
.fld-memo,
#set-date-format-preview,
#sy-fp,
#t-attach-cur {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
  opacity: 0.75;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}
:is(
  dialog form, dialog form [id$="-row"], dialog form [id$="-wrap"], dialog form details.adv, dialog form details.adv > div,
  .ln-panel, .ln-panel [data-ln-for], .ln-panel [data-ln-ids], .ln-field,
  :is(#account-dialog-body, #ledger-dialog-body, #group-dialog-body) > div, #account-dialog-body [id$="-row"],
  .set-panels section,
  .set-panels section :is([id^="sy-g-"], [id^="pd-g-"], #set-date-format-custom, details.adv, .sync-field-group, .sync-feature-group, .sync-feature-settings)
) > * + :is(.fld-hint, .fld-memo, #set-date-format-preview, #sy-fp, #t-attach-cur) {
  margin-top: var(--fld-memo-gap) !important;
}

/* The first field of a dialog starts right under the dialog title. */
:is(dialog form, :is(#account-dialog-body, #ledger-dialog-body, #group-dialog-body) > div) > :first-child {
  margin-top: 0 !important;
}

/* A textarea sitting on the text baseline leaves a descender strip below
   it; top alignment keeps the gap to the next label the same as inputs. */
dialog textarea {
  vertical-align: top;
}

/* Grids of wrapping labels (transfer sources and recipients): the label's
   own gap is the label gap, the grid's row gap is the field gap. */
.src-grid,
.rec-grid {
  row-gap: var(--fld-group-gap);
}
/* The Auto fee row exists only when shown, so a hidden one leaves no gap. */
.src-grid {
  grid-template-rows: none;
}
.src-grid label,
.rec-grid label {
  gap: var(--fld-label-gap);
  margin: 0;
}

/* Group labels (Spend from, Recipients) are field labels too: same face. */
.fld-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
@media (max-width: 720px) {
  .fld-label { font-size: 0.78rem; }
}

/* Recipients: the group label hugs its list like any other label. */
#t-recipients {
  row-gap: var(--fld-label-gap);
}
#t-recipients > .fld-label {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Buttons that belong to a field's list (add a recipient, add a source,
   split evenly) hug that list like a memo; action buttons (Save, Connect,
   the dialog's submit) are separate steps and keep the field gap. An empty
   list takes no room, so "+ Add recipient" sits right under its label. */
#t-rec-list:empty {
  display: none;
}
#t-source-list > .src-row:first-child {
  margin-top: 0;
}
#t-source-list > .src-row:last-child {
  margin-bottom: 0;
}
#t-sources-row > :is(#t-source-add, #t-source-split) {
  margin-top: var(--fld-label-gap) !important;
}
