/* ============================================
   Upload Media Component - BEM Scoped Styles
   Prefix: .sc-upload-media
   ============================================ */
$isPublish: "[data-is-publish='true']";

.sc-upload-media {
  display: flex;
  flex-direction: column;
  font-family: inherit;
  color: #344054;
  //  padding: 16px 24px;
  height: 538px;

  &:is(#{$isPublish} *) {
    padding: 16px 24px;
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  /* === Header === */
  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    // padding: 16px 16px 0px 16px;
  }

  &__title {
    font-size: 16px;
    font-weight: 600;
    color: var(--_gray-900);
    margin: 0;
    line-height: 24px;
  }

  &__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    color: #667085;
    transition: all 0.15s ease;

    &:hover {
      background: #f2f4f7;
      color: #344054;
    }

    svg {
      width: 20px;
      height: 20px;
      stroke: currentColor;
      fill: none;
      stroke-width: 2;
      stroke-linecap: round;
      stroke-linejoin: round;
    }
  }

  /* === Tabs === */
  &__tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    gap: 12px;
    padding: 16px 0px 0px 0px;
  }

  &__tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border: 1px solid #e4e7ec;
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    color: #344054;

    &:hover:not(&--disabled) {
      background: var(--_primary-25);
      border-color: var(--_primary-400);
    }

    &--active {
      border-color: var(--_primary-400);
      background: var(--_primary-25);
      color: var(--_primary-400);

      .sc-upload-media__tab-icon svg {
        stroke: var(--_primary-400);
      }
    }

    &--disabled {
      background: #f9fafb;
      color: #98a2b3;
      cursor: not-allowed;
      pointer-events: none;
    }
  }

  &__tab-icon {
    display: flex;
    align-items: center;

    svg {
      width: 20px;
      height: 20px;
      stroke: #667085;
      fill: none;
      stroke-width: 2;
      stroke-linecap: round;
      stroke-linejoin: round;
    }
  }

  /* === Body === */
  &__body {
    height: 100%;
    padding: 16px 0px 0px 0px;
  }

  /* === Footer === */
  &__footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 8px 0;
    // border-top: 1px solid #e4e7ec;
  }

  &__btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
    line-height: 1.4;

    &--cancel {
      background: transparent;
      color: var(--_gray-900);

      &:hover {
        background: #f9fafb;
      }
    }

    &--primary {
      background: #4a6cf7;
      color: #fff;

      &:hover:not(:disabled) {
        background: #3b5de7;
      }

      &:disabled {
        background: #b0c4ff;
        cursor: not-allowed;
      }
    }
  }

  &__spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: sc-upload-media-spin 0.6s linear infinite;
    display: none;

    &--visible {
      display: inline-block;
    }
  }
}

/* === FromDevice === */
.sc-upload-media-device {
  border: 1px solid #e4e7ec;
  border-radius: 6px;
  background: #fcfcfd;
  padding: 16px;
  height: 100%;
  overflow-y: auto;
  display: flex;

  &__dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    cursor: pointer;
    text-align: center;
    color: var(--_gray-900);
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    transition: all 0.15s ease;
    height: 80px;
    padding: 40px;
    margin: auto;
    width: fit-content;
    align-self: center;

    &:hover,
    &:focus {
      border: 1px solid var(--_primary-300) !important;
      outline: 2px solid var(--_primary-50);
      background-color: var(--_primary-25);
    }

    &--dragover {
      border-color: #4a6cf7;
      background: #f0f4ff;
    }
  }

  &__dropzone-icon {
    display: flex;
    align-items: center;

    svg {
      width: 24px;
      height: 24px;
      stroke: #667085;
      fill: none;
      stroke-width: 2;
      stroke-linecap: round;
      stroke-linejoin: round;
    }
  }

  &__dropzone-text {
    font-size: 14px;
    font-weight: 500;
  }

  &__current-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 100%;

    img {
      max-width: 200px;
      max-height: 150px;
      object-fit: contain;
      border: 1px solid #e4e7ec;
      border-radius: 4px;
      padding: 8px;
      background: #fff;
    }
  }

  &__replace-text {
    font-size: 14px;
    color: #667085;
  }

  &__file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
  }

  &__file-item {
    position: relative;
    border: 1px solid var(--_gray-200);
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 6px;
    height: 170px;

    &:hover {
      border: 1px solid var(--_primary-200);
      box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.2);
    }
  }

  &__file-preview {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;

    img {
      max-width: 100%;
      max-height: 100%;
      object-fit: cover;
    }

    video {
      max-width: 100%;
      max-height: 100%;
      object-fit: cover;
    }

    &:hover .sc-upload-media-device__file-remove {
      opacity: 1;
    }
  }

  &__file-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    border: none;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);

    svg {
      width: 14px;
      height: 14px;
      stroke: #d92d20;
      fill: none;
      stroke-width: 2;
      stroke-linecap: round;
      stroke-linejoin: round;
    }
  }

  &__file-name {
    display: flex;
    align-items: center;
    gap: 6px;
    // margin-top: 6px;
    padding: 8px;
    font-size: 12px;
    color: var(--_gray-900);

    span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 90px;
    }

    svg {
      width: 16px;
      height: 16px;
      stroke: #667085;
      fill: none;
      stroke-width: 2;
      flex-shrink: 0;
    }
  }

  /* Hidden file input */
  &__input {
    display: none;
  }
}

