// Activity Audits Page
.arraysubs-audit-filters {
  margin-bottom: 16px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid #ccd0d4;
  border-radius: 4px;

  &__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;

    // inline-flex centers the inline SVG with the label inside the buttons
    // used here (button-small with leading icon). The icon previously sat
    // slightly above the text because the buttons fell back to inline-block.
    button,
    .arraysubs-audit-filters__logging-link {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 4px;
      line-height: 1 !important;
      min-height: 30px !important;
    }

    .arraysubs-audit-filters__logging-link {
      white-space: nowrap;
    }

    // Pin native selects/date inputs to the 30px button height. WP 7.0
    // raised the select / input[type] default min-height to 40px, which
    // makes them tower over the buttons in this filter row.
    select,
    input[type="date"] {
      min-height: 30px;
      line-height: 1.5;
    }
  }

  &__select {
    min-width: 140px;
    max-width: 180px;
    padding: 0 24px 0 8px;
  }

  &__date {
    max-width: 150px;
    padding: 0 8px;
  }

  &__search {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 160px;
    max-width: 280px;
    padding: 0 8px;
    border: 1px solid #8c8f94;
    border-radius: 4px;
    background: #fff;
    min-height: 30px;
    box-sizing: border-box;

    svg {
      color: #8c8f94;
      flex-shrink: 0;
    }

    // The inner input is borderless inside the wrapper; let the wrapper own
    // the row height so WP 7.0's 40px input default does not push this group
    // taller than the surrounding 30px buttons/selects.
    input[type="text"] {
      flex: 1;
      border: none;
      outline: none;
      padding: 0;
      background: transparent;
      font-size: 13px;
      line-height: 1.5;
      min-height: 0;
      height: auto;
    }
  }
}

.arraysubs-audit-table-wrap {
  background: #fff;
  border: 1px solid #ccd0d4;
  border-radius: 4px;
  overflow-x: auto;

  table {
    border: 0 !important;
  }
}

.arraysubs-loading {
  padding: 5px;
}
// Drop the inherited `.wp-list-table.fixed` table-layout so the Activity
// column can size to its content instead of equal-dividing every column
// and word-breaking the sentence text mid-token ("Cancelle\nd.").
.arraysubs-audit-table-wrap .arraysubs-audit-table {
  margin: 0;
  table-layout: auto;
}

.arraysubs-audit-table {
  &__col--date {
    width: 160px;
    white-space: nowrap;
  }

  &__col--meta {
    width: 170px;
  }

  &__col--sub {
    width: 260px;
  }

  &__col--desc {
    min-width: 320px;
    width: auto;
    word-break: normal;
    overflow-wrap: anywhere;
  }
}

// Stack the badges that used to be Author/Type/Visibility columns into
// a single Meta cell. Vertical layout keeps each badge readable in the
// narrower combined column.
.arraysubs-audit-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.arraysubs-audit-activity {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;

  &__content {
    flex: 1;
    min-width: 0;
  }

  &__changes-button.button.button-small {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    min-height: 22px;
    padding: 0 6px;
    color: var(--wp-admin-theme-color);
    border-color: var(--wp-admin-theme-color);
    background: transparent;
    font-size: 11px;
    font-weight: 500;
    line-height: 20px;
    white-space: nowrap;

    &:hover {
      color: var(--wp-admin-theme-color-darker-10);
      border-color: var(--wp-admin-theme-color-darker-10);
      background: color-mix(in srgb, var(--wp-admin-theme-color) 6%, transparent);
    }

    &:focus-visible {
      box-shadow: 0 0 0 1px var(--wp-admin-theme-color);
    }
  }
}

// Author badges
.arraysubs-audit-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;

  &--system {
    background: #f0f0f1;
    color: #50575e;
  }

  &--admin {
    background: color-mix(in srgb, var(--wp-admin-theme-color) 6%, transparent);
    color: var(--wp-admin-theme-color-darker-20);
  }

  &--customer {
    background: #edf8ee;
    color: #1e4620;
  }

  &--gateway {
    background: #fef8ee;
    color: #6e3b00;
  }
}

