.metadata-picker {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--card-background);
  animation: fadeIn 0.3s ease-in;
}

// Visibility utilities
.mobile-only {
  display: flex;

  @media (min-width: 768px) {
    display: none !important;
  }
}

.desktop-only {
  display: none;

  @media (min-width: 768px) {
    display: flex;
  }
}


// Detail loading banner
.detail-loading-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 8px;
  color: var(--p-green-400);
  font-size: 0.875rem;
  font-weight: 600;
  animation: fadeIn 0.3s ease-in;

  i {
    font-size: 1rem;
  }
}

// Body
.dialog-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;

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

  &::-webkit-scrollbar-track {
    background: transparent;
  }

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

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

// Column Headers - mirrors field-row structure for alignment (desktop only)
.column-headers {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.875rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--overlay-background);
  border: 1px solid var(--border-color);
  border-radius: 8px;

  @media (min-width: 768px) {
    justify-content: flex-start;
  }

  // Spacer to match field-label width (desktop only)
  &::before {
    content: '';
    min-width: 120px;
    flex-shrink: 0;
    display: none;

    @media (min-width: 768px) {
      display: block;
    }
  }

  .column-label {
    display: none;
    align-items: center;
    gap: 0.625rem;
    font-size: 1rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex: 1;

    @media (min-width: 768px) {
      display: flex;
    }

    i {
      font-size: 1.125rem;
    }

    &.current {
      color: var(--primary-color);
      justify-content: flex-end;
      padding-right: 1rem;
    }

    &.fetched {
      color: var(--p-blue-400);
      justify-content: flex-start;
      padding-left: 1rem;
    }
  }

  .column-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-shrink: 0;
    margin-left: 0.75rem;
    margin-right:  0.75rem;
  }
}

// Sections
.form-section {
  .section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary-color);

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

    &.collapsible-header {
      cursor: pointer;
      user-select: none;
      transition: color 0.2s ease;

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

      .section-toggle {
        margin-left: auto;
        font-size: 0.75rem;
        color: var(--text-secondary-color);
      }
    }

    .section-empty-badge {
      font-size: 0.7rem;
      font-weight: 500;
      text-transform: none;
      letter-spacing: normal;
      color: var(--text-secondary-color);
      background: var(--surface-ground);
      border: 1px solid var(--border-color);
      border-radius: 4px;
      padding: 0.125rem 0.5rem;
      opacity: 0.8;
    }
  }

  .section-content {
    background: var(--overlay-background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
  }
}

// Cover Image
.cover-wrapper {
  position: relative;
}

.cover-image {
  width: 120px;
  height: auto;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);

  @media (min-width: 768px) {
    width: 150px;
  }

  ::ng-deep img {
    width: 100%;
    height: auto;
    display: block;
  }
}

.lock-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--p-green-500);
  border: 2px solid var(--card-background);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;

  i {
    font-size: 0.625rem;
    color: white;
  }

  &.locked {
    background: var(--p-orange-500);
  }

  &:hover {
    transform: scale(1.1);
  }
}

.cover-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary-color);
}

// Cover type icon in label
.cover-type-icon {
  font-size: 0.8rem;
  margin-right: 0.25rem;
}

// Square cover for audiobooks
.square-cover {
  aspect-ratio: 1;

  ::ng-deep img {
    object-fit: cover;
    aspect-ratio: 1;
  }
}

// Audiobook cover row
.audiobook-cover-row {
  background: rgba(var(--p-primary-500-rgb), 0.03);
}

// Transfer button placeholder (same width as button)
.transfer-btn-placeholder {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

// No cover placeholder
.no-cover-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  background: var(--surface-ground);
  border: 1px dashed var(--border-color);
  border-radius: 6px;
  color: var(--text-secondary-color);

  @media (min-width: 768px) {
    width: 150px;
    height: 150px;
  }

  i {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
  }

  span {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
}


// Field Rows
.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-color);

  &:last-child {
    border-bottom: none;
  }

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

// Cover field row specific styles
.cover-field-row {
  padding: 1rem;

  .field-label {
    text-align: center;
    margin-bottom: 0.5rem;

    @media (min-width: 768px) {
      text-align: left;
      margin-bottom: 0;
    }
  }

  .field-content {
    align-items: center;
    gap: 1rem;

    @media (min-width: 768px) {
      gap: 1.5rem;
    }
  }

  // On mobile, center covers and show labels
  .field-side {
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;

    @media (min-width: 768px) {
      flex-direction: row;
    }
  }

  // Position covers towards the arrow on desktop only
  @media (min-width: 768px) {
    padding: 1rem;

    .field-side.current {
      justify-content: flex-end;
    }

    .field-side.fetched {
      justify-content: flex-start;
    }
  }
}

