/**
 * Vertical rhythm - spacing within sections (theme_settings.vertical_rhythm).
 *
 * Headings: no top margin, tight margin below from --rhythm-h*-after.
 * Copy/lists: --rhythm-copy-after. Media: --rhythm-media-after.
 * Intro to content: --rhythm-block-gap.
 * Off per section: data-site-rhythm="off" on <section>.
 */

/* Headings: no margin above, tight and theme-controlled margin below */
:where(main, body) section:not([data-site-rhythm="off"]) h1 {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-h1-after, var(--rhythm-heading-after, var(--rhythm-copy-after)));
}

:where(main, body) section:not([data-site-rhythm="off"]) h2 {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-h2-after, var(--rhythm-heading-after, var(--rhythm-copy-after)));
}

:where(main, body) section:not([data-site-rhythm="off"]) h3 {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-h3-after, var(--rhythm-heading-after, var(--rhythm-copy-after)));
}

:where(main, body) section:not([data-site-rhythm="off"]) h4 {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-h4-after, var(--rhythm-heading-after, var(--rhythm-copy-after)));
}

:where(main, body) section:not([data-site-rhythm="off"]) h5 {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-h5-after, var(--rhythm-heading-after, var(--rhythm-copy-after)));
}

:where(main, body) section:not([data-site-rhythm="off"]) h6 {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-h6-after, var(--rhythm-heading-after, var(--rhythm-copy-after)));
}

:where(main, body) section:not([data-site-rhythm="off"]) p {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-copy-after);
}

/* Media */
:where(main, body) section:not([data-site-rhythm="off"]) :is(img, picture, video, figure) {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-media-after);
}

/* Listor */
:where(main, body) section:not([data-site-rhythm="off"]) :is(ul, ol) {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-copy-after);
}

/* Intro-block → huvudinnehåll */
:where(main, body) section:not([data-site-rhythm="off"]) :is(header, [class$="__header"], [class$="__head"], [class$="__intro"]) {
  margin-block-start: 0;
  margin-block-end: var(--rhythm-block-gap);
}

/* Sista barnet: ingen extra margin i botten */
:where(main, body) section:not([data-site-rhythm="off"]) :is(h1, h2, h3, h4, h5, h6, p, ul, ol, img, picture, video, figure):last-child {
  margin-block-end: 0;
}

.site-header :is(h1, h2, h3, h4, h5, h6, p),
.site-footer :is(h1, h2, h3, h4, h5, h6, p) {
  margin-block: 0;
}

/**
 * Knapprader (*__actions): luft ovanför (även nästlade section — inte bara main > section).
 * Sista stycke/lista före raden: ingen dubbel margin-bottom.
 */
:where(main, body) section:not([data-site-rhythm="off"]) [class$="__actions"] {
  margin-top: var(--rhythm-actions-before);
}

:where(main, body) section:not([data-site-rhythm="off"]) p:has(+ [class$="__actions"]) {
  margin-block-end: 0;
}

:where(main, body)
  section:not([data-site-rhythm="off"])
  [class$="__text"]:has(+ [class$="__actions"])
  > :is(p, ul, ol):last-child {
  margin-block-end: 0;
}