// Entity badges
.arraysubs-audit-entity {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;

  &--subscription {
    background: color-mix(in srgb, var(--wp-admin-theme-color) 6%, transparent);
    color: var(--wp-admin-theme-color-darker-20);
  }

  &--product {
    background: #f3e8ff;
    color: #5b21b6;
  }

  &--member {
    background: #ecfdf3;
    color: #166534;
  }

  &--order {
    background: #fef2f2;
    color: #9f1239;
  }

  &--payment {
    background: #edf8ee;
    color: #1e4620;
  }

  &--renewal {
    background: #fef8ee;
    color: #6e3b00;
  }

  &--cancellation {
    background: #fde8e8;
    color: #991b1b;
  }

  &--other {
    background: #f0f0f1;
    color: #50575e;
  }

  &--coupon {
    background: #fef3c7;
    color: #92400e;
  }

  &--email {
    background: #ede9fe;
    color: #5b21b6;
  }

  &--settings {
    background: color-mix(in srgb, var(--wp-admin-theme-color) 6%, transparent);
    color: var(--wp-admin-theme-color);
  }
}

.arraysubs-audit-sub-link {
  font-weight: 500;
  text-decoration: none;
  color: var(--wp-admin-theme-color);

  &:hover {
    color: var(--wp-admin-theme-color-darker-10);
  }
}

.arraysubs-audit-ref-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.arraysubs-audit-ref-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid #dcdcde;
  border-radius: 999px;
  background: #f6f7f7;
  color: #1d2327;
  font-size: 12px;
  line-height: 1.3;
  text-decoration: none;
}

.arraysubs-audit-changes-modal {
  &__summary {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid #dcdcde;
    border-radius: 6px;
    background: #f6f7f7;
    color: #1d2327;
    line-height: 1.5;
  }

  &__table-wrap {
    overflow-x: auto;
  }
}

.arraysubs-audit-changes-table {
  width: 100%;
  border-collapse: collapse;

  th,
  td {
    padding: 12px;
    border: 1px solid #dcdcde;
    text-align: left;
    vertical-align: top;
  }

  th {
    background: #f6f7f7;
    font-weight: 600;
  }

  td:first-child {
    width: 28%;
    font-weight: 600;
  }

  td:nth-child(2),
  td:nth-child(3) {
    width: 36%;
    white-space: pre-wrap;
    word-break: break-word;
  }
}

// Visibility badges
.arraysubs-audit-visibility {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;

  &--private {
    background: #f5f0ff;
    color: #6b21a8;
  }

  &--customer {
    background: #edf8ee;
    color: #1e4620;
  }
}

// Pagination
.arraysubs-audit-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  padding: 12px;

  &__info {
    font-size: 13px;
    color: #50575e;
  }

  &__total {
    margin-left: 4px;
    color: #8c8f94;
  }

  .button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }
}

// Logging Settings Popover
.arraysubs-audit-logging-settings {
  position: relative;

  &__popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 100;
    width: 320px;
    background: #fff;
    border: 1px solid #ccd0d4;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  }

  &__header {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f1;
    font-size: 13px;
  }

  &__loading {
    padding: 16px;
    margin: 0;
    color: #646970;
    font-size: 13px;
    text-align: center;
  }

  &__list {
    margin: 0;
    padding: 4px 0;
    list-style: none;
  }

  &__item {
    margin: 0;
    padding: 0;
    border-bottom: 1px solid #f0f0f1;

    &:last-child {
      border-bottom: none;
    }
  }

  &__label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;

    &:hover {
      background: #f6f7f7;
    }
  }

  &__info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
  }

  &__name {
    font-size: 13px;
    font-weight: 600;
    color: #1d2327;
  }

  &__help {
    font-size: 12px;
    color: #646970;
    line-height: 1.4;
  }

  &__toggle {
    flex-shrink: 0;
  }

  &__always-on {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin: 0;
    padding: 12px 16px;
    border-top: 1px solid #f0f0f1;
    background: #f6f7f7;
    color: #50575e;
    font-size: 12px;
    line-height: 1.4;

    svg {
      flex-shrink: 0;
      margin-top: 1px;
      color: var(--wp-admin-theme-color);
    }
  }
}

