@use "../../styles/mixins" as m;

// A module hashes its own keyframes, so they are declared here rather than
// pulled from _motion.scss — see that file's note.
@keyframes svGenerateSpin {
  to {
    transform: rotate(360deg);
  }
}

// An indeterminate sweep: the generator gives no progress, only an end.
@keyframes svGenerateSweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(250%);
  }
}

@include m.scoped {
  .root {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: -6px;
  }
  // Reads as an assistive action beside the description, not as a second
  // primary button: violet type on the page, no fill.
  .trigger {
    @include m.wp-reset-button;
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid #e8edf5;
    background: #fff;
    color: #6436c9;
    cursor: pointer;
    font:
      700 13px/20px "Plus Jakarta Sans",
      sans-serif;
    box-shadow:
      4px 4px 11px #dce2ec,
      -2px -2px 7px #fbfcfe;
    &:hover {
      color: #51299f;
    }
    &[aria-expanded="true"] {
      box-shadow:
        inset 4px 4px 9px #dce2ec,
        inset -2px -2px 6px #fbfcfe;
    }
    &:focus-visible {
      outline: 2px solid #6436c9;
      outline-offset: 2px;
    }
  }
  .triggerIcon {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
  }
  .panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-radius: 14px;
    border: 1px solid #e4dcf8;
    background: #faf8ff;
  }
  .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    font-size: 13px;
    font-weight: 600;
    color: #39415a;
    textarea {
      @include m.wp-reset-control;
      width: 100%;
      max-width: 100%;
      min-width: 0;
      margin: 0;
      box-sizing: border-box;
      padding: 10px 12px;
      border-radius: 12px;
      border: 1px solid #e8edf5;
      background: #fff;
      color: #151b2b;
      resize: vertical;
      box-shadow:
        inset 4px 4px 9px #dce2ec,
        inset -2px -2px 6px #fbfcfe;
      font:
        500 14px/21px "Plus Jakarta Sans",
        sans-serif;
      &:focus {
        outline: 2px solid #6436c9;
        outline-offset: 2px;
      }
    }
  }
  .options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
  }
  .note {
    color: #5b6680;
  }
  .actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }
  .generate,
  .cancel {
    @include m.wp-reset-button;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    font:
      700 13px/20px "Plus Jakarta Sans",
      sans-serif;
    &:disabled {
      cursor: default;
      opacity: 0.55;
    }
    &:focus-visible {
      outline: 2px solid #6436c9;
      outline-offset: 2px;
    }
  }
  .generate {
    background: #6436c9;
    color: #fff;
    box-shadow:
      6px 6px 14px #dce2ec,
      -3px -3px 9px #fbfcfe;
    &:hover:not(:disabled) {
      background: #51299f;
    }
  }
  .cancel {
    background: #fff;
    border-color: #e8edf5;
    color: #39415a;
  }
  .spinner {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    animation: svGenerateSpin 0.7s linear infinite;
    @include m.reduced-motion {
      animation: none;
    }
  }
  .progress {
    overflow: hidden;
    height: 4px;
    border-radius: 999px;
    background: #ece4fb;
    span {
      display: block;
      width: 40%;
      height: 100%;
      border-radius: inherit;
      background: linear-gradient(90deg, #a07ced, #6436c9);
      animation: svGenerateSweep 1.1s ease-in-out infinite;
    }
    // Without the sweep the bar still has to read as "working", so it fills.
    @include m.reduced-motion {
      span {
        width: 100%;
        animation: none;
      }
    }
  }
  .error {
    color: #b42318;
    font-weight: 600;
  }
  .tags {
    display: flex;
    flex-direction: column;
    gap: 8px;
    strong {
      font-size: 13px;
      font-weight: 600;
      color: #39415a;
    }
  }
  .tagList {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .tag {
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid #e4dcf8;
    background: #fff;
    color: #51299f;
    font-size: 12px;
    font-weight: 600;
  }
}