.field-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-color);
  min-width: 100px;

  @media (min-width: 768px) {
    min-width: 120px;
    flex-shrink: 0;
  }
}

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

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

.field-side {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;

  &.fetched {
    .field-input,
    .field-textarea,
    .chips-input {
      opacity: 0.7;
    }
  }
}

.lock-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--p-green-500);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;

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

  &.locked {
    background: var(--p-orange-500);
  }

  &:hover {
    transform: scale(1.05);
  }
}

.field-input {
  flex: 1;
  min-width: 0;
  width: 100%;
}

.field-textarea {
  flex: 1;
  min-width: 0;
  width: 100%;
  resize: vertical;
}

.chips-input {
  flex: 1;
  min-width: 0;
  width: 100%;

  &.readonly {
    pointer-events: none;
  }
}

.textarea-row {
  .field-content {
    @media (min-width: 768px) {
      align-items: flex-start;
    }
  }

  .field-side {
    @media (min-width: 768px) {
      align-items: flex-start;
    }
  }

  .lock-btn {
    @media (min-width: 768px) {
      margin-top: 0.25rem;
    }
  }

  .transfer-btn {
    @media (min-width: 768px) {
      margin-top: 0.25rem;
    }
  }
}

// Transfer Button
.transfer-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;

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

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

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

  &.saved {
    border-color: var(--p-green-500);
    background: var(--p-green-500);

    i {
      color: white;
    }
  }

  &.copied {
    border-color: var(--p-yellow-500);
    background: rgba(234, 179, 8, 0.15);

    i {
      color: var(--p-yellow-500);
    }
  }

  &.reset {
    border-color: var(--p-red-500);
    background: rgba(239, 68, 68, 0.15);

    i {
      color: var(--p-red-500);
    }
  }
}

// Footer
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--overlay-background);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.footer-left {
  display: flex;
  align-items: center;
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.footer-divider {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  margin: 0 0.25rem;
}

// AutoComplete overrides
::ng-deep .p-autocomplete {
  width: 100% !important;

  .p-autocomplete-multiple-container {
    width: 100%;
  }
}

// Animation
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

// Mobile optimizations
@media (max-width: 767px) {
  .dialog-body {
    padding: 1rem;
    gap: 1.25rem;
  }

  .dialog-footer {
    flex-direction: column;
    padding: 0.875rem 1rem;
    gap: 0.75rem;

    .footer-left,
    .footer-right {
      width: 100%;
      justify-content: center;
    }
  }

  .field-label {
    font-size: 0.8rem;
    font-weight: 600;
  }
}

.author-chips-container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem;
  min-height: 2.25rem;
  border: 1px solid var(--p-inputtext-border-color);
  border-radius: 6px;
  background: var(--p-inputtext-background);
  flex: 1;
  min-width: 0;

  &.disabled {
    opacity: 0.6;
    background: var(--p-inputtext-disabled-background);
    cursor: default;

    .author-chip {
      cursor: default;
    }
  }
}

.author-add-input {
  flex: 1 1 6rem;
  min-width: 6rem;

  ::ng-deep input {
    border: none !important;
    background: transparent !important;
    padding: 0.25rem;
    box-shadow: none !important;
    outline: none !important;
  }
}

.author-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: 1rem;
  background: var(--p-chip-background);
  color: var(--p-chip-color);
  font-size: 0.875rem;
  cursor: grab;
  user-select: none;
}

.main-author-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--p-primary-color);
  color: var(--p-primary-contrast-color);
  font-size: 0.6rem;
  font-weight: 700;
  flex-shrink: 0;
}

.author-chip-remove {
  font-size: 0.65rem;
  cursor: pointer;
  opacity: 0.6;
  padding: 0.15rem;
  &:hover { opacity: 1; }
}

.cdk-drag-preview {
  box-sizing: border-box;
  border-radius: 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.cdk-drag-placeholder {
  opacity: 0.4;
}

.cdk-drag-animating {
  transition: transform 200ms ease;
}
