// Export column picker — the icon button beside "Export CSV" on the
// subscriptions list and the dropdown it opens.

// Room a checkbox focus ring needs outside its own box.
$ring-gutter: 6px;

// "Export CSV" and the picker read as a single segmented control: the toolbar
// gap sits outside the pair, and the shared edge collapses to one border.
// The `.button` in each selector is deliberate — it outweighs WordPress's own
// `.wp-core-ui .button` radius and margin rules.
.arraysubs-export-actions {
  display: inline-flex;
  align-items: center;

  .button.arraysubs-export-actions__csv {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  .button.arraysubs-export-columns__trigger {
    margin-left: -1px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
}

.arraysubs-export-columns {
  position: relative;
  display: inline-flex;

  &__trigger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 34px;
    padding: 0 !important;

    svg {
      display: block;
    }

    // Keep the focused or hovered half on top so its outline is not clipped
    // by the neighbouring button it overlaps.
    &:focus,
    &:hover {
      z-index: 1;
    }
  }

  &__panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1000;
    width: 340px;
    max-width: calc(100vw - 40px);
    padding: 14px;
    border: 1px solid var(--arraysubs-dl-color-border-medium, #c3c4c7);
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(24, 48, 90, 0.16);
    text-align: left;
  }

  &__header {
    margin-bottom: 10px;
  }

  &__title {
    margin: 0;
    color: #1d2327;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
  }

  &__subtitle {
    margin: 4px 0 0;
    color: #646970;
    font-size: 12px;
    line-height: 1.5;
  }

  &__filter {
    width: 100%;
    min-height: 30px;
    // Trimmed by the scroller's own top gutter below, so the visible gap
    // between the search box and the first group stays the same.
    margin-bottom: 10px - $ring-gutter;
    padding: 0 8px;
    border: 1px solid var(--arraysubs-dl-color-border-dark, #8c8f94);
    border-radius: 4px;
    font-size: 13px;

    &:focus {
      outline: none;
      border-color: var(--arraysubs-dl-color-link, #2271b1);
      box-shadow: 0 0 0 1px var(--arraysubs-dl-color-link, #2271b1);
    }
  }

  &__body {
    // Tall enough to reach the shipping group without scrolling on a normal
    // laptop, capped so the panel never runs off a short viewport.
    max-height: min(460px, 52vh);
    // `overflow-y: auto` makes the other axis clip too, which shaved the focus
    // ring off the checkboxes sitting on either edge. Pad the scroller and pull
    // it back out by the same amount, so the ring has room while the columns
    // stay flush with the panel's content edges.
    margin: 0 -#{$ring-gutter};
    padding: $ring-gutter;
    overflow-y: auto;
  }

  &__group + &__group {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f1;
  }

  &__group-head {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;

    input {
      flex: 0 0 auto;
      margin: 0;
    }
  }

  &__group-title {
    // Takes the free space so the count and tick box sit hard right.
    flex: 1 1 auto;
    color: #1d2327;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
  }

  &__group-count {
    flex: 0 0 auto;
    color: #787c82;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
  }

  &__list {
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 10px;
  }

  &__item {
    display: flex;
    align-items: center;
    gap: 6px;
    // Pulled back by its own padding so each tick box lines up with the group
    // title above it, while the hover band keeps its breathing room.
    margin-left: -4px;
    padding: 3px 4px;
    border-radius: 3px;
    color: #2c3338;
    font-size: 12px;
    line-height: 1.4;
    cursor: pointer;

    &:hover {
      background: #f6f7f7;
    }

    input {
      margin: 0;
      flex: 0 0 auto;
    }

    &--locked {
      cursor: not-allowed;
      opacity: 0.7;
    }
  }

  &__status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 12px 0;
    color: #646970;
    font-size: 12px;

    &--error {
      color: var(--arraysubs-dl-color-danger, #d63638);
    }
  }

  &__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    // Trimmed by the scroller's bottom gutter, same as the search box above.
    margin-top: 12px - $ring-gutter;
    padding-top: 10px;
    border-top: 1px solid #f0f0f1;
  }

  &__summary {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #646970;
    font-size: 12px;
  }

  &__actions {
    display: inline-flex;
    align-items: center;
    gap: 12px;

    .button-link {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 0;
      color: var(--arraysubs-dl-color-link, #2271b1);
      font-size: 12px;
      text-decoration: none;

      &:hover:not(:disabled) {
        text-decoration: underline;
      }

      &:disabled {
        color: #a7aaad;
        cursor: not-allowed;
      }
    }
  }
}
