@use '../styles/variables' as *;

.pem {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: $spacing-4;

  &__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(3px);
  }

  &__panel {
    position: relative;
    z-index: 1;
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: $radius-xl;
    box-shadow: $shadow-xl;
    width: 100%;
    max-width: 480px;
    overflow: hidden;
  }

  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: $spacing-5 $spacing-6;
    border-bottom: 1px solid var(--clr-border);
  }

  &__title {
    font-size: $font-size-lg;
    font-weight: $font-weight-semibold;
    color: var(--clr-text);
  }

  &__close {
    background: transparent;
    border: none;
    color: var(--clr-text-secondary);
    cursor: pointer;
    padding: $spacing-1;
    border-radius: $radius-base;
    display: flex;
    align-items: center;
    transition: color $transition-fast;

    &:hover { color: var(--clr-text); }
  }

  &__tabs {
    display: flex;
    border-bottom: 1px solid var(--clr-border);
  }

  &__tab {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: $spacing-2;
    padding: $spacing-3;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-size: $font-size-sm;
    font-weight: $font-weight-medium;
    font-family: $font-family-base;
    color: var(--clr-text-secondary);
    cursor: pointer;
    transition: color $transition-fast, border-color $transition-fast;

    &:hover { color: var(--clr-text); }

    &--active {
      color: var(--clr-primary);
      border-bottom-color: var(--clr-primary);
    }
  }

  &__saved {
    display: flex;
    align-items: center;
    gap: $spacing-2;
    padding: $spacing-3 $spacing-6;
    background: #f0fdf4;
    border-bottom: 1px solid #bbf7d0;
    color: #15803d;
    font-size: $font-size-sm;
    font-weight: $font-weight-medium;
  }

  &__form {
    padding: $spacing-6;
    display: flex;
    flex-direction: column;
    gap: $spacing-5;
  }

  &__field { display: flex; flex-direction: column; gap: $spacing-2; }

  &__label {
    font-size: $font-size-sm;
    font-weight: $font-weight-medium;
    color: var(--clr-text);
  }

  &__input {
    padding: $spacing-3 $spacing-4;
    border: 1px solid var(--clr-border);
    border-radius: $radius-base;
    font-size: $font-size-sm;
    font-family: $font-family-base;
    color: var(--clr-text);
    background: var(--clr-surface);
    outline: none;
    transition: border-color $transition-fast, box-shadow $transition-fast;

    &::placeholder { color: var(--clr-text-muted); }

    &:focus {
      border-color: $primary-400;
      box-shadow: 0 0 0 3px rgba($primary-400, 0.18);
    }

    &:disabled {
      opacity: 0.6;
      background: var(--clr-surface-raised);
      cursor: not-allowed;
    }

    &--error {
      border-color: $color-error;
      &:focus { box-shadow: 0 0 0 3px rgba($color-error, 0.18); }
    }
  }

  &__error { font-size: $font-size-xs; color: $color-error; }

  &__hint {
    font-size: $font-size-xs;
    color: var(--clr-text-muted);
  }

  &__section-label {
    font-size: $font-size-xs;
    font-weight: $font-weight-semibold;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--clr-text-muted);
    margin-bottom: -$spacing-2;
  }

  // Toggle rows
  &__toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: $spacing-4;
    padding: $spacing-3 0;
    border-bottom: 1px solid var(--clr-border);
    cursor: pointer;

    &:last-of-type { border-bottom: none; }
  }

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

  &__toggle-label {
    font-size: $font-size-sm;
    font-weight: $font-weight-medium;
    color: var(--clr-text);
  }

  &__toggle-desc {
    font-size: $font-size-xs;
    color: var(--clr-text-muted);
  }

  // iOS-style switch
  &__switch {
    flex-shrink: 0;
    position: relative;
    width: 40px;
    height: 22px;
    border-radius: $radius-full;
    background: var(--clr-border);
    border: none;
    cursor: pointer;
    transition: background $transition-base;

    &--on { background: var(--clr-primary); }
  }

  &__switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: $radius-full;
    background: #fff;
    box-shadow: $shadow-sm;
    transition: transform $transition-base;

    .pem__switch--on & { transform: translateX(18px); }
  }

  &__actions {
    display: flex;
    justify-content: flex-end;
    gap: $spacing-3;
    padding-top: $spacing-2;
    border-top: 1px solid var(--clr-border);
  }

  &__cancel-btn {
    padding: $spacing-2 $spacing-5;
    background: transparent;
    border: 1px solid var(--clr-border);
    border-radius: $radius-base;
    font-size: $font-size-sm;
    font-weight: $font-weight-medium;
    font-family: $font-family-base;
    color: var(--clr-text-secondary);
    cursor: pointer;
    transition: background $transition-fast;

    &:hover { background: var(--clr-surface-raised); }
  }

  &__save-btn {
    padding: $spacing-2 $spacing-5;
    background: var(--clr-primary);
    color: #fff;
    border: none;
    border-radius: $radius-base;
    font-size: $font-size-sm;
    font-weight: $font-weight-semibold;
    font-family: $font-family-base;
    cursor: pointer;
    transition: background $transition-fast, opacity $transition-fast;

    &:hover:not(:disabled) { background: var(--clr-primary-hover); }
    &:disabled { opacity: 0.55; cursor: not-allowed; }
  }
}
