/**
 * Modules Page Styles
 *
 * One grid of module cards. Each card has a body (icon, title, badge, info
 * link, description) and a footer band holding the switch — or "Always on",
 * or why the module is unavailable — and the Configure link.
 *
 * @package ArraySubs
 */

.arraysubs-top-header__aside:has(.arraysubs-modules__controls) {
  flex: 0 1 400px;
  margin-inline-start: auto;

  @media (max-width: 782px) {
    flex-basis: 100%;
  }
}

.arraysubs-modules {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;

  @media (max-width: 1200px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  @media (max-width: 782px) {
    grid-template-columns: minmax(0, 1fr);
  }

  &__controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
  }

  &__search {
    position: relative;
    display: flex;
    flex: 1 1 260px;
    align-items: center;
    min-width: 0;
    max-width: 100%;

    > svg {
      position: absolute;
      inset-inline-start: 12px;
      color: #646970;
      pointer-events: none;
    }

    input[type="search"] {
      box-sizing: border-box;
      width: 100%;
      min-width: 0;
      min-height: 40px;
      margin: 0;
      padding: 6px 38px;
      border: 1px solid #8c8f94;
      border-radius: 4px;
      background: #fff;
      color: #1d2327;
      font-size: 14px;

      &:focus {
        border-color: var(--wp-admin-theme-color);
        box-shadow: 0 0 0 1px var(--wp-admin-theme-color);
        outline: 2px solid transparent;
      }

      &::-webkit-search-cancel-button {
        appearance: none;
      }

      @media (max-width: 782px) {
        min-height: 44px;
        font-size: 16px;
      }
    }
  }

  &__clear-search {
    position: absolute;
    inset-inline-end: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: #646970;
    cursor: pointer;

    &:hover {
      background: #f0f0f1;
      color: var(--wp-admin-theme-color);
    }

    &:focus-visible {
      outline: 2px solid var(--wp-admin-theme-color);
    }
  }

  &__bulk-action {
    flex: 0 0 auto;
  }

  &__empty {
    padding: 24px;
    border: 1px solid #c3c4c7;
    border-radius: 6px;
    background: #fff;
    text-align: center;

    p {
      margin: 0 0 12px;
      color: #646970;
    }
  }
}

.arraysubs-module-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #dcdcde;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: border-color $transition-fast;

  &.is-on {
    border-color: color-mix(in srgb, var(--wp-admin-theme-color) 40%, #dcdcde);
  }

  // Grows so the footers line up across a grid row.
  &__body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
  }

  &__header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
  }

  &__icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--wp-admin-theme-color) 10%, #fff);
    color: var(--wp-admin-theme-color);
    transition:
      background-color $transition-fast,
      color $transition-fast;

    img {
      display: block;
      width: 24px;
      height: 24px;
      object-fit: contain;
    }
  }

  &.is-off &__icon,
  &.is-locked &__icon {
    background: #f0f0f1;
    color: #646970;
  }

  &__heading {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    min-width: 0;
    min-height: 40px;

    h3 {
      margin: 0;
      color: #1d2327;
      font-size: 15px;
      font-weight: 600;
      line-height: 1.4;
      overflow-wrap: anywhere;
    }
  }

  &__docs {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin: 6px -6px 0 0;
    border-radius: 50%;
    color: var(--wp-admin-theme-color);
    transition:
      background-color $transition-fast,
      color $transition-fast;

    &:hover,
    &:focus {
      background: color-mix(in srgb, var(--wp-admin-theme-color) 10%, #fff);
      color: var(--wp-admin-theme-color-darker-10);
    }

    &:focus {
      outline: 2px solid transparent;
      box-shadow: 0 0 0 2px var(--wp-admin-theme-color);
    }
  }

  &__description {
    margin: 0;
    color: #50575e;
    font-size: 13px;
    line-height: 1.6;
  }

  &__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-sizing: border-box;
    min-height: 56px;
    padding: 12px 20px;
    border-top: 1px solid #f0f0f1;
    background: #f6f7f7;
  }

  &__status {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    color: #646970;
    font-size: 13px;

    > svg {
      flex: 0 0 auto;
    }

    a {
      color: var(--wp-admin-theme-color);

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

  &.is-core &__status {
    color: #007017;
    font-weight: 600;
  }

  &__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
  }

  &__configure {
    flex: 0 0 auto;
    cursor: pointer;
    border-radius: 2px;
    color: var(--wp-admin-theme-color);
    font-size: 13px;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;

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

    &:focus {
      outline: 2px solid transparent;
      box-shadow: 0 0 0 2px var(--wp-admin-theme-color);
    }
  }
}

// Badge tones: pro follows the admin color scheme; core stays neutral, and
// free and addon keep distinct category colors so they read apart.
.arraysubs-module-badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: #f0f0f1;
  color: #50575e;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;

  &--core {
    color: #2c3338;
  }

  &--free {
    background: #edfaef;
    color: #007017;
  }

  &--pro {
    background: color-mix(in srgb, var(--wp-admin-theme-color) 12%, #fff);
    color: var(--wp-admin-theme-color-darker-20);
  }

  &--addon {
    background: #fff;
    color: #3c434a;
    box-shadow: inset 0 0 0 1px #c3c4c7;
  }
}

button.arraysubs-module-card__configure {
  padding: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
  line-height: inherit;
  cursor: pointer;
}

.arraysubs-module-card.notranslate .arraysubs-module-card__status {
  flex-shrink: 0;
  white-space: nowrap;
}

.arraysubs-translated-languages {
  direction: ltr;
  text-align: left;

  &__intro {
    margin: 0 0 16px;
    color: #50575e;
    font-size: 13px;
    line-height: 1.6;

    strong,
    span {
      display: block;
    }

    strong {
      margin-bottom: 2px;
      color: #1d2327;
      font-weight: 600;
    }
  }

  &__list {
    max-height: min(44vh, 320px);
    margin: 0;
    padding: 0;
    border: 1px solid #dcdcde;
    border-radius: 6px;
    overflow-y: auto;
    list-style: none;

    &:focus-visible {
      outline: 2px solid var(--wp-admin-theme-color);
      outline-offset: 3px;
    }

    li {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: center;
      gap: 16px;
      margin: 0;
      padding: 10px 12px;
      border-bottom: 1px solid #f0f0f1;
      font-size: 13px;
      line-height: 1.5;

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

    code {
      padding: 2px 6px;
      border: 1px solid #e2e4e7;
      border-radius: 4px;
      background: #f6f7f7;
      color: #50575e;
      font-size: 12px;
      white-space: nowrap;
    }
  }

  &__footer {
    margin-top: 16px;
    text-align: right;
  }
}
