@use '../../styles/panel-shared' as panel;

.book-uploader {
  width: 700px;
  max-width: 700px;
  display: flex;
  flex-direction: column;

  @media (max-width: 768px) {
    width: 100%;
    max-width: 100%;
  }
}

.panel-header {
  @include panel.panel-header;
  border-bottom: none;
}

.upload-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.75rem;
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);

  @media (max-width: 480px) {
    padding: 1rem;
    gap: 1rem;
  }
}

.destination-section,
.library-selection,
.file-upload-section {
  display: flex;
  flex-direction: column;

  .section-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 0.875rem;
    background: var(--overlay-background);
    border-radius: 6px;

    .section-title {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      font-size: 0.9rem;
      font-weight: 600;
      color: var(--text-color);

      i {
        color: var(--primary-color);
        font-size: 1rem;
      }
    }

    @media (max-width: 480px) {
      padding: 0.5rem 0.625rem;

      .section-title {
        font-size: 0.85rem;
      }
    }
  }
}

.destination-selector {
  display: flex;
  justify-content: center;
}

.selection-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0 0.75rem 1rem 0.75rem;

  .field-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;

    .field-label {
      font-size: 0.875rem;
      font-weight: 600;
      color: var(--text-color);
      padding-left: 0.25rem;
    }
  }
}

.file-upload-section {
  ::ng-deep .p-fileupload {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    background: var(--ground-background);
    transition: border-color 0.3s ease, background-color 0.3s ease;

    .p-fileupload-buttonbar {
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 0;
      background: transparent;
      border: none;
    }

    .p-fileupload-content {
      padding: 1rem;
      background: transparent;
      border: none;
      transition: background-color 0.3s ease;

      &.p-fileupload-highlight {
        background: color-mix(in srgb, var(--primary-color) 5%, transparent);

        .empty-icon-wrapper {
          border-color: var(--primary-color);

          .empty-icon {
            color: var(--primary-color);
            opacity: 1;
            transform: scale(1.1);
          }
        }
      }
    }

    &:has(.p-fileupload-highlight) {
      border-color: var(--primary-color);
    }
  }

  .upload-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    width: 100%;

    .action-buttons {
      display: flex;
      gap: 0.75rem;
      flex-wrap: wrap;
      justify-content: center;
    }

    .upload-hint {
      color: var(--text-secondary-color);
      font-size: 0.875rem;
      text-align: center;
    }

    @media (max-width: 480px) {
      padding: 0.75rem;
      gap: 0.5rem;

      .action-buttons {
        width: 100%;
        flex-direction: column;

        ::ng-deep .p-button {
          width: 100%;
        }
      }

      .upload-hint {
        font-size: 0.8rem;
      }
    }
  }

  .upload-progress-summary {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.625rem 0.875rem;
    margin-bottom: 0.5rem;

    .progress-row {
      display: flex;
      align-items: center;
      gap: 1rem;
      margin-bottom: 0.5rem;
      font-size: 0.85rem;

      .progress-status {
        display: flex;
        align-items: center;
        gap: 0.375rem;
        font-weight: 600;
        color: var(--text-color);

        i {
          font-size: 0.9rem;
          color: var(--primary-color);
        }

        .pi-check-circle {
          color: #22c55e;
        }
      }

      .progress-files {
        color: var(--text-secondary-color);

        .failed-count {
          color: #ef4444;
          font-weight: 500;
        }
      }

      .progress-bytes {
        color: var(--text-secondary-color);
        margin-left: auto;
      }

      .progress-percent {
        font-weight: 700;
        color: var(--primary-color);
        min-width: 42px;
        text-align: right;
      }
    }

    ::ng-deep .overall-progress-bar {
      height: 6px;
      border-radius: 3px;
      background: var(--overlay-background);

      .p-progressbar-value {
        border-radius: 3px;
        transition: width 0.3s ease;
      }
    }

    @media (max-width: 480px) {
      padding: 0.5rem 0.75rem;

      .progress-row {
        flex-wrap: wrap;
        gap: 0.5rem;
        font-size: 0.8rem;

        .progress-bytes {
          margin-left: 0;
        }
      }
    }
  }

  .files-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.25rem;

    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: var(--overlay-background);
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb {
      background: var(--border-color);
      border-radius: 3px;
      transition: background 0.2s ease;

      &:hover {
        background: var(--primary-color);
      }
    }

    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--overlay-background);

    .file-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
      padding: 0.25rem 0.75rem;
      background: var(--card-background);
      border: 1px solid var(--border-color);
      border-radius: 8px;
      transition: all 0.2s ease;

      &:hover {
        border-color: var(--primary-color);
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
      }

      .file-info {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        flex: 1;
        min-width: 0;

        .file-name {
          flex: 1;
          font-weight: 500;
          color: var(--text-color);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 0.9rem;
        }

        .file-size {
          color: var(--text-secondary-color);
          font-size: 0.875rem;
          flex-shrink: 0;
        }

        .file-progress-text {
          font-size: 0.85rem;
          font-weight: 600;
          color: var(--primary-color);
          min-width: 40px;
          text-align: right;
          flex-shrink: 0;
        }
      }

      .file-actions {
        display: flex;
        align-items: center;
        flex-shrink: 0;

        .status-icon {
          font-size: 1.25rem;
          padding: 0.5rem;

          &.uploading {
            color: var(--primary-color);
          }

          &.success {
            color: #22c55e;
          }

          &.warning,
          &.error {
            color: #f97316;
          }
        }
      }

      @media (max-width: 480px) {
        padding: 0.625rem;
        gap: 0.5rem;

        .file-info {
          gap: 0.5rem;

          .file-name {
            font-size: 0.85rem;
          }

          .file-size {
            font-size: 0.8rem;
          }
        }

        .file-actions {
          .status-icon {
            font-size: 1rem;
            padding: 0.375rem;
          }
        }
      }
    }
  }

  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1.5rem 1rem;

    .empty-icon-wrapper {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 80px;
      height: 80px;
      background: var(--overlay-background);
      border-radius: 50%;
      margin-bottom: 1rem;
      border: 3px dashed var(--border-color);
      transition: border-color 0.3s ease;

      .empty-icon {
        font-size: 2.5rem;
        color: var(--text-secondary-color);
        opacity: 0.6;
        transition: color 0.3s ease, opacity 0.3s ease, transform 0.3s ease;

        &.active {
          color: #22c55e;
        }
      }
    }

    .empty-title {
      margin: 0 0 1.5rem 0;
      font-size: 1.125rem;
      font-weight: 600;
      color: var(--text-color);
    }

    .empty-description {
      margin: 0;
      font-size: 0.875rem;
      color: var(--text-secondary-color);
      max-width: 450px;
      line-height: 1.5;

      strong {
        color: var(--text-color);
      }
    }

    @media (max-width: 480px) {
      padding: 1.5rem 0.75rem;
      min-height: 180px;

      .empty-icon-wrapper {
        width: 70px;
        height: 70px;
        margin-bottom: 0.75rem;

        .empty-icon {
          font-size: 2rem;
        }
      }

      .empty-title {
        font-size: 1rem;
      }

      .empty-description {
        font-size: 0.8rem;
        max-width: 100%;
      }
    }
  }
}

::host ::ng-deep .p-fileupload-content p-progressbar {
  display: none !important;
}

.full-width {
  width: 100%;
}
