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

.magic-shelf-container {
  display: flex;
  flex-direction: column;

  @media (max-width: 1280px) {
    width: 100%;
    max-width: 100%;
  }
}

.panel-header {
  @include panel.panel-header;
  border-bottom: none;
}

.import-panel {
  margin-bottom: 0.75rem;
  padding: 1rem;
  background: var(--overlay-background);
  border: 1px solid var(--border-color);
  border-radius: 8px;

  .import-textarea {
    width: 100%;
    font-family: monospace;
    font-size: 0.85rem;
    resize: vertical;
  }

  .import-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.75rem;
  }
}

.magic-shelf-content {
  padding: 2rem;
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-bottom: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  min-height: 450px;

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

.form-header {
  margin-bottom: 0.75rem;
  display: flex;
  width: 100%;
  gap: 1rem;
  padding: 1rem;
  background: var(--overlay-background);
  border-radius: 8px;
  border: 1px solid var(--border-color);

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 0.75rem;
  }
}

.form-field {
  flex: 1;

  label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
  }

  input {
    width: 100%;
  }
}

.icon-picker-section {
  display: flex;
  align-items: flex-end;

  .icon-picker-wrapper {
    label {
      display: block;
      margin-bottom: 0.5rem;
      font-weight: 600;
      color: var(--text-color);
      font-size: 0.9rem;
    }

    .selected-icon-display {
      display: flex;
      align-items: center;
      gap: 0.5rem;
    }

    .icon-display-container {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      padding: 0.625rem 1rem;
      border: 1px solid var(--border-color);
      border-radius: 6px;
      cursor: pointer;
      transition: all 0.2s ease;
      background: var(--card-background);

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

      &:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
      }

      .selected-icon {
        flex-shrink: 0;
      }

      .icon-label {
        font-size: 0.95rem;
        color: var(--text-secondary-color);
        white-space: nowrap;
      }

      .icon-placeholder {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        color: var(--text-secondary-color);

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

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

  @media (max-width: 768px) {
    align-items: flex-start;
  }
}

.public-checkbox-section {
  display: flex;
  align-items: flex-end;

  .checkbox-wrapper {
    display: flex;
    align-items: center;
    padding: 0.625rem 0;

    label {
      margin-left: 0.5rem;
      font-weight: 500;
      color: var(--text-color);
      cursor: pointer;
    }
  }

  @media (max-width: 768px) {
    align-items: flex-start;

    .checkbox-wrapper {
      padding: 0.5rem 0;
    }
  }
}

.rules-container {
  overflow: auto;
  max-height: 40rem;
  padding: 0.5rem;

  @media (max-width: 768px) {
    max-height: 35rem;
  }

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

.dialog-footer {
  @include panel.dialog-footer-end;
  justify-content: space-between;
}

.save-button-section {
  margin: 1.5rem 0 0 0;
  padding: 1rem;
  background: var(--overlay-background);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  text-align: left;
}

.group-container {
  padding: 1rem;
  border-left: 4px solid var(--primary-color);
  margin-top: 0.75rem;
  width: 100%;
  border-radius: 8px;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  transition: all 0.3s ease;

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

  @media (max-width: 768px) {
    padding: 0.75rem;
  }
}

.group-header {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;

  label {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
  }

  .condition-select {
    width: 9rem;
  }

  @media (max-width: 640px) {
    gap: 0.5rem;

    .condition-select {
      width: 100%;
      max-width: 9rem;
    }
  }
}

.rule-item {
  margin-left: 1rem;
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  padding: 0.125rem;
  gap: 0.75rem;
  background: var(--overlay-background);
  transition: all 0.2s ease;

  .field-select,
  .operator-select {
    min-width: 14rem;
  }

  .value-input,
  .autocomplete-wrapper {
    width: 100%;
  }

  @media (max-width: 1024px) {
    flex-wrap: wrap;
    margin-left: 0.5rem;
    gap: 0.5rem;

    .field-select,
    .operator-select {
      min-width: 12rem;
      flex: 1;
    }

    .value-input,
    .autocomplete-wrapper {
      flex: 1;
      min-width: 200px;
    }
  }

  @media (max-width: 640px) {
    margin-left: 0;
    padding: 0.5rem;

    .field-select,
    .operator-select {
      min-width: 100%;
    }
  }
}
