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

:host {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.cover-search-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;

  .panel-header {
    @include panel.panel-header;
    flex-shrink: 0;
  }

  .dialog-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    min-height: 0;
    padding: 1.5rem;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  }
}

// Search Section
.search-section {
  flex-shrink: 0;
  background: var(--surface-ground);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;

  .form-row {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
  }

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

    &.title-field {
      flex: 1.2;
    }

    &.author-field {
      flex: 1;
    }

    label {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      font-size: 0.875rem;
      font-weight: 500;
      color: var(--text-color-secondary);

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

      .required {
        color: var(--red-400);
      }
    }

    input {
      width: 100%;
    }

    .error-message {
      display: flex;
      align-items: center;
      gap: 0.35rem;
      color: var(--red-400);
      font-size: 0.8rem;

      i {
        font-size: 0.75rem;
      }
    }
  }

  .form-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 1px;
  }
}

// Results Section
.results-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

// Empty & Loading States
.empty-state,
.loading-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  text-align: center;
  background: var(--surface-ground);
  border: 1px dashed var(--surface-border);
  border-radius: 12px;

  h3 {
    margin: 0 0 0.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-color);
  }

  p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-color-secondary);
    max-width: 300px;
  }
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-100), var(--primary-50));
  border-radius: 50%;
  margin-bottom: 1.5rem;

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

  &.warning {
    background: linear-gradient(135deg, var(--yellow-100), var(--yellow-50));

    i {
      color: var(--yellow-600);
    }
  }
}

.loading-state {
  p {
    margin-top: 1rem;
  }
}

// Results Header
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--surface-border);

  .results-count {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-color);

    i {
      color: var(--primary-color);
    }
  }

  .results-hint {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-color-secondary);

    i {
      font-size: 0.8rem;
    }
  }
}

// Covers Grid
.covers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.25rem;
  padding: 0.25rem;
}

.cover-card {
  .cover-image-wrapper {
    position: relative;
    width: 150px;
    height: 220px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-ground);
    border: 2px solid transparent;

    &:hover {
      border-color: var(--primary-color);

      .cover-overlay {
        opacity: 1;
      }
    }

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

      .p-image-preview {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;

        img {
          max-width: 100%;
          max-height: 100%;
          object-fit: contain;
        }
      }

      .p-image-preview-mask {
        background: rgba(0, 0, 0, 0.6);
      }

      .p-image-preview-indicator {
        border-radius: 4px;
      }
    }
  }

  .resolution-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    z-index: 2;
    pointer-events: none;
  }

  .cover-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    opacity: 0;
    z-index: 3;
  }
}

// Responsive
@media (max-width: 768px) {
  .search-section .form-row {
    flex-direction: column;
    align-items: stretch;

    .form-field {
      &.title-field,
      &.author-field {
        flex: none;
      }
    }

    .form-actions {
      flex-direction: row;
      justify-content: flex-end;
      margin-top: 0.5rem;

      ::ng-deep .p-button:not(.p-button-icon-only) {
        flex: 1;
      }
    }
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .covers-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 1rem;
  }
}
