// Store Credit Management Page Styles
// BEM methodology with arraysubs- prefix

.arraysubs-store-credit {
  // Search Section
  &__search-section {
    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 {
    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;
    min-width: 0;
  }

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

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

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

  &__customer-balance {
    font-weight: 600;
    color: #007017;
    background: #e6f6e6;
    padding: 3px 10px;
    border-radius: $radius-lg;
    font-size: 12px;
  }

  // Customer Section
  &__customer-section {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    margin-bottom: 24px;
  }

  &__customer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #ddd;
    background: #f6f7f7;
    border-radius: 4px 4px 0 0;

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

    p {
      margin: 4px 0 0;
      font-size: 13px;
      color: #646970;
    }
  }

  &__customer-info {
    flex: 1;
  }

  &__customer-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }

  // Balance Card
  &__balance-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 24px;
    margin: 20px;
    border-radius: 8px;
    text-align: center;
  }

  &__balance-label {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 8px;
  }

  &__balance-amount {
    font-size: 36px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;

    svg {
      opacity: 0.8;
    }
  }

  // Adjustment Section
  &__adjustment-section {
    padding: 0 20px 20px;

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

  &__adjustment-form {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
  }

  &__adjustment-amount {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 120px;

    label {
      font-size: 13px;
      font-weight: 500;
      color: #1d2327;
    }

    input {
      padding: 8px 12px;
      border: 1px solid #8c8f94;
      border-radius: 4px;
      font-size: 14px;
      width: 120px;

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

  &__adjustment-type {
    display: flex;
    flex-direction: column;
    gap: 6px;

    > label {
      font-size: 13px;
      font-weight: 500;
      color: #1d2327;
    }
  }

  &__radio-group {
    display: flex;
    gap: 16px;

    label {
      display: flex;
      align-items: center;
      gap: 6px;
      cursor: pointer;
      font-size: 14px;
      color: #1d2327;

      input[type="radio"] {
        margin: 0;
      }

      svg {
        width: 16px;
        height: 16px;
      }
    }
  }

  &__adjustment-note {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 200px;

    label {
      font-size: 13px;
      font-weight: 500;
      color: #1d2327;
    }

    input {
      padding: 8px 12px;
      border: 1px solid #8c8f94;
      border-radius: 4px;
      font-size: 14px;
      width: 100%;

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

  // History Section
  &__history-section {
    padding: 0 20px 20px;

    h4 {
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 0 0 16px;
      font-size: 14px;
      font-weight: 600;
      color: #1d2327;

      svg {
        width: 18px;
        height: 18px;
        color: #646970;
      }
    }
  }

  &__history-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    overflow: hidden;

    th,
    td {
      padding: 12px 16px;
      text-align: left;
      border-bottom: 1px solid #f0f0f1;
      font-size: 13px;
    }

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

    tbody tr:hover {
      background: #f9f9f9;
    }

    tbody tr:last-child td {
      border-bottom: none;
    }
  }

  &__source-label {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    background: #f0f0f1;
    color: #50575e;
  }

  &__note {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #646970;
    font-style: italic;
  }

  &__amount {
    font-weight: 600;

    &--credit {
      color: #007017;
    }

    &--debit {
      color: #b32d2e;
    }
  }

  // Pagination
  &__pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    margin-top: 16px;
    border-top: 1px solid #e0e0e0;

    button {
      padding: 6px 12px;
      font-size: 13px;

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }
    }

    span {
      font-size: 13px;
      color: #646970;
    }
  }

  &__no-history {
    text-align: center;
    padding: 30px;
    color: #646970;
    font-style: italic;
  }

  // Empty State
  &__empty-state {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    text-align: center;
    padding: 60px 20px;
    color: #646970;

    svg {
      width: 48px;
      height: 48px;
      margin-bottom: 16px;
      opacity: 0.4;
      color: #1d2327;
    }

    p {
      margin: 0;
      font-size: 14px;
      max-width: 400px;
      margin: 0 auto;
    }
  }

  // Loading state
  &__loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: #646970;

    svg {
      animation: spin 1s linear infinite;
      margin-right: 10px;
    }
  }
}

