/*
 * Sidebar. Sticky right column of .arbo-content (see style.css). Site differences via tokens: --wp--custom--sidebar--*
 */

/*
 * Per-level colours (level 1 = thema/overview, 2 = risicogroep, 3 = maatregel).
 * Optional tokens settings.custom.sidebar.level{N}.*; anything not set falls
 * back to the regular sidebar token.
 */
.arbo-sidebar {
  --sb-background: var(--wp--custom--sidebar--background);
  --sb-text: var(--wp--custom--sidebar--text);
  --sb-heading: var(--wp--custom--sidebar--heading);
  --sb-icon: var(--wp--custom--sidebar--icon);
  --sb-arrow: var(--wp--custom--sidebar--arrow);
  --sb-tag-background: var(--wp--custom--sidebar--tag-background);
  --sb-tag-text: var(--wp--custom--sidebar--tag-text);
}
.arbo-sidebar--level-2 {
  --sb-background: var(--wp--custom--sidebar--level-2--background, var(--wp--custom--sidebar--background));
  --sb-text: var(--wp--custom--sidebar--level-2--text, var(--wp--custom--sidebar--text));
  --sb-heading: var(--wp--custom--sidebar--level-2--heading, var(--wp--custom--sidebar--heading));
  --sb-icon: var(--wp--custom--sidebar--level-2--icon, var(--wp--custom--sidebar--icon));
  --sb-arrow: var(--wp--custom--sidebar--level-2--arrow, var(--wp--custom--sidebar--arrow));
  --sb-tag-background: var(--wp--custom--sidebar--level-2--tag-background, var(--wp--custom--sidebar--tag-background));
  --sb-tag-text: var(--wp--custom--sidebar--level-2--tag-text, var(--wp--custom--sidebar--tag-text));
}
.arbo-sidebar--level-3 {
  --sb-background: var(--wp--custom--sidebar--level-3--background, var(--wp--custom--sidebar--background));
  --sb-text: var(--wp--custom--sidebar--level-3--text, var(--wp--custom--sidebar--text));
  --sb-heading: var(--wp--custom--sidebar--level-3--heading, var(--wp--custom--sidebar--heading));
  --sb-icon: var(--wp--custom--sidebar--level-3--icon, var(--wp--custom--sidebar--icon));
  --sb-arrow: var(--wp--custom--sidebar--level-3--arrow, var(--wp--custom--sidebar--arrow));
  --sb-tag-background: var(--wp--custom--sidebar--level-3--tag-background, var(--wp--custom--sidebar--tag-background));
  --sb-tag-text: var(--wp--custom--sidebar--level-3--tag-text, var(--wp--custom--sidebar--tag-text));
}

.arbo-sidebar {
  --sidebar-pad: 2rem;
  /* Sticks below the sticky header + breadcrumbs (live heights from header.js). */
  --sidebar-top: calc(
    var(--wp-admin--admin-bar--height, 0px) + var(--arbo-header-sticky-offset, 0px) +
      var(--arbo-breadcrumbs-height, 0px) + 1.5rem
  );

  position: sticky;
  top: var(--sidebar-top);
  z-index: 2; /* above the hero when pulled up into it */
  max-height: calc(100vh - var(--sidebar-top) - 1.5rem);
  overflow-y: auto; /* taller than the screen: scrolls on its own */
  overscroll-behavior: contain;
  scrollbar-width: thin;
  margin: 0;
  padding: var(--sidebar-pad);
  border-radius: var(--wp--custom--sidebar--radius);
  background: var(--sb-background);
  color: var(--sb-text);
  box-shadow: var(--wp--custom--sidebar--shadow);
  font-size: var(--wp--preset--font-size--normal);

  & .arbo-link-list {
    --arrow: var(--sb-arrow);
    gap: 0.75rem;
  }
}

/* Pulled up into the hero (token sidebar.overlap = distance from the top of
   the content area). Needs the extra specificity: core's flow layout resets
   the first child's top margin with `:root :where(.is-layout-flow) > :first-child`
   (0,2,0), which loads later. */
.arbo-content > .arbo-sidebar.wp-block-arbo-sidebar {
  margin-block-start: calc(-1 * var(--wp--custom--sidebar--overlap));
}

/* ---------- Actions ---------- */

.arbo-sidebar__actions {
  display: flex;
  justify-content: space-around;
  gap: 0.5rem;
  margin-block-end: 2rem;
}

.arbo-sidebar__action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  border: 0;
  border-radius: var(--wp--custom--radius--small);
  background: none;
  color: inherit;
  font: inherit;
  font-size: var(--wp--preset--font-size--small);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease;

  & .arbo-sidebar__icon {
    color: var(--sb-icon);
  }
  &:hover {
    transform: translateY(-2px);
  }
  &:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
  }
}

/* ---------- Sections ---------- */

.arbo-sidebar__section + .arbo-sidebar__section {
  margin-block-start: 1.75rem;
}