/* === FromUrl === */
.sc-upload-media-url {
  height: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;

  &__input-wrapper {
    position: relative;
    border: 1px solid var(--_gray-300);
    border-radius: 6px;
    transition:
      background-color 0.2s,
      color 0.2s,
      border-color 0.2s,
      box-shadow 0.2s;

    &:focus-within {
      border: 1px solid var(--_primary-300);
      outline: 2px solid var(--_primary-50);
    }
  }

  &__input {
    width: 100%;
    padding: 10px 36px;
    // border: 1px solid #e4e7ec;
    border-radius: 6px;
    font-size: 14px;
    color: #344054;
    outline: none;
    transition: border-color 0.15s ease;

    &:focus {
      border-color: #4a6cf7;
      box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
    }

    &--invalid {
      border-color: #d92d20;

      &:focus {
        box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.1);
      }
    }

    &:disabled {
      background: #f9fafb;
      color: #98a2b3;
    }
  }

  &__input-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    cursor: pointer;

    svg {
      width: 16px;
      height: 16px;
      stroke: #667085;
      fill: none;
      stroke-width: 2;
    }
  }

  &__input-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;

    svg {
      width: 14px;
      height: 14px;
      stroke: #667085;
      fill: none;
      stroke-width: 2;
    }
  }

  &__error {
    font-size: 12px;
    color: #d92d20;
    margin-top: 4px;
  }

  &__preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid #e4e7ec;
    border-radius: 6px;
    background: #fcfcfd;
    overflow-y: auto;
    min-height: 0;

    img {
      max-width: 100%;
      max-height: 200px;
      object-fit: contain;
    }
  }

  &__preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #667085;
    font-size: 14px;
    font-weight: 500;
    height: 100%;

    svg {
      width: 24px;
      height: 24px;
      stroke: #667085;
      fill: none;
      stroke-width: 2;
    }
  }

  &__macro-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
    height: 100%;
    text-align: center;
    padding: 16px;

    strong {
      color: #4a6cf7;
      word-break: break-all;
    }
  }
}

