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

.responsive-table {
  min-width: 50rem;

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

.directory-picker {
  width: 700px;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  height: 80vh;
  max-height: 900px;

  @media (max-width: 640px) {
    width: 100%;
    max-width: 100%;
    height: 90vh;
  }
}

.panel-header {
  @include panel.panel-header;
}

.picker-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 2rem;
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-top: none;

  .current-path {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem;
    background: var(--overlay-background);
    border-radius: 6px;

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

      i {
        color: coral;
      }
    }

    .path-value {
      flex: 1;
      color: var(--text-color);
      font-family: monospace;
      font-size: 0.875rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .controls-row {
    display: flex;
    gap: 0.75rem;

    .search-input-wrapper {
      position: relative;
      flex: 1;

      ::ng-deep {
        .p-inputicon {
          color: var(--text-secondary-color);
        }
      }

      .clear-icon {
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        color: var(--text-secondary-color);
        cursor: pointer;
        transition: color 0.2s;
        z-index: 1;

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

  .selection-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;

    @media (max-width: 640px) {
      flex-direction: column;
      width: 100%;

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

  .selection-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: var(--primary-color);
    color: var(--primary-contrast-color);
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.875rem;

    i {
      font-size: 0.875rem;
    }
  }

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

    .current-path {
      flex-direction: column;
      align-items: flex-start;
      gap: 0.5rem;

      .path-value {
        width: 100%;
      }
    }

    .controls-row {
      flex-direction: column;
      gap: 0.5rem;
    }
  }
}

.directories-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 2rem;
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-top: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  flex: 1;
  min-height: 0;
  overflow: hidden;

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

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-secondary-color);

  ::ng-deep .custom-spinner {
    .p-progress-spinner-circle {
      stroke: var(--primary-color);
    }
  }
}

.loading-text {
  margin-top: 0.75rem;
  color: var(--text-secondary-color);
}

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

  .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;

    .empty-icon {
      font-size: 2.5rem;
      color: var(--text-secondary-color);
      opacity: 0.5;
    }
  }

  .empty-title {
    margin: 0 0 0.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: 350px;
    line-height: 1.5;
  }

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

    .empty-icon-wrapper {
      width: 60px;
      height: 60px;

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

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

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

.directories-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  height: 100%;
  overflow: hidden;
}

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

  .folder-count {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color);

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

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

    .folder-count {
      font-size: 0.8rem;
    }
  }
}

.directories-grid {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  padding-right: 0.25rem;
  min-height: 0;
  opacity: 1;
  transition: opacity 0.3s ease-in-out;
  width: 100%;

  &.loading {
    opacity: 0;
  }

  &.fade-in {
    animation: fadeInUp 0.4s ease-out;
  }

  &::-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);
}

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

.directory-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--ground-background);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  transition: all 0.3s ease;
  cursor: pointer;
  opacity: 0;
  animation: fadeInItem 0.3s ease-out forwards;
  width: 100%;
  max-width: 100%;

  @for $i from 1 through 20 {
    &:nth-child(#{$i}) {
      animation-delay: #{$i * 0.03}s;
    }
  }

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

    .directory-icon {
      color: var(--primary-color);
      transform: scale(1.08);
    }

    .navigate-icon {
      opacity: 1;
      transform: translateY(2px);
    }
  }

  &.selected {
    border-color: var(--p-primary-800);

    .directory-icon-wrapper {
      background: var(--primary-color);

      .directory-icon {
        color: var(--primary-contrast-color);
      }
    }
  }

  .directory-checkbox {
    display: flex;
    align-items: center;
  }

  .directory-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    min-width: 0;

    .directory-icon-wrapper {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 32px;
      height: 32px;
      background: var(--overlay-background);
      border-radius: 6px;
      flex-shrink: 0;

      .directory-icon {
        font-size: 1rem;
        color: var(--text-secondary-color);
        transition: all 0.3s ease;
      }
    }

    .directory-info {
      flex: 1;
      display: flex;
      flex-direction: column;
      gap: 0.1875rem;
      min-width: 0;
      overflow: hidden;

      .directory-name {
        font-size: 0.875rem;
        color: var(--text-color);
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
        line-height: 1.3;
      }

      .directory-path {
        font-size: 0.75rem;
        color: var(--text-secondary-color);
        font-family: monospace;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
        line-height: 1.2;
      }
    }

    .navigate-icon {
      color: var(--text-secondary-color);
      opacity: 0;
      transition: all 0.3s ease;
      flex-shrink: 0;
    }
  }

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

    .directory-label {
      gap: 0.375rem;

      .directory-icon-wrapper {
        width: 26px;
        height: 26px;

        .directory-icon {
          font-size: 0.875rem;
        }
      }

      .directory-info {
        .directory-name {
          font-size: 0.875rem;
        }

        .directory-path {
          display: none;
        }
      }
    }
  }
}

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

.selection-note {
  margin-top: 0.75rem;
  color: var(--text-secondary-color);
}

.dialog-footer {
@include panel.dialog-footer;
border-top: 1px solid var(--border-color);

  .selection-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary-color);
    font-size: 0.9rem;

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

  @media (max-width: 480px) {
    .footer-info {
      text-align: center;
    }
  }
}

@media (max-width: 768px) {
  .directory-picker {
    border-radius: 0;
  }

  .picker-header,
  .search-bar,
  .current-path,
  .directory-list,
  .picker-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .folder-item {
    .folder-info {
      .folder-path {
        display: none;
      }
    }
  }

  .current-path {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;

    .path-value {
      width: 100%;
    }

    .selected-count {
      align-self: flex-start;
    }
  }

  .picker-footer {
    flex-direction: column;
    align-items: stretch;

    .footer-info {
      text-align: center;
    }

    .footer-actions {
      width: 100%;

      button {
        flex: 1;
      }
    }
  }
}
