// Member Insight / Manage Members Page Styles
// BEM methodology with arraysubs- prefix

.arraysubs-member-insight {
  max-width: 1200px;

  // ── Search Card ──────────────────────────────────────
  &__search-card {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: $radius-sm;
    padding: $spacing-lg;
    margin-bottom: $spacing-lg;
  }

  &__search-box {
    position: relative;

    label {
      display: flex;
      align-items: center;
      gap: 6px;
      margin-bottom: $spacing-sm;
      font-weight: 600;
      font-size: 14px;
      color: #1d2327;
    }
  }

  &__search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  &__search-input {
    flex: 1;
    max-width: 500px;
    height: 42px;
    padding: 0 16px;
    border: 1px solid #8c8f94;
    border-radius: $radius-sm;
    font-size: 14px;
    transition:
      border-color $transition-fast,
      box-shadow $transition-fast;

    &:focus {
      border-color: #2271b1;
      box-shadow: 0 0 0 1px #2271b1;
      outline: none;
    }
  }

  &__searching-indicator {
    font-size: 13px;
    color: #646970;
    font-style: italic;
  }

  &__search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 100%;
    max-width: 500px;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: $radius-sm;
    box-shadow: $shadow-lg;
    max-height: 350px;
    overflow-y: auto;
    z-index: 1000;
  }

  &__search-result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-bottom: 1px solid #f0f0f1;
    background: none;
    cursor: pointer;
    text-align: left;
    transition: background $transition-fast;

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

    &:hover {
      background: #f0f6fc;
    }
  }

  &__result-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  &__result-name {
    font-weight: 600;
    color: #1d2327;
    font-size: 14px;
  }

  &__result-meta {
    font-size: 12px;
    color: #646970;
  }

  &__result-stats {
    flex-shrink: 0;
    margin-left: $spacing-md;
  }

  &__result-subs {
    font-size: 12px;
    font-weight: 500;
    color: #007017;
    background: #e6f6e6;
    padding: 3px 10px;
    border-radius: $radius-lg;
  }

  // ── Loading ──────────────────────────────────────────
  &__loading {
    display: flex;
    flex-direction: column;
    gap: $spacing-md;
  }

  // ── Empty State ──────────────────────────────────────
  &__empty-state {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: $radius-sm;
    padding: 60px $spacing-lg;
    text-align: center;
    color: #646970;

    svg {
      color: #c3c4c7;
      margin-bottom: $spacing-md;
    }

    h3 {
      margin: 0 0 8px;
      color: #1d2327;
      font-size: 18px;
    }

    p {
      margin: 0;
      font-size: 14px;
      max-width: 500px;
      margin-left: auto;
      margin-right: auto;
      line-height: 1.6;
    }
  }

  // ── Details Container ────────────────────────────────
  &__details {
    display: flex;
    flex-direction: column;
    gap: $spacing-lg;
  }

  // ── Profile Card ─────────────────────────────────────
  &__profile-card {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: $radius-sm;
    overflow: hidden;
  }

  &__profile-header {
    display: flex;
    align-items: flex-start;
    gap: $spacing-lg;
    padding: $spacing-lg;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    border-bottom: 1px solid #f0f0f1;
  }

  &__profile-avatar {
    flex-shrink: 0;

    img {
      border-radius: 50%;
      border: 3px solid #fff;
      box-shadow: $shadow-sm;
    }
  }

  &__profile-info {
    flex: 1;
    min-width: 0;
  }

  &__profile-name {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 600;
    color: #1d2327;
  }

  &__profile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: $spacing-md;
    font-size: 13px;
    color: #646970;

    span {
      display: inline-flex;
      align-items: center;
      gap: 4px;

      svg {
        color: #8c8f94;
      }
    }
  }

  &__profile-roles {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: $spacing-sm;
  }

  &__role-badge {
    display: inline-block;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 500;
    color: #2271b1;
    background: #e7f3fe;
    border-radius: $radius-lg;
    text-transform: capitalize;
  }

  &__profile-actions {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    align-items: flex-start;
    flex-wrap: wrap;

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

  // ── Edit Panel ──────────────────────────────────────
  &__edit-panel {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: $radius-sm;
    padding: $spacing-lg;
  }

  &__edit-section {
    padding-bottom: $spacing-lg;
    margin-bottom: $spacing-lg;
    border-bottom: 1px solid #f0f0f1;

    &:last-child {
      padding-bottom: 0;
      margin-bottom: 0;
      border-bottom: none;
    }

    h3 {
      margin: 0 0 $spacing-md;
      font-size: 15px;
      font-weight: 600;
      color: #1d2327;
    }
  }

  &__edit-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: $spacing-md;
    margin-bottom: $spacing-md;

    h3 {
      margin: 0;
    }

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

  &__edit-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: $spacing-md;
  }

  &__field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;

    span {
      font-size: 12px;
      font-weight: 600;
      color: #1d2327;
    }

    input,
    select {
      width: 100%;
      min-height: 36px;
      border: 1px solid #8c8f94;
      border-radius: $radius-sm;
      color: #1d2327;
      font-size: 13px;
    }
  }

  &__additional-address {
    padding: $spacing-md;
    margin-bottom: $spacing-md;
    border: 1px solid #dcdcde;
    border-radius: $radius-sm;
    background: #f9f9f9;

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

  &__additional-address-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: $spacing-md;
    margin-bottom: $spacing-md;

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

  // ── Stats Grid ───────────────────────────────────────
  &__stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: 1fr;
    gap: 8px;
  }

  &__stat-card {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: $radius-sm;
    padding: $spacing-md $spacing-lg;
    display: flex;
    align-items: center;
    gap: $spacing-md;
    transition: box-shadow $transition-fast;

    &:hover {
      box-shadow: $shadow-sm;
    }

    &--primary {
      border-left: 3px solid #2271b1;
      .arraysubs-member-insight__stat-icon {
        color: #2271b1;
        background: #e7f3fe;
      }
    }
    &--success {
      border-left: 3px solid #007017;
      .arraysubs-member-insight__stat-icon {
        color: #007017;
        background: #e6f6e6;
      }
    }
    &--info {
      border-left: 3px solid #0369a1;
      .arraysubs-member-insight__stat-icon {
        color: #0369a1;
        background: #e0f2fe;
      }
    }
    &--purple {
      border-left: 3px solid #7c3aed;
      .arraysubs-member-insight__stat-icon {
        color: #7c3aed;
        background: #f3e8ff;
      }
    }
    &--danger {
      border-left: 3px solid #a00;
      .arraysubs-member-insight__stat-icon {
        color: #a00;
        background: #fce4e4;
      }
    }
    &--default {
      border-left: 3px solid #646970;
      .arraysubs-member-insight__stat-icon {
        color: #646970;
        background: #f0f0f1;
      }
    }
  }

  &__stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: $radius-md;
    flex-shrink: 0;
  }

  &__stat-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  &__stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #1d2327;
    line-height: 1.2;

    .woocommerce-Price-amount {
      font-size: inherit;
    }
  }

  &__stat-label {
    font-size: 12px;
    color: #646970;
    margin-top: 2px;
  }

  // ── Collapsible Section ──────────────────────────────
  &__section {
    background: #fff;
    border: 1px solid #c3c4c7;
    margin-bottom: $spacing-lg;
    border-radius: $radius-sm;
    overflow: hidden;
  }

  &__section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 14px $spacing-lg;
    background: #f6f7f7;
    border: none;
    border-bottom: 1px solid transparent;
    cursor: pointer;
    transition: background $transition-fast;

    &:hover {
      background: #f0f0f1;
    }

    .arraysubs-member-insight__section--open & {
      border-bottom-color: #c3c4c7;
    }
  }

  &__section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #1d2327;

    svg {
      color: #646970;
    }
  }

  &__section-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    font-size: 12px;
    font-weight: 600;
    color: #2271b1;
    background: #e7f3fe;
    border-radius: $radius-lg;
  }

  &__section-body {
    padding: $spacing-lg;
    overflow-x: auto;
  }

  &__empty-message {
    color: #646970;
    font-style: italic;
    margin: 0;
    padding: $spacing-md 0;
    text-align: center;
  }

  // ── Table ────────────────────────────────────────────
  &__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;

    th {
      text-align: left;
      padding: 10px 12px;
      font-weight: 600;
      color: #1d2327;
      border-bottom: 2px solid #c3c4c7;
      background: #f9f9f9;
      white-space: nowrap;
    }

    td {
      padding: 10px 12px;
      border-bottom: 1px solid #f0f0f1;
      color: #1d2327;
      vertical-align: middle;
    }

    tr:hover td {
      background: #f9fbfd;
    }

    a {
      color: #2271b1;
      text-decoration: none;
      font-weight: 500;

      &:hover {
        color: #135e96;
        text-decoration: underline;
      }
    }
  }

  &__table-actions {
    display: flex;
    gap: 8px;
  }

  // ── Badge ────────────────────────────────────────────
  &__badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: $radius-lg;
    white-space: nowrap;
  }

  // ── Order Status ─────────────────────────────────────
  &__order-status {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: $radius-lg;
    white-space: nowrap;
    background: #f0f0f1;
    color: #646970;

    &--completed {
      background: #e6f6e6;
      color: #007017;
    }
    &--processing {
      background: #e0f2fe;
      color: #0369a1;
    }
    &--on-hold {
      background: #fff3cd;
      color: #856404;
    }
    &--pending {
      background: #e7f3fe;
      color: #0a58ca;
    }
    &--cancelled {
      background: #fce4e4;
      color: #a00;
    }
    &--refunded {
      background: #f3e8ff;
      color: #7c3aed;
    }
    &--failed {
      background: #fce4e4;
      color: #a00;
    }
  }

  // ── Addresses ────────────────────────────────────────
  &__addresses-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: $spacing-lg;
  }

  &__address-card {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: $radius-sm;
    padding: $spacing-lg;

    h4 {
      margin: 0 0 $spacing-sm;
      font-size: 14px;
      font-weight: 600;
      color: #1d2327;
    }
  }

  &__address-contact {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 6px;
    font-size: 13px;
    color: #646970;

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

  &__address-text {
    margin: $spacing-sm 0 0;
    font-size: 13px;
    color: #1d2327;
    line-height: 1.6;
    white-space: pre-line;
  }

  // ── Quick Links ───────────────────────────────────────
  &__quick-links {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: $spacing-md;
    margin-bottom: $spacing-lg;
  }

  &__quick-link-card {
    display: flex;
    align-items: center;
    gap: $spacing-md;
    padding: $spacing-md $spacing-lg;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: $radius-sm;
    text-decoration: none;
    color: #1d2327;
    transition:
      border-color $transition-fast,
      box-shadow $transition-fast;

    &:hover,
    &:focus {
      border-color: #2271b1;
      box-shadow: 0 0 0 1px #2271b1;
      color: #1d2327;
      text-decoration: none;
    }
  }

  &__quick-link-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: $radius-sm;
    flex-shrink: 0;

    &--orders {
      background: #e7f3fe;
      color: #2271b1;
    }

    &--credit {
      background: #f3e8ff;
      color: #7c3aed;
    }
  }

  &__quick-link-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
  }

  &__quick-link-title {
    font-weight: 600;
    font-size: 14px;
    color: #1d2327;
  }

  &__quick-link-desc {
    font-size: 12px;
    color: #646970;
    margin-top: 2px;
  }

  &__quick-link-arrow {
    color: #c3c4c7;
    flex-shrink: 0;
    transition: color $transition-fast;

    .arraysubs-member-insight__quick-link-card:hover & {
      color: #2271b1;
    }
  }

  // ── Responsive ───────────────────────────────────────
  @media (max-width: 782px) {
    &__profile-header {
      flex-direction: column;
      align-items: center;
      text-align: center;
    }

    &__profile-meta {
      justify-content: center;
    }

    &__profile-roles {
      justify-content: center;
    }

    &__profile-actions {
      align-self: center;
      justify-content: center;
    }

    &__stats-grid {
      grid-template-columns: repeat(2, 1fr);
    }

    &__edit-grid {
      grid-template-columns: 1fr;
    }

    &__edit-section-header {
      flex-direction: column;
      align-items: stretch;
    }

    &__additional-address-header {
      grid-template-columns: 1fr;
      align-items: stretch;
    }

    &__addresses-grid {
      grid-template-columns: 1fr;
    }

    &__quick-links {
      grid-template-columns: 1fr;
    }

    &__table {
      font-size: 12px;

      th,
      td {
        padding: 8px;
      }
    }
  }

  @media (max-width: 600px) {
    &__stats-grid {
      grid-template-columns: 1fr;
    }

    &__search-input {
      max-width: 100%;
    }

    &__search-results {
      max-width: 100%;
    }
  }
}
