$provider-colors: (
  'amazon': #FF9902,
  'goodreads': #bc957a,
  'google': #0DB65D,
  'hardcover': #6366F1,
  'douban': #1474E9,
  'lubimyczytac': #FF5501,
  'comicvine': #F9E04F,
  'ranobedb': #06b6d4
);

.metadata-container {
  height: 100%;
  width: 100%;
  flex: auto;
}

.searcher-container {
  max-width: 1600px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease-in;
}

.search-header {
  margin-bottom: 1.5rem;

  .header-content {
    text-align: center;
  }

  .header-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.375rem;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;

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

  .header-subtitle {
    font-size: 0.875rem;
    color: var(--text-color-secondary);
    margin: 0;
  }
}

.search-card {
  background: var(--p-surface-900);
  border-radius: 0.75rem;
  padding: 1.25rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
  transition: all 0.3s ease;

  &:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  }
}

.search-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1rem;

  @media (min-width: 640px) {
    grid-template-columns: repeat(2, 1fr);
  }

  @media (min-width: 1024px) {
    grid-template-columns: 2fr 1fr 1.5fr 1.5fr auto;
    align-items: end;
  }
}

.search-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;

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

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

  &.search-field-provider {
    @media (min-width: 640px) {
      grid-column: span 2;
    }

    @media (min-width: 1024px) {
      grid-column: auto;
    }
  }

  &.search-button-field {
    @media (min-width: 640px) {
      grid-column: span 2;
    }

    @media (min-width: 1024px) {
      grid-column: auto;
    }
  }
}

::ng-deep {
  .custom-search-button {
    width: 100%;
    height: 2.5rem;
    font-weight: 600;
    font-size: 0.9375rem;
    border-radius: 0.5rem;

    @media (min-width: 1024px) {
      width: auto;
      min-width: 8rem;
    }
  }
}

.search-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--p-surface-900);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-color-secondary);
  border-left: 3px solid var(--primary-color);

  i {
    color: var(--primary-color);
    font-size: 0.9375rem;
    flex-shrink: 0;
  }
}

.provider-status {
  background: var(--p-surface-900);
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.status-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;

  .results-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  h3 {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.375rem;

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

  .results-count {
    padding: 0.25rem 0.75rem;
    background: rgba(var(--primary-color-rgb, 99, 102, 241), 0.2);
    color: var(--primary-color);
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 700;
    border: 1px solid var(--primary-color);
  }
}

.fetching-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.85rem;
  background: rgba(34, 197, 94, 0.8);
  color: white;
  border-radius: 2rem;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.35);
}

.provider-pills {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}

.provider-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--p-surface-900);
  border: 1px solid var(--p-surface-600);
  border-radius: 0.5rem;
  transition: all 0.3s ease;
  user-select: none;

  &.has-results {
    background: var(--p-surface-900);
    border-color: var(--primary-color);
    cursor: pointer;

    .pill-icon {
      background: rgba(var(--primary-color-rgb, 99, 102, 241), 0.12);
      color: var(--primary-color);
    }

    .pill-count {
      background: rgba(var(--primary-color-rgb, 99, 102, 241), 0.18);
      color: #fff;
      font-weight: 700;
    }
  }

  &.active {
    background: rgba(var(--primary-color-rgb, 99, 102, 241), 0.10);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(var(--primary-color-rgb, 99, 102, 241), 0.10),
    0 2px 6px rgba(var(--primary-color-rgb, 99, 102, 241), 0.10);
    transform: translateY(-1px);

    .pill-icon {
      background: rgba(var(--primary-color-rgb, 99, 102, 241), 0.18);
      color: var(--primary-color);
    }

    .pill-name {
      color: var(--primary-color);
      font-weight: 700;
    }

    .pill-count {
      background: rgba(var(--primary-color-rgb, 99, 102, 241), 0.22);
      color: #fff;
      font-weight: 800;
    }
  }

  @each $provider, $color in $provider-colors {
    &.provider-#{$provider} {
      &.has-results {
        border-color: $color;

        .pill-icon {
          background: rgba($color, 0.12);
          color: $color;
        }

        .pill-count {
          background: rgba($color, 0.18);
          color: #fff;
          font-weight: 700;
        }

        .pill-name {
          color: $color;
        }
      }

      &.active {
        background: rgba($color, 0.2);
        border-color: $color;
        box-shadow: 0 0 0 2px rgba($color, 0.10), 0 2px 6px rgba($color, 0.10);

        .pill-name {
          color: $color;
        }

        .pill-icon {
          background: rgba($color, 0.18);
          color: $color;
        }

        .pill-count {
          background: rgba($color, 0.22);
          color: #fff;
          font-weight: 800;
        }
      }
    }
  }

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  }

  &.active:hover {
    transform: translateY(-3px);
  }
}