.arbo-sidebar__heading {
  margin: 0 0 0.85rem;
  color: var(--sb-heading);
  font-size: var(--wp--preset--font-size--normal-medium);
  font-weight: 700;
}

/* Metadata as tags (werkzaamheden, vorm van …, type) */
.arbo-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;

  & a,
  & span {
    display: inline-block;
    padding: 0.35em 0.8em;
    border-radius: var(--wp--custom--radius--small);
    background: var(--sb-tag-background);
    color: var(--sb-tag-text);
    font-size: var(--wp--preset--font-size--small);
    font-weight: 700;
    text-decoration: none;
  }
  & a:hover,
  & a:focus-visible {
    filter: brightness(1.08);
    text-decoration: underline;
  }

  /* Not a link (e.g. type oplossing): an indication, not a button. */
  & span {
    padding: calc(0.35em - 1px) calc(0.8em - 1px);
    border: 1px solid color-mix(in srgb, currentColor 45%, transparent);
    background: transparent;
    color: inherit;
    font-weight: 400;
    cursor: default;
  }
}

/* Current page in a list (siblings) */
.arbo-sidebar .arbo-link-list .is-current > a {
  font-weight: 700;
}

/* Bijlagen ↓ */
.arbo-download-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;

  & a {
    position: relative;
    display: block;
    padding-inline-start: 1.5rem;
    color: inherit;
    text-decoration: none;
  }
  & a::before {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    top: 0.2em;
    width: 1rem;
    height: 1rem;
    background: var(--sb-arrow);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2v11M3 8l5 5 5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  & a:hover .arbo-download-list__title,
  & a:focus-visible .arbo-download-list__title {
    text-decoration: underline;
  }
}
.arbo-download-list__meta {
  display: block;
  font-size: var(--wp--preset--font-size--small);
  opacity: 0.75;
}

/* Back link ← */
.arbo-sidebar__back {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-block-start: 2.25rem;
  color: inherit;
  font-size: var(--wp--preset--font-size--small);
  text-decoration: none;

  &::before {
    content: '';
    width: 1rem;
    height: 1rem;
    background: var(--sb-arrow);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 8H2M7 3 2 8l5 5'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  &:hover {
    text-decoration: underline;
  }
}

/* ---------- Selection dialog ---------- */

.arbo-select-dialog {
  width: min(36rem, 100% - 2rem);
  max-height: min(42rem, 100% - 2rem);
  padding: 0;
  border: 0;
  border-radius: var(--wp--custom--radius--medium);
  background: var(--wp--preset--color--white);
  color: var(--wp--preset--color--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);

  &::backdrop {
    background: rgb(0 0 0 / 0.45);
  }
  &[open] {
    animation: arbo-dialog-in 0.2s ease-out;
  }
}
@keyframes arbo-dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
}
@media (prefers-reduced-motion: reduce) {
  .arbo-select-dialog[open] { animation: none; }
}

.arbo-select-dialog__form {
  display: flex;
  flex-direction: column;
  max-height: inherit;
}

.arbo-select-dialog__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 1.5rem 1rem;

  & h2 {
    margin: 0;
    font-size: var(--wp--preset--font-size--medium);
  }
}
.arbo-select-dialog__close {
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 50%;
  background: var(--wp--preset--color--background-medium);
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.arbo-select-dialog__body {
  overflow-y: auto;
  padding: 0 1.5rem 1rem;

  & fieldset {
    margin: 1.25rem 0 0;
    padding: 0;
    border: 0;
  }
  & legend {
    margin-bottom: 0.4rem;
    font-weight: 700;
  }
  & label {
    display: flex;
    align-items: start;
    gap: 0.6rem;
    padding: 0.3rem 0;
    cursor: pointer;
  }
  & input[type='checkbox'] {
    flex: none;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0.2rem 0 0;
    accent-color: var(--wp--preset--color--accent);
  }
}
.arbo-select-dialog__all {
  padding-bottom: 0.75rem !important;
  border-bottom: 1px solid var(--wp--preset--color--background-medium);
  font-weight: 700;
}

.arbo-select-dialog__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem 1.5rem;
  border-top: 1px solid var(--wp--preset--color--background-medium);

  & .wp-element-button {
    border: 2px solid var(--wp--preset--color--accent);
    cursor: pointer;
  }
  & .wp-element-button:not(.is-primary) {
    background: transparent;
    color: var(--wp--preset--color--accent);
  }
  & .wp-element-button.is-primary {
    order: 1;
  }
  & .wp-element-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }
}
.arbo-select-dialog__count {
  margin: 0 auto 0 0;
  font-size: var(--wp--preset--font-size--small);
}

/* ---------- Small screens: not sticky, above the content ---------- */

@media (max-width: 900px) {
  .arbo-sidebar,
  .arbo-content > .arbo-sidebar.wp-block-arbo-sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    margin: 2.5rem 0 0; /* below the content */
    transform: none !important;
  }
}

/* ---------- Editor preview ---------- */

.arbo-sidebar.is-editor-preview {
  position: static;
  max-height: none;
}