// Credit History Page
.arraysubs-credit-history {
  &__filters {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    padding: 16px 20px;
    margin-bottom: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
  }

  &__filter-group {
    display: flex;
    align-items: center;
    gap: 12px;

    label {
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 13px;
      font-weight: 500;
      color: #1d2327;

      svg {
        width: 16px;
        height: 16px;
        color: #646970;
      }
    }

    select {
      padding: 6px 10px;
      border: 1px solid #8c8f94;
      border-radius: 4px;
      font-size: 14px;
      min-width: 150px;

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

  &__total {
    font-size: 13px;
    color: #646970;
  }

  &__table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    overflow: hidden;

    th,
    td {
      padding: 12px 16px;
      text-align: left;
      border-bottom: 1px solid #f0f0f1;
      font-size: 13px;
    }

    th {
      background: #f6f7f7;
      font-weight: 600;
      color: #1d2327;
      white-space: nowrap;
    }

    tbody tr {
      transition: background 0.15s ease;

      &:hover {
        background: #f9f9f9;
      }
    }

    tbody tr:last-child td {
      border-bottom: none;
    }
  }

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

  &__customer-name {
    font-weight: 500;
    color: #1d2327;
  }

  &__customer-email {
    font-size: 12px;
    color: #646970;
  }

  &__source-label {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    background: #f0f0f1;
    color: #50575e;
  }

  &__note {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #646970;
    font-style: italic;
  }

  &__subscription {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #2271b1;
  }

  &__amount {
    font-weight: 600;

    &--credit {
      color: #007017;
    }

    &--debit {
      color: #b32d2e;
    }
  }

  &__pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    margin-top: 16px;

    button {
      padding: 6px 12px;
      font-size: 13px;

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }
    }

    span {
      font-size: 13px;
      color: #646970;
    }
  }

  &__empty {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    text-align: center;
    padding: 60px 20px;
    color: #646970;

    svg {
      width: 48px;
      height: 48px;
      margin-bottom: 16px;
      opacity: 0.4;
      color: #1d2327;
    }

    p {
      margin: 0;
      font-size: 14px;
    }
  }

  &__note-box {
    background: #fff8e5;
    border: 1px solid #f0c14b;
    border-radius: 4px;
    padding: 12px 16px;
    margin-top: 24px;

    p {
      margin: 0;
      font-size: 13px;
      color: #1d2327;

      strong {
        color: #996800;
      }
    }
  }

  &__delete-modal {
    p {
      margin: 0 0 16px;
      font-size: 14px;
      color: #1d2327;
    }
  }

  &__delete-details {
    background: #f6f7f7;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 12px 16px;
    margin-bottom: 16px;

    p {
      margin: 0 0 8px;
      font-size: 13px;

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

  &__delete-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid #ddd;
  }
}

// Responsive
@media (max-width: 782px) {
  .arraysubs-store-credit {
    &__customer-header {
      align-items: flex-start;
      gap: 12px;
      flex-direction: column;
    }

    &__customer-actions {
      width: 100%;
    }

    &__adjustment-form {
      flex-direction: column;
      align-items: stretch;
    }

    &__adjustment-amount input {
      width: 100%;
    }

    &__radio-group {
      flex-direction: column;
      gap: 8px;
    }

    &__history-table {
      display: block;
      overflow-x: auto;
    }

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

@media (max-width: 600px) {
  .arraysubs-store-credit {
    &__search-input {
      max-width: 100%;
    }

    &__search-result-item {
      align-items: flex-start;
      gap: $spacing-sm;
      flex-direction: column;
    }

    &__result-stats {
      margin-left: 0;
    }
  }
}

// Animation
@keyframes spin {
  from {
    transform: rotate(0deg);
  }

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