@use "core/functions" as *;
@use "core/mixins" as *;

// fixit-encryptor custom element
fixit-encryptor {
  display: block;
}

// Card container for the decryptor UI
.fixit-decryptor-container {
  text-align: center;
  margin-block: fi-var(decryptor-margin-block);
}

// Form wrapper
.fixit-decryptor-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  max-width: 24rem;
  margin-inline: auto;
  padding: 1.5rem;
  border: 1px solid fi-var(global-border-color);
  transition: opacity 0.3s ease-out;
  @include border-radius;
  @include box-shadow(hover);
}

// Lock icon header
.fixit-decryptor-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  aspect-ratio: 1;
  background-color: light-dark(fi-rgba(fi-var(primary), 0.1), fi-rgba(fi-var(primary), 0.15));
  @include border-radius(full);
}

// Password input field with icon prefix
.fixit-decryptor-field {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0 0.75rem;
  border: 1px solid fi-var(global-border-color);
  background-color: fi-var(global-background-color);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  @include border-radius;

  &:focus-within {
    border-color: var(--fi-primary);
    box-shadow: 0 0 0 2px light-dark(fi-rgba(fi-var(primary), 0.15), fi-rgba(fi-var(primary), 0.25));
  }

  > i {
    flex-shrink: 0;
    color: fi-var(global-font-tertiary-color);
    font-size: 0.8rem;
  }
}

.fixit-decryptor-input {
  flex: 1;
  height: 2.5rem;
  border: none;
  outline: none;
  background: transparent;
  color: fi-var(global-font-color);

  &::placeholder {
    color: fi-var(global-font-quaternary-color);
  }
}

// Unlock button
.fixit-decryptor-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 2.5rem;
  border: none;
  background-color: fi-rgba(fi-var(primary), 0.95);
  color: var(--fi-global-background-color, #fff);
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s ease;
  @include border-radius;

  &:hover {
    opacity: 0.85;
  }
}

// Re-encrypt button (page-level, after decryption)
.fixit-encryptor-btn {
  display: none;
  margin-top: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid fi-var(global-border-color);
  border-radius: 50%;
  background: none;
  color: fi-var(global-font-tertiary-color);
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;

  &:hover {
    color: fi-var(global-link-hover-color);
    border-color: fi-var(global-link-hover-color);
    background-color: light-dark(fi-rgba(fi-var(primary), 0.06), fi-rgba(fi-var(primary), 0.1));
  }

  .decrypted & {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

// Page-level decryptor
article fixit-encryptor {
  .fixit-decryptor-container {
    @include set-fi-var(decryptor-margin-block, 2rem);
  }

  &.decrypted > .fixit-decryptor-container .fixit-decryptor-form {
    display: none;
  }
}

// Fade-in when form becomes visible (e.g. page load or re-encrypt)
@starting-style {
  article fixit-encryptor > .fixit-decryptor-container .fixit-decryptor-form {
    opacity: 0;
  }
}

// Shortcode-level decryptor — connected input + button design
#content fixit-encryptor {
  .fixit-decryptor-container {
    @include set-fi-var(decryptor-margin-block, 1rem);
  }

  .fixit-decryptor-form {
    flex-direction: row;
    justify-content: center;
    gap: 0;
    max-width: 24rem;
    padding: 0;
    border: none;
    border-radius: 0;
  }

  .fixit-decryptor-header {
    display: none;
  }

  .fixit-decryptor-field {
    flex: 1;
    height: 2.5rem;
    border-right: none;
    border-radius: fi-var(global-border-radius) 0 0 fi-var(global-border-radius);

    &:focus-within + .fixit-decryptor-btn {
      border-color: var(--fi-primary);
      box-shadow: 0 0 0 2px light-dark(fi-rgba(fi-var(primary), 0.15), fi-rgba(fi-var(primary), 0.25));
    }
  }

  .fixit-decryptor-btn {
    width: auto;
    padding: 0 0.85rem;
    border-radius: 0 fi-var(global-border-radius) fi-var(global-border-radius) 0;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
  }

  &.decrypted > .fixit-decryptor-container {
    display: none;
  }
}

// Hidden elements for encrypted pages
.encrypted-hidden {
  display: none !important;
}