.pill-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: var(--p-surface-600);
  border-radius: 0.375rem;
  color: var(--text-color-secondary);
  flex-shrink: 0;
  transition: all 0.3s ease;

  i {
    font-size: 0.9375rem;
  }
}

.pill-content {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .pill-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-color);
  }

  .pill-count {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 0.375rem;
    background: var(--p-surface-600);
    color: #fff;
    border-radius: 2rem;
    font-weight: 800;
    font-size: 1rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  }
}

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

  .empty-icon {
    width: 4rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--p-surface-900);
    border-radius: 50%;
    margin-bottom: 1rem;

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

    &.no-results {
      background: var(--p-surface-900);

      i {
        color: var(--text-color-secondary);
      }
    }
  }

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

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

.results-section {
  animation: fadeIn 0.3s ease-in;
}

.results-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--p-surface-900);
  border-radius: 0.75rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);

  @media (min-width: 768px) {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

.results-info {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;

  @media (min-width: 768px) {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
  }

  h3 {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.375rem;

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

  .results-count {
    padding: 0.1875rem 0.625rem;
    background: var(--p-surface-900);
    color: var(--primary-color);
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 600;
  }
}

.results-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.375rem;
    white-space: nowrap;

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

  p-select {
    min-width: 180px;
  }
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;

  @media (min-width: 768px) {
    grid-template-columns: repeat(2, 1fr);
  }

  @media (min-width: 1200px) {
    grid-template-columns: repeat(3, 1fr);
  }
}

.metadata-card {
  background: var(--p-surface-900);
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: row;
  height: 200px;
  animation: slideInFromTop 0.4s ease-out;

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    border-color: var(--primary-color);

    .card-overlay {
      opacity: 1;
    }

    .card-image img {
      transform: scale(1.05);
    }
  }
}

.card-image {
  position: relative;
  width: 140px;
  min-width: 140px;
  height: 200px;
  overflow: hidden;
  background: var(--p-surface-900);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;

  img {
    width: 140px;
    height: 200px;
    object-fit: cover;
    transition: transform 0.3s ease;
  }

  .card-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    color: white;

    i {
      font-size: 1.5rem;
    }

    span {
      font-weight: 600;
      font-size: 0.875rem;
    }
  }
}

.card-content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.card-header {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-color);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-provider {
  font-size: 0.9rem;

  ::ng-deep a {
    text-decoration: none;
    font-weight: 700;

    &:hover {
      text-decoration: underline;
    }
  }

  @each $provider, $color in $provider-colors {
    &.provider-#{$provider} ::ng-deep a {
      color: $color;
    }
  }
}

.card-authors {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-color-secondary);
  display: flex;
  align-items: center;
  gap: 0.375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;

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

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.5rem 0.5rem 0;
  background: var(--p-surface-900);
  border-radius: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-color-secondary);
  font-weight: 500;
  white-space: nowrap;

  i {
    padding-right: 0.25rem;
    font-size: 0.6875rem;
    color: var(--primary-color);
    flex-shrink: 0;
  }
}

.card-description {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-color-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
