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

.duplicate-merger-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.dialog-content {
  flex: 1;
  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);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preset-section {
  display: flex;
  align-items: center;
}

.advanced-section {
  .advanced-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--p-text-muted-color);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.25rem 0;

    &:hover {
      color: var(--p-text-color);
    }

    i {
      font-size: 0.75rem;
    }
  }

  .signal-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.5rem;
    padding: 0.75rem 0 0 0;
  }

  .signal-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;

    label {
      font-size: 0.875rem;
      cursor: pointer;
      user-select: none;
    }
  }
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);

  .action-bar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .action-bar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
  }

  .delete-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;

    label {
      font-size: 0.875rem;
      cursor: pointer;
      user-select: none;
      white-space: nowrap;
    }
  }
}

.results-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--p-text-muted-color);
  gap: 0.75rem;

  i {
    font-size: 2.5rem;
  }

  p {
    margin: 0;
    font-size: 0.9375rem;
  }
}

.groups-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.duplicate-group {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;

  .group-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);

    .group-label {
      font-weight: 600;
      font-size: 0.8125rem;
      color: var(--p-text-muted-color);
    }

    .group-actions {
      margin-left: auto;
      display: flex;
      gap: 0.5rem;
    }
  }

  .group-books {
    display: flex;
    flex-direction: column;
  }
}

.book-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  cursor: pointer;
  transition: background-color 0.1s;

  &:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
  }

  &:hover {
    background: var(--p-content-hover-background);
  }

  &.selected-target {
    background: var(--p-highlight-background);
  }

  &.marked-for-deletion {
    background: color-mix(in srgb, var(--p-red-500) 8%, transparent);
  }

  .delete-checkbox {
    flex-shrink: 0;
  }

  .book-cover {
    width: 36px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 3px;
    object-fit: cover;
    background: var(--p-surface-200);
  }

  .book-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.0625rem;

    .book-title {
      font-weight: 600;
      font-size: 0.875rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .book-authors {
      font-size: 0.8125rem;
      color: var(--p-text-muted-color);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .book-formats {
      display: flex;
      flex-wrap: wrap;
      gap: 0.25rem;
      margin-top: 0.125rem;

      .format-badge {
        display: inline-block;
        font-size: 0.625rem;
        font-weight: 700;
        padding: 0.0625rem 0.3125rem;
        border-radius: 3px;
        background: var(--p-primary-100);
        color: var(--p-primary-700);
        text-transform: uppercase;
        letter-spacing: 0.02em;
      }

      .file-count {
        font-size: 0.75rem;
        color: var(--p-text-muted-color);
      }

      .file-detail {
        font-size: 0.75rem;
        color: var(--p-text-muted-color);
      }
    }

    .book-file-path {
      display: flex;
      align-items: center;
      gap: 0.25rem;
      font-size: 0.75rem;
      color: var(--p-text-muted-color);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-top: 0.125rem;

      i {
        font-size: 0.6875rem;
        flex-shrink: 0;
      }
    }
  }

  .book-select {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;

    .target-label {
      font-size: 0.6875rem;
      color: var(--p-primary-color);
      text-transform: uppercase;
      font-weight: 700;
      letter-spacing: 0.03em;
    }
  }
}

.help-text {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--p-text-muted-color);
  background: var(--p-content-hover-background);
  border-radius: 6px;
  line-height: 1.4;

  i {
    flex-shrink: 0;
    margin-top: 0.125rem;
    font-size: 0.875rem;
  }
}

:host-context(.p-dark) {
  .book-row .book-cover {
    background: var(--p-surface-700);
  }

  .book-row .book-formats .format-badge {
    background: rgba(var(--p-primary-500-rgb, 99, 102, 241), 0.15);
    color: var(--p-primary-400);
  }
}

@media (max-width: 640px) {
  .action-bar {
    flex-direction: column;
    align-items: stretch;

    .action-bar-right {
      flex-wrap: wrap;
    }
  }

  .duplicate-group .group-header {
    flex-wrap: wrap;
  }
}