// Pro-only message
.arraysubs-pro-only-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;

  &__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    border-radius: 50%;
    background: #f0f0f1;
    color: #8c8f94;
  }

  &__title {
    margin: 0 0 12px;
    font-size: 22px;
    font-weight: 600;
    color: #1d2327;
  }

  &__description {
    max-width: 460px;
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    color: #646970;
  }
}

// Spin animation (shared)
.arraysubs-spin {
  animation: arraysubs-spin 1s linear infinite;
}

@keyframes arraysubs-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

// Scheduled-Job Logs
.arraysubs-job-filter-label {
  font-size: 13px;
  font-weight: 500;
  color: #50575e;
}

.arraysubs-job-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  // Long failure labels ("insufficient funds on the card") used to spill
  // out of the cell because of `white-space: nowrap`. Keep the icon and
  // the first run of text on one line via flex but let the label wrap if
  // the column is narrower than the badge.
  max-width: 100%;

  & > span {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  &--http {
    white-space: nowrap;

    > svg {
      flex-shrink: 0;
    }

    > span {
      overflow-wrap: normal;
      word-break: normal;
    }
  }

  &--success {
    background: #edf8ee;
    color: #1e4620;
  }

  &--failed {
    background: #fde8e8;
    color: #991b1b;
  }

  &--skipped {
    background: #f0f0f1;
    color: #50575e;
  }
}

.arraysubs-job-table {
  &__col--status {
    width: 100px;
  }

  &__col--hook {
    width: 200px;
  }

  &__col--detail {
    min-width: 240px;
    line-height: 1.5;
  }
}

.arraysubs-job-hook-label {
  display: block;
  font-weight: 500;
  color: #1d2327;
}

.arraysubs-job-sub-link {
  display: inline-block;
  margin-top: 2px;
  font-size: 12px;
}

.arraysubs-job-row--failed {
  background-color: #fef2f2 !important;
}

// Drop the inherited `.wp-list-table.fixed` table-layout so the Failure
// column can size to its content instead of overflowing into Failed.
.arraysubs-audit-table-wrap .arraysubs-renewal-failures-table {
  table-layout: auto;
}

.arraysubs-renewal-failures-table {
  th,
  td {
    vertical-align: top;
    overflow-wrap: anywhere;
  }

  &__meta,
  &__reason {
    display: block;
    margin-top: 4px;
    color: #646970;
    font-size: 12px;
    line-height: 1.4;
  }

  &__reason {
    max-width: 260px;
  }

  &__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;

    .button {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      min-height: 30px;
      white-space: nowrap;
    }
  }
}

.arraysubs-portal-failures-table__col--http {
  width: 72px;
  white-space: nowrap;
}

.arraysubs-portal-failure-details {
  dl {
    display: grid;
    grid-template-columns: minmax(120px, 180px) minmax(0, 1fr);
    gap: 12px 16px;
    margin: 0;
  }

  dt {
    color: #646970;
    font-weight: 600;
  }

  dd {
    margin: 0;
    min-width: 0;
  }

  pre {
    overflow: auto;
    max-height: 260px;
    margin: 0;
    padding: 12px;
    border: 1px solid #dcdcde;
    border-radius: 4px;
    background: #f6f7f7;
    white-space: pre-wrap;
  }
}

// Responsive
@media (max-width: 782px) {
  .arraysubs-audit-filters__row {
    flex-direction: column;
    align-items: stretch;
  }

  .arraysubs-audit-filters__select,
  .arraysubs-audit-filters__date,
  .arraysubs-audit-filters__search {
    max-width: 100%;
  }

  .arraysubs-job-table__col--hook {
    width: auto;
    min-width: 140px;
  }

  .arraysubs-portal-failure-details dl {
    grid-template-columns: 1fr;
  }
}

// Shown in place of a page whose module is switched off.
.arraysubs-module-disabled-message__action {
  margin-top: 20px !important;
}

.arraysubs-logging-settings {
  .arraysubs-settings-left-grid {
    width: 100%;
  }

  .arraysubs-fb-alert-wrapper {
    grid-template-columns: minmax(0, 1fr);
  }
}