/* === MyAssets === */
.sc-upload-media-assets {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;

  &__search {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--_gray-300) !important;
    border-radius: 6px;
    font-size: 14px;
    color: var(--_gray-900);
    outline: none;
    transition:
      background-color 0.2s,
      color 0.2s,
      border-color 0.2s,
      box-shadow 0.2s;

    &:focus {
      border: 1px solid var(--_primary-300) !important;
      outline: 2px solid var(--_primary-50);
    }
  }

  &__breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #667085;
  }

  &__breadcrumb-back {
    display: flex;
    align-items: center;
    cursor: pointer;
    background: none;
    border: none;
    padding: 2px;
    color: #667085;

    svg {
      width: 16px;
      height: 16px;
      stroke: currentColor;
      fill: none;
      stroke-width: 2;
    }

    &:hover {
      color: #344054;
    }
  }

  &__breadcrumb-item {
    cursor: pointer;
    color: var(--_gray-600);

    &:hover:not(&--active) {
      color: var(--_gray-900);
    }

    &--active {
      font-weight: 400;
      color: var(--_gray-900);
      cursor: default !important;
    }
  }

  &__breadcrumb-sep {
    color: var(--_gray-600);
  }

  &__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    border: 1px solid #e4e7ec;
    border-radius: 6px;
    background: #fcfcfd;
    padding: 16px;
    height: 260px;
    overflow-y: auto;
  }

  /* Folder card */
  &__folder {
    display: flex;
    flex-direction: column;
    border: 1px solid #e4e7ec;
    border-radius: 6px;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s ease;
    height: min-content;

    // &:hover {
    //   border-color: #4a6cf7;
    // }
  }

  &__folder-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 128px;
    background: #fff;

    svg {
      width: 48px;
      height: 48px;
      stroke: #d0d5dd;
      fill: none;
      stroke-width: 1.5;
    }
  }

  &__folder-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e4e7ec;
    font-size: 13px;
    color: var(--_gray-900);

    span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    input[type="radio"] {
      width: 16px;
      height: 16px;
      accent-color: var(--_primary-400);
      cursor: pointer;
      flex-shrink: 0;
    }

    &:hover {
      background: #f9fafb;
    }
  }

  /* Image card */
  &__image-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid #e4e7ec;
    border-radius: 6px;
    height: 170px;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s ease;
    height: 170px;
    width: 100%;

    .sc-upload-media-assets__img-cntainer {
      height: 130px;
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      overflow: hidden;

      &__image-thumb {
        max-width: 100%;
        max-height: 128px;

        object-fit: contain;
      }

      &__image-placeholder {
        width: 100%;
        height: 128px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #f5f5f5;

        svg {
          width: 32px;
          height: 32px;
          stroke: #d0d5dd;
          fill: none;
          stroke-width: 1.5;
        }
      }
    }

    &--selected {
      border-color: var(--_primary-400);
      border-width: 1px;
    }
  }

  &__file__name-checkbox {
    padding: 8px;
    display: flex;
    align-items: center;
    flex-grow: 1;
    width: 100%;
    border-top: 1px solid var(--_gray-200);
    justify-content: space-between;

    span {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 115px;
      line-height: 22px;
      text-align: left;
    }

    input[type="checkbox"] {
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
      width: 18px;
      height: 18px;
      border: 1px solid var(--_gray-300);
      border-radius: 50%;
      cursor: pointer;
      position: relative;
      margin: 0;
      transition: all 0.15s ease;

      &:checked {
        border-color: var(--_primary-400);
        background: var(--_primary-400);

        &::after {
          content: "";
          position: absolute;
          top: 45%;
          left: 50%;
          transform: translate(-50%, -60%) rotate(45deg);
          width: 4px;
          height: 9px;
          border: solid #fff;
          border-width: 0 1.5px 1.5px 0;
        }
      }

      &:hover {
        border-color: var(--_primary-400);
      }
    }
  }

  /* Empty state */
  &__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #98a2b3;
    font-size: 14px;
    grid-column: 1 / -1;
    color: var(--_gray-600);
  }

  /* Loading skeleton */
  &__skeleton {
    border-radius: 6px;
    height: 120px;
    background: linear-gradient(90deg, #f2f4f7 25%, #e4e7ec 50%, #f2f4f7 75%);
    background-size: 200% 100%;
    animation: sc-upload-media-shimmer 1.5s ease-in-out infinite;
  }
}

/* === Animations === */
@keyframes sc-upload-media-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes sc-upload-media-shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* === Upload Media Modal z-index override === */
.cfrm__modal--upload-media {
  .cfrm__modal__backdrop {
    z-index: 99999 !important;
  }

  .cfrm__modal__container {
    z-index: 100000 !important;
  }

  .cfrm__modal__body {
    .sc-upload-media {
      .sc-upload-media__tabs {
        padding: 8px 0px 0px 0px;
      }

      .sc-upload-media__footer {
        padding: 12px 0px 16px 0px;
      }
    }
  }

  .sc-upload-media__header {
    display: none;
  }
}

/* === sccoreui Dialog override for upload media === */
.upload-media-dialog {
  z-index: 100000 !important;
  border-radius: 12px !important;
  overflow: hidden !important;

  .p-dialog-header {
    display: none !important;
  }

  .p-dialog-content {
    padding: 0 !important;
    border-radius: 12px !important;

    .sc-upload-media {
      padding: 16px 24px;
    }
  }
}

.upload-media-dialog+.p-dialog-mask {
  z-index: 99999 !important;
}